Compare commits
7 Commits
VAINGSANG
...
eb1ecdf405
| Author | SHA1 | Date | |
|---|---|---|---|
| eb1ecdf405 | |||
| 6d7970970a | |||
| 2decf0afa2 | |||
| d9743ce1ee | |||
| 853dc5a940 | |||
| 263711cff3 | |||
| 5ad0874d53 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -28,3 +28,4 @@ tmp/
|
|||||||
### --- Système / OS ---
|
### --- Système / OS ---
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
*.db
|
||||||
|
|||||||
@@ -7,5 +7,6 @@
|
|||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="sqlite-jdbc-3.51.2.0" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -23,17 +23,17 @@ public class CampagneAutoroute {
|
|||||||
double pente = 30.0;
|
double pente = 30.0;
|
||||||
|
|
||||||
if (difficulte == 1) { // FACILE
|
if (difficulte == 1) { // FACILE
|
||||||
vitesse = 4.0;
|
vitesse = 6.0;
|
||||||
pente = 20.0;
|
pente = 20.0;
|
||||||
} else if (difficulte == 2) { // MOYEN
|
} else if (difficulte == 2) { // MOYEN
|
||||||
vitesse = 8.0;
|
vitesse = 7.0;
|
||||||
pente = 45.0;
|
pente = 45.0;
|
||||||
} else if (difficulte == 3) { // DIFFICILE
|
} else if (difficulte == 3) { // DIFFICILE
|
||||||
vitesse = 12.0;
|
vitesse = 8.0;
|
||||||
pente = 70.0;
|
pente = 70.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- 2. CRÉATION DES OBJETS AVEC LA MÊME VITESSE ---
|
// --- 2. CRÉATION DES OBJETS
|
||||||
|
|
||||||
// On passe la vitesse au fond pour qu'il défile au même rythme !
|
// On passe la vitesse au fond pour qu'il défile au même rythme !
|
||||||
FondAutoroute fond = new FondAutoroute(vitesse);
|
FondAutoroute fond = new FondAutoroute(vitesse);
|
||||||
|
|||||||
62
src/linea/CampagneEspace.java
Normal file
62
src/linea/CampagneEspace.java
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package linea;
|
||||||
|
|
||||||
|
import javax.swing.Timer;
|
||||||
|
|
||||||
|
public class CampagneEspace {
|
||||||
|
protected Jeu jeu;
|
||||||
|
|
||||||
|
public CampagneEspace(Jeu j) {
|
||||||
|
this.jeu = j;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lancerNiveauLune(int difficulte) {
|
||||||
|
System.out.println("Lancement Espace - Difficulté : " + difficulte);
|
||||||
|
|
||||||
|
if(jeu.horloge != null) {
|
||||||
|
jeu.horloge.stop();
|
||||||
|
}
|
||||||
|
jeu.horloge = new Timer(40, jeu);
|
||||||
|
|
||||||
|
jeu.ecran.viderObjets();
|
||||||
|
|
||||||
|
double vitesse = 5.0;
|
||||||
|
double pente = 30.0;
|
||||||
|
|
||||||
|
if (difficulte == 1) { // FACILE
|
||||||
|
vitesse = 6.0;
|
||||||
|
pente = 20.0;
|
||||||
|
} else if (difficulte == 2) { // MOYEN
|
||||||
|
vitesse = 7.0;
|
||||||
|
pente = 45.0;
|
||||||
|
} else if (difficulte == 3) { // DIFFICILE
|
||||||
|
vitesse = 8.0;
|
||||||
|
pente = 70.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Fond étoilé
|
||||||
|
FondEspace fond = new FondEspace();
|
||||||
|
jeu.ecran.ajouterObjet(fond);
|
||||||
|
|
||||||
|
// 2. Ligne de trajectoire
|
||||||
|
jeu.laligne = new Ligne(vitesse, pente);
|
||||||
|
jeu.ecran.ajouterObjet(jeu.laligne);
|
||||||
|
|
||||||
|
// 3. Cercle Espace avec physique Lunaire (niveau 1)
|
||||||
|
CercleEspace halo = new CercleEspace(0, 360, 1);
|
||||||
|
jeu.ecran.ajouterObjet(halo);
|
||||||
|
|
||||||
|
// Liaisons contrôles
|
||||||
|
jeu.demiCercleAvant = halo;
|
||||||
|
jeu.demiCercleArriere = halo;
|
||||||
|
|
||||||
|
// UI et lancement
|
||||||
|
jeu.ecran.setGameOver(false);
|
||||||
|
jeu.score = 0;
|
||||||
|
jeu.labScore.setText("<html><h3 style='color:white;'>LUNE - score : 0</h3></html>");
|
||||||
|
|
||||||
|
jeu.layout.show(jeu.conteneurPrincipal, "JEU");
|
||||||
|
jeu.ecran.setFocusable(true);
|
||||||
|
jeu.ecran.requestFocusInWindow();
|
||||||
|
jeu.horloge.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,28 +11,34 @@ public class CampagneOcean {
|
|||||||
this.jeuPrincipal = jeu;
|
this.jeuPrincipal = jeu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void lancerNiveau(int niveau) {
|
public void lancerNiveau(int difficulte) {
|
||||||
System.out.println("Lancement du niveau Ocean - Difficulté : " + niveau);
|
System.out.println("Lancement du niveau Ocean - Difficulté : " + difficulte);
|
||||||
|
|
||||||
if (jeuPrincipal.horloge != null) {
|
if (jeuPrincipal.horloge != null) {
|
||||||
jeuPrincipal.horloge.stop();
|
jeuPrincipal.horloge.stop();
|
||||||
}
|
}
|
||||||
jeuPrincipal.horloge = new Timer(40, jeuPrincipal);
|
jeuPrincipal.horloge = new Timer(40, jeuPrincipal);
|
||||||
|
double vitesse = 5.0;
|
||||||
|
double pente = 30.0;
|
||||||
|
|
||||||
|
if (difficulte == 1) { // FACILE
|
||||||
|
vitesse = 6.0;
|
||||||
|
pente = 20.0;
|
||||||
|
} else if (difficulte == 2) { // MOYEN
|
||||||
|
vitesse = 7.0;
|
||||||
|
pente = 45.0;
|
||||||
|
} else if (difficulte == 3) { // DIFFICILE
|
||||||
|
vitesse = 8.0;
|
||||||
|
pente = 70.0;
|
||||||
|
}
|
||||||
|
|
||||||
jeuPrincipal.ecran.viderObjets();
|
jeuPrincipal.ecran.viderObjets();
|
||||||
|
|
||||||
FondOcean monFond = new FondOcean();
|
FondOcean monFond = new FondOcean();
|
||||||
jeuPrincipal.ecran.ajouterObjet(monFond);
|
jeuPrincipal.ecran.ajouterObjet(monFond);
|
||||||
|
|
||||||
jeuPrincipal.laligne = new Ligne();
|
jeuPrincipal.laligne = new Ligne(vitesse, pente);
|
||||||
|
|
||||||
if (niveau == 1) {
|
|
||||||
jeuPrincipal.laligne.setInclinaisonMax(10.0);
|
|
||||||
} else if (niveau == 2) {
|
|
||||||
jeuPrincipal.laligne.setInclinaisonMax(30.0);
|
|
||||||
} else {
|
|
||||||
jeuPrincipal.laligne.setInclinaisonMax(55.0);
|
|
||||||
}
|
|
||||||
jeuPrincipal.ecran.ajouterObjet(jeuPrincipal.laligne);
|
jeuPrincipal.ecran.ajouterObjet(jeuPrincipal.laligne);
|
||||||
|
|
||||||
Cercle joueur = new Cercle(0, 360);
|
Cercle joueur = new Cercle(0, 360);
|
||||||
|
|||||||
41
src/linea/CercleEspace.java
Normal file
41
src/linea/CercleEspace.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package linea;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.geom.Arc2D;
|
||||||
|
|
||||||
|
public class CercleEspace extends Cercle {
|
||||||
|
|
||||||
|
protected double gravite;
|
||||||
|
|
||||||
|
public CercleEspace(double debutArc, double finArc, int niveauEspace) {
|
||||||
|
super(debutArc, finArc);
|
||||||
|
this.x = 400;
|
||||||
|
this.y = 200;
|
||||||
|
|
||||||
|
if (niveauEspace == 1) { // LUNE
|
||||||
|
this.gravite = 1.62;
|
||||||
|
this.couleur = Color.WHITE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void Afficher(Graphics g) {
|
||||||
|
Graphics2D g2D = (Graphics2D) g;
|
||||||
|
|
||||||
|
// Halo extérieur (lueur)
|
||||||
|
g2D.setStroke(new BasicStroke(12.0f));
|
||||||
|
Color haloColor = new Color(this.couleur.getRed(), this.couleur.getGreen(), this.couleur.getBlue(), 60);
|
||||||
|
g2D.setColor(haloColor);
|
||||||
|
g2D.draw(new Arc2D.Double(x-rayon/2, y-rayon, rayon, rayon*2, debut, fin, Arc2D.OPEN));
|
||||||
|
|
||||||
|
// Cercle central brillant
|
||||||
|
g2D.setStroke(new BasicStroke(3.0f));
|
||||||
|
g2D.setColor(this.couleur);
|
||||||
|
g2D.draw(new Arc2D.Double(x-rayon/2, y-rayon, rayon, rayon*2, debut, fin, Arc2D.OPEN));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void Animer() {
|
||||||
|
// On conserve la physique de base de Cercle (gravité/impulsion standard)
|
||||||
|
super.Animer();
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/linea/FondEspace.java
Normal file
39
src/linea/FondEspace.java
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package linea;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class FondEspace extends ObjetGraphique {
|
||||||
|
private int[] starX = new int[100];
|
||||||
|
private int[] starY = new int[100];
|
||||||
|
private Random rand = new Random();
|
||||||
|
|
||||||
|
public FondEspace() {
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
starX[i] = rand.nextInt(800);
|
||||||
|
starY[i] = rand.nextInt(600);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void Afficher(Graphics g) {
|
||||||
|
// Espace profond
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.fillRect(0, 0, 800, 600);
|
||||||
|
|
||||||
|
// Étoiles
|
||||||
|
g.setColor(Color.WHITE);
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
g.fillOval(starX[i], starY[i], 2, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void Animer() {
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
starX[i] -= 2; // Défilement vers la gauche
|
||||||
|
if (starX[i] < 0) starX[i] = 800;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,95 +1,96 @@
|
|||||||
package linea;
|
package linea;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
|
|
||||||
public class GestionnaireBDD {
|
public class GestionnaireBDD {
|
||||||
|
|
||||||
private Connection conn = null;
|
private Connection conn = null;
|
||||||
private static final String DB_FILE = "linea_scores.db";
|
// On utilise une base de données SQLite, qui est un simple fichier.
|
||||||
|
private final String DB_URL = "jdbc:sqlite:linea.db";
|
||||||
|
|
||||||
/**
|
|
||||||
* Le constructeur établit la connexion et crée la table si elle n'existe pas.
|
|
||||||
*/
|
|
||||||
public GestionnaireBDD() {
|
public GestionnaireBDD() {
|
||||||
try {
|
try {
|
||||||
// URL de connexion pour SQLite
|
// Le pilote JDBC pour SQLite doit être ajouté à votre projet.
|
||||||
String url = "jdbc:sqlite:" + DB_FILE;
|
Class.forName("org.sqlite.JDBC");
|
||||||
// Établir la connexion
|
conn = DriverManager.getConnection(DB_URL);
|
||||||
conn = DriverManager.getConnection(url);
|
|
||||||
System.out.println("Connexion à la base de données SQLite établie.");
|
System.out.println("Connexion à la base de données SQLite établie.");
|
||||||
// S'assurer que la table pour les scores existe
|
|
||||||
creerTableSiNecessaire();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.err.println("Erreur de connexion à la base de données : " + e.getMessage());
|
System.out.println("Erreur de connexion à la BDD : " + e.getMessage());
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
System.out.println("Le pilote JDBC SQLite n'a pas été trouvé. Veuillez l'ajouter à votre projet.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void initialiserBaseDeDonnees() {
|
||||||
* Crée la table 'parties' si elle n'est pas déjà présente dans la base de données.
|
// Crée les tables si elles n'existent pas et insère les données de difficulté.
|
||||||
*/
|
|
||||||
private void creerTableSiNecessaire() {
|
|
||||||
String sql = "CREATE TABLE IF NOT EXISTS parties (\n"
|
|
||||||
+ " id INTEGER PRIMARY KEY AUTOINCREMENT,\n"
|
|
||||||
+ " duree_secondes INTEGER NOT NULL,\n"
|
|
||||||
+ " campagne_id INTEGER NOT NULL,\n"
|
|
||||||
+ " difficulte_id INTEGER NOT NULL,\n"
|
|
||||||
+ " score INTEGER NOT NULL,\n"
|
|
||||||
+ " date_partie TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n"
|
|
||||||
+ ");";
|
|
||||||
|
|
||||||
// 'try-with-resources' assure que le Statement est bien fermé
|
|
||||||
try (Statement stmt = conn.createStatement()) {
|
try (Statement stmt = conn.createStatement()) {
|
||||||
stmt.execute(sql);
|
// Table pour les difficultés
|
||||||
|
stmt.execute("CREATE TABLE IF NOT EXISTS difficultes (" +
|
||||||
|
"id_difficulte INT PRIMARY KEY, " +
|
||||||
|
"vitesse REAL NOT NULL, " +
|
||||||
|
"pente REAL NOT NULL)");
|
||||||
|
|
||||||
|
// Table pour les scores des parties
|
||||||
|
stmt.execute("CREATE TABLE IF NOT EXISTS parties (" +
|
||||||
|
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||||
|
"duree INT, " +
|
||||||
|
"campagne_id INT, " +
|
||||||
|
"difficulte_id INT, " +
|
||||||
|
"score INT, " +
|
||||||
|
"date_partie TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
|
||||||
|
|
||||||
|
// Insertion des valeurs de difficulté par défaut
|
||||||
|
// L'instruction "INSERT OR IGNORE" est spécifique à SQLite et évite les doublons.
|
||||||
|
stmt.execute("INSERT OR IGNORE INTO difficultes (id_difficulte, vitesse, pente) VALUES (1, 6, 20);");
|
||||||
|
stmt.execute("INSERT OR IGNORE INTO difficultes (id_difficulte, vitesse, pente) VALUES (2, 7, 45);");
|
||||||
|
stmt.execute("INSERT OR IGNORE INTO difficultes (id_difficulte, vitesse, pente) VALUES (3, 8, 70);");
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.err.println("Erreur lors de la création de la table : " + e.getMessage());
|
System.out.println("Erreur lors de l'initialisation de la base de données : " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public double[] getParametresDifficulte(int difficulteId) {
|
||||||
* Enregistre les informations d'une partie terminée dans la base de données.
|
// Par défaut (si non trouvé), on retourne les valeurs pour la difficulté 1.
|
||||||
* Utilise un PreparedStatement pour la sécurité et la performance.
|
double[] params = {6.0, 20.0};
|
||||||
*
|
String sql = "SELECT vitesse, pente FROM difficultes WHERE id_difficulte = ?";
|
||||||
* @param dureePartie Durée du jeu en secondes.
|
|
||||||
* @param idCampagne ID de la campagne jouée.
|
|
||||||
* @param idDifficulte ID de la difficulté choisie.
|
|
||||||
* @param score Score final du joueur.
|
|
||||||
*/
|
|
||||||
public void enregistrerPartie(int dureePartie, int idCampagne, int idDifficulte, int score) {
|
|
||||||
if (conn == null) {
|
|
||||||
System.err.println("Impossible d'enregistrer la partie : pas de connexion à la BDD.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String sql = "INSERT INTO parties(duree_secondes, campagne_id, difficulte_id, score) VALUES(?,?,?,?)";
|
|
||||||
|
|
||||||
|
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
||||||
|
pstmt.setInt(1, difficulteId);
|
||||||
|
ResultSet rs = pstmt.executeQuery();
|
||||||
|
|
||||||
|
if (rs.next()) {
|
||||||
|
params[0] = rs.getDouble("vitesse");
|
||||||
|
params[1] = rs.getDouble("pente");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.out.println("Erreur lors de la récupération des paramètres de difficulté : " + e.getMessage());
|
||||||
|
}
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enregistrerPartie(int dureePartie, int idCampagneActive, int difficulteActive, int score) {
|
||||||
|
String sql = "INSERT INTO parties(duree, campagne_id, difficulte_id, score) VALUES(?,?,?,?)";
|
||||||
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
||||||
pstmt.setInt(1, dureePartie);
|
pstmt.setInt(1, dureePartie);
|
||||||
pstmt.setInt(2, idCampagne);
|
pstmt.setInt(2, idCampagneActive);
|
||||||
pstmt.setInt(3, idDifficulte);
|
pstmt.setInt(3, difficulteActive);
|
||||||
pstmt.setInt(4, score);
|
pstmt.setInt(4, score);
|
||||||
pstmt.executeUpdate();
|
pstmt.executeUpdate();
|
||||||
System.out.println("Partie enregistrée avec succès ! Score : " + score);
|
System.out.println("Partie enregistrée avec succès.");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.err.println("Erreur lors de l'enregistrement de la partie : " + e.getMessage());
|
System.out.println("Erreur lors de l'enregistrement de la partie : " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Ferme la connexion à la base de données.
|
|
||||||
* Il est important d'appeler cette méthode à la fermeture de l'application.
|
|
||||||
*/
|
|
||||||
public void fermerConnexion() {
|
public void fermerConnexion() {
|
||||||
try {
|
try {
|
||||||
if (conn != null && !conn.isClosed()) {
|
if (conn != null) {
|
||||||
conn.close();
|
conn.close();
|
||||||
System.out.println("Connexion à la base de données fermée.");
|
System.out.println("Connexion BDD fermée.");
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
System.err.println("Erreur lors de la fermeture de la connexion BDD : " + ex.getMessage());
|
System.out.println(ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
menuCampagne = new MenuCampagne(this);
|
menuCampagne = new MenuCampagne(this);
|
||||||
|
|
||||||
// Initialisation initiale
|
// Initialisation initiale
|
||||||
resetPartie();
|
resetPartie(6,20);
|
||||||
|
|
||||||
// On ajoute l'action au bouton "Retour" de la ZoneDessin (Game Over)
|
// On ajoute l'action au bouton "Retour" de la ZoneDessin (Game Over)
|
||||||
ecran.btnRetour.addActionListener(new ActionListener() {
|
ecran.btnRetour.addActionListener(new ActionListener() {
|
||||||
@@ -92,6 +92,9 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
if (idCampagneActive == 1) {
|
if (idCampagneActive == 1) {
|
||||||
CampagneAutoroute campagne = new CampagneAutoroute(this);
|
CampagneAutoroute campagne = new CampagneAutoroute(this);
|
||||||
campagne.lancerNiveau(numeroNiveau);
|
campagne.lancerNiveau(numeroNiveau);
|
||||||
|
} else if (idCampagneActive == 2) {
|
||||||
|
CampagneEspace campagne = new CampagneEspace(this);
|
||||||
|
campagne.lancerNiveauLune(numeroNiveau);
|
||||||
}
|
}
|
||||||
else if (idCampagneActive == 3) {
|
else if (idCampagneActive == 3) {
|
||||||
CampagneOcean campagne = new CampagneOcean(this);
|
CampagneOcean campagne = new CampagneOcean(this);
|
||||||
@@ -103,14 +106,13 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void lancerPartie() {
|
public void lancerPartie() {
|
||||||
resetPartie();
|
|
||||||
layout.show(conteneurPrincipal, "JEU");
|
layout.show(conteneurPrincipal, "JEU");
|
||||||
ecran.setFocusable(true);
|
ecran.setFocusable(true);
|
||||||
ecran.requestFocusInWindow();
|
ecran.requestFocusInWindow();
|
||||||
horloge.start();
|
horloge.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetPartie() {
|
public void resetPartie(double vitesse, double pente) {
|
||||||
if(horloge != null) {
|
if(horloge != null) {
|
||||||
horloge.stop();
|
horloge.stop();
|
||||||
}
|
}
|
||||||
@@ -120,7 +122,7 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
demiCercleAvant = new Cercle(90, -180);
|
demiCercleAvant = new Cercle(90, -180);
|
||||||
demiCercleArriere = new Cercle(90, 180);
|
demiCercleArriere = new Cercle(90, 180);
|
||||||
|
|
||||||
laligne = new Ligne();
|
laligne = new Ligne(vitesse, pente);
|
||||||
|
|
||||||
demiCercleArriere.setCouleur(new Color(0.8f, 0.0f, 0.0f));
|
demiCercleArriere.setCouleur(new Color(0.8f, 0.0f, 0.0f));
|
||||||
demiCercleAvant.setCouleur(new Color(1.0f, 0.2f, 0.2f));
|
demiCercleAvant.setCouleur(new Color(1.0f, 0.2f, 0.2f));
|
||||||
@@ -136,6 +138,7 @@ public class Jeu implements KeyListener, ActionListener {
|
|||||||
labScore.setText("<html><h3>score : 0</h3></html>");
|
labScore.setText("<html><h3>score : 0</h3></html>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
ecran.traiterBoucleAnimation();
|
ecran.traiterBoucleAnimation();
|
||||||
|
|||||||
@@ -54,19 +54,24 @@ public class Ligne extends ObjetGraphique{// Hérite de la classe ObjetGraphique
|
|||||||
Segment s = new Segment(x, y, dx, dy);
|
Segment s = new Segment(x, y, dx, dy);
|
||||||
listSegments.add(s);
|
listSegments.add(s);
|
||||||
|
|
||||||
for (int i=1; i<nbSegments; i++) {
|
for (int i = 1; i < nbSegments; i++) {
|
||||||
dx = (Math.random()*20)+80;
|
dx = (Math.random() * 20) + 80;
|
||||||
|
|
||||||
|
if (i <= 5) {
|
||||||
|
dy = 0;
|
||||||
|
} else {
|
||||||
dy = (Math.random() * (2.0 * inclinaisonMax)) - inclinaisonMax;
|
dy = (Math.random() * (2.0 * inclinaisonMax)) - inclinaisonMax;
|
||||||
|
|
||||||
if (y + dy < 0 || y + dy > 600) {
|
if (y + dy < 0 || y + dy > 600) {
|
||||||
dy = -dy;
|
dy = -dy;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
s = new Segment(x,y,dx,dy);
|
s = new Segment(x, y, dx, dy);
|
||||||
s.setCouleur(new Color(0.2f,0.2f,0.2f));
|
s.setCouleur(new Color(0.2f, 0.2f, 0.2f));
|
||||||
|
|
||||||
x+=dx;
|
x += dx;
|
||||||
y+=dy;
|
y += dy;
|
||||||
listSegments.add(s);
|
listSegments.add(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user