2026-02-10 16:39:21 +01:00
|
|
|
|
package linea;
|
|
|
|
|
|
|
2026-03-25 20:54:24 +01:00
|
|
|
|
import java.awt.BorderLayout;
|
2026-02-10 16:39:21 +01:00
|
|
|
|
import java.awt.Color;
|
2026-03-25 20:54:24 +01:00
|
|
|
|
import java.awt.FlowLayout;
|
2026-02-10 16:39:21 +01:00
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
|
|
import java.awt.event.KeyEvent;
|
|
|
|
|
|
import java.awt.event.KeyListener;
|
2026-03-25 20:54:24 +01:00
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import java.util.List;
|
2026-02-10 16:39:21 +01:00
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
|
|
import javax.swing.JLabel;
|
2026-03-28 08:16:44 +01:00
|
|
|
|
import javax.swing.JList;
|
2026-03-16 15:36:24 +01:00
|
|
|
|
import javax.swing.JOptionPane;
|
2026-03-25 20:54:24 +01:00
|
|
|
|
import javax.swing.JPanel;
|
2026-03-28 08:16:44 +01:00
|
|
|
|
import javax.swing.JScrollPane;
|
2026-03-25 20:54:24 +01:00
|
|
|
|
import javax.swing.Timer;
|
2026-03-16 15:36:24 +01:00
|
|
|
|
|
|
|
|
|
|
public class Jeu implements KeyListener, ActionListener {
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
// PROPRIETES
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
protected ZoneDessin ecran = new ZoneDessin();
|
|
|
|
|
|
protected Cercle demiCercleAvant;
|
|
|
|
|
|
protected Cercle demiCercleArriere;
|
|
|
|
|
|
protected Ligne ligne;
|
|
|
|
|
|
|
2026-03-28 08:16:44 +01:00
|
|
|
|
private int _niv;
|
2026-03-16 15:36:24 +01:00
|
|
|
|
protected Timer horloge;
|
2026-03-28 14:18:17 +01:00
|
|
|
|
protected JFrame fenetre;
|
2026-03-16 15:36:24 +01:00
|
|
|
|
protected double score = 0;
|
|
|
|
|
|
protected JLabel labScore;
|
2026-03-25 20:54:24 +01:00
|
|
|
|
protected JLabel labMeilleurScore;
|
2026-03-28 14:18:17 +01:00
|
|
|
|
protected JLabel labNiveau;
|
2026-03-25 20:54:24 +01:00
|
|
|
|
private DatabaseConnection db;
|
|
|
|
|
|
private int idCompte;
|
|
|
|
|
|
private int meilleurSansCompte = 0;
|
|
|
|
|
|
private int mortsSansCompte = 0;
|
|
|
|
|
|
private int tempsSansCompteSec = 0;
|
|
|
|
|
|
private long debutPartieMs = 0;
|
2026-03-28 08:16:44 +01:00
|
|
|
|
private boolean immortel = false;
|
2026-03-28 14:18:17 +01:00
|
|
|
|
private final boolean modeCampagne;
|
2026-03-25 20:54:24 +01:00
|
|
|
|
|
|
|
|
|
|
private int meilleurActuel() {
|
|
|
|
|
|
return idCompte > 0 ? db.getMeilleurScoreParCompte(idCompte) : meilleurSansCompte;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String statsActuelles() {
|
|
|
|
|
|
if (idCompte > 0) {
|
2026-03-28 14:18:17 +01:00
|
|
|
|
return db.getStatsParCompte(idCompte) + "\n\n" + db.getStatsCampagneParCompte(idCompte);
|
2026-03-25 20:54:24 +01:00
|
|
|
|
}
|
2026-03-28 14:18:17 +01:00
|
|
|
|
return "💀 Nombre de morts: " + mortsSansCompte
|
|
|
|
|
|
+ "\n⏱️ Temps total: " + tempsSansCompteSec + "s"
|
|
|
|
|
|
+ "\n🏆 Meilleur score: " + meilleurSansCompte;
|
2026-03-25 20:54:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void enregistrerPartie(int scoreActuel, int tempsPartieSec) {
|
|
|
|
|
|
if (idCompte > 0) {
|
|
|
|
|
|
db.sauvegarderScore(scoreActuel, idCompte, 1, tempsPartieSec);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
meilleurSansCompte = Math.max(meilleurSansCompte, scoreActuel);
|
|
|
|
|
|
mortsSansCompte += 1;
|
|
|
|
|
|
tempsSansCompteSec += tempsPartieSec;
|
|
|
|
|
|
}
|
2026-03-16 15:36:24 +01:00
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
// CONSTRUCTEUR
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
2026-03-28 08:16:44 +01:00
|
|
|
|
public Jeu(DatabaseConnection db, int idCompte, int niveau) {
|
2026-03-28 14:18:17 +01:00
|
|
|
|
this(db, idCompte, niveau, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Jeu(DatabaseConnection db, int idCompte, int niveau, boolean modeCampagne) {
|
2026-03-25 20:54:24 +01:00
|
|
|
|
this.db = db;
|
|
|
|
|
|
this.idCompte = idCompte;
|
2026-03-28 08:16:44 +01:00
|
|
|
|
this._niv = niveau;
|
2026-03-28 14:18:17 +01:00
|
|
|
|
this.modeCampagne = modeCampagne;
|
2026-03-16 15:36:24 +01:00
|
|
|
|
labScore = new JLabel();
|
|
|
|
|
|
labScore.setText("<html><h3>score : 0</h3></html>");
|
2026-03-25 20:54:24 +01:00
|
|
|
|
|
|
|
|
|
|
labMeilleurScore = new JLabel();
|
2026-03-28 14:18:17 +01:00
|
|
|
|
labNiveau = new JLabel();
|
2026-03-25 20:54:24 +01:00
|
|
|
|
|
|
|
|
|
|
JPanel panneauScores = new JPanel(new FlowLayout(FlowLayout.LEFT, 20, 0));
|
|
|
|
|
|
panneauScores.setOpaque(false);
|
|
|
|
|
|
panneauScores.add(labScore);
|
|
|
|
|
|
panneauScores.add(labMeilleurScore);
|
2026-03-28 14:18:17 +01:00
|
|
|
|
panneauScores.add(labNiveau);
|
2026-03-25 20:54:24 +01:00
|
|
|
|
ecran.add(panneauScores, BorderLayout.NORTH);
|
|
|
|
|
|
rafraichirMeilleurScore();
|
2026-03-28 14:18:17 +01:00
|
|
|
|
rafraichirNiveau();
|
2026-03-25 20:54:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void rafraichirMeilleurScore() {
|
|
|
|
|
|
labMeilleurScore.setText("<html><h3>meilleur : " + meilleurActuel() + "</h3></html>");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-28 14:18:17 +01:00
|
|
|
|
private void rafraichirNiveau() {
|
|
|
|
|
|
labNiveau.setText("<html><h3>niveau : " + _niv + "</h3></html>");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void rafraichirTitreFenetre() {
|
|
|
|
|
|
if (fenetre == null) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
String titre = modeCampagne ? "Linea Game [CAMPAGNE]" : "Linea Game";
|
|
|
|
|
|
fenetre.setTitle(titre + (immortel ? " [MODE IMMORTEL 🛡️]" : ""));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String categorieNiveau(int niveau) {
|
|
|
|
|
|
if (niveau <= 2) return "Facile";
|
|
|
|
|
|
if (niveau <= 4) return "Moyen";
|
|
|
|
|
|
if (niveau <= 6) return "Difficile";
|
|
|
|
|
|
if (niveau <= 8) return "Tres Difficile";
|
|
|
|
|
|
if (niveau <= 10) return "Expert";
|
|
|
|
|
|
if (niveau <= 12) return "Cauchemar";
|
|
|
|
|
|
if (niveau <= 14) return "Chaos";
|
|
|
|
|
|
if (niveau <= 16) return "Infernal";
|
|
|
|
|
|
if (niveau <= 18) return "Apocalypse";
|
|
|
|
|
|
if (niveau <= 20) return "Extreme";
|
|
|
|
|
|
if (niveau <= 30) return "Infini";
|
|
|
|
|
|
if (niveau <= 50) return "Au-dela";
|
|
|
|
|
|
return "Cosmos";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void appliquerThemeNiveau() {
|
|
|
|
|
|
String categorie = categorieNiveau(_niv);
|
|
|
|
|
|
Color fond;
|
|
|
|
|
|
Color couleurLigne;
|
|
|
|
|
|
Color couleurAvant;
|
|
|
|
|
|
Color couleurArriere;
|
|
|
|
|
|
Color couleurTexte;
|
|
|
|
|
|
|
|
|
|
|
|
switch (categorie) {
|
|
|
|
|
|
case "Facile":
|
|
|
|
|
|
fond = new Color(225, 245, 225);
|
|
|
|
|
|
couleurLigne = new Color(45, 120, 45);
|
|
|
|
|
|
couleurAvant = new Color(55, 185, 80);
|
|
|
|
|
|
couleurArriere = new Color(175, 70, 70);
|
|
|
|
|
|
couleurTexte = new Color(20, 50, 20);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Moyen":
|
|
|
|
|
|
fond = new Color(215, 235, 250);
|
|
|
|
|
|
couleurLigne = new Color(40, 95, 150);
|
|
|
|
|
|
couleurAvant = new Color(50, 165, 120);
|
|
|
|
|
|
couleurArriere = new Color(185, 80, 85);
|
|
|
|
|
|
couleurTexte = new Color(20, 45, 80);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Difficile":
|
|
|
|
|
|
fond = new Color(250, 235, 200);
|
|
|
|
|
|
couleurLigne = new Color(155, 95, 40);
|
|
|
|
|
|
couleurAvant = new Color(195, 145, 55);
|
|
|
|
|
|
couleurArriere = new Color(175, 70, 40);
|
|
|
|
|
|
couleurTexte = new Color(85, 55, 20);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Tres Difficile":
|
|
|
|
|
|
fond = new Color(245, 215, 195);
|
|
|
|
|
|
couleurLigne = new Color(145, 70, 40);
|
|
|
|
|
|
couleurAvant = new Color(185, 110, 65);
|
|
|
|
|
|
couleurArriere = new Color(175, 55, 45);
|
|
|
|
|
|
couleurTexte = new Color(80, 35, 25);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Expert":
|
|
|
|
|
|
fond = new Color(210, 190, 235);
|
|
|
|
|
|
couleurLigne = new Color(105, 55, 160);
|
|
|
|
|
|
couleurAvant = new Color(130, 85, 200);
|
|
|
|
|
|
couleurArriere = new Color(170, 60, 95);
|
|
|
|
|
|
couleurTexte = new Color(45, 20, 70);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Cauchemar":
|
|
|
|
|
|
fond = new Color(175, 160, 210);
|
|
|
|
|
|
couleurLigne = new Color(85, 65, 150);
|
|
|
|
|
|
couleurAvant = new Color(120, 90, 190);
|
|
|
|
|
|
couleurArriere = new Color(155, 55, 110);
|
|
|
|
|
|
couleurTexte = new Color(245, 245, 245);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Chaos":
|
|
|
|
|
|
fond = new Color(205, 120, 120);
|
|
|
|
|
|
couleurLigne = new Color(170, 40, 45);
|
|
|
|
|
|
couleurAvant = new Color(225, 115, 40);
|
|
|
|
|
|
couleurArriere = new Color(200, 30, 60);
|
|
|
|
|
|
couleurTexte = new Color(245, 245, 245);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Infernal":
|
|
|
|
|
|
fond = new Color(165, 70, 55);
|
|
|
|
|
|
couleurLigne = new Color(190, 35, 25);
|
|
|
|
|
|
couleurAvant = new Color(235, 95, 25);
|
|
|
|
|
|
couleurArriere = new Color(210, 25, 20);
|
|
|
|
|
|
couleurTexte = new Color(245, 245, 245);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Apocalypse":
|
|
|
|
|
|
fond = new Color(120, 40, 45);
|
|
|
|
|
|
couleurLigne = new Color(210, 30, 40);
|
|
|
|
|
|
couleurAvant = new Color(245, 95, 35);
|
|
|
|
|
|
couleurArriere = new Color(225, 20, 35);
|
|
|
|
|
|
couleurTexte = new Color(245, 245, 245);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Extreme":
|
|
|
|
|
|
fond = new Color(70, 70, 70);
|
|
|
|
|
|
couleurLigne = new Color(225, 225, 225);
|
|
|
|
|
|
couleurAvant = new Color(255, 235, 70);
|
|
|
|
|
|
couleurArriere = new Color(240, 80, 80);
|
|
|
|
|
|
couleurTexte = new Color(245, 245, 245);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Infini":
|
|
|
|
|
|
fond = new Color(35, 55, 85);
|
|
|
|
|
|
couleurLigne = new Color(95, 170, 255);
|
|
|
|
|
|
couleurAvant = new Color(70, 220, 255);
|
|
|
|
|
|
couleurArriere = new Color(180, 80, 255);
|
|
|
|
|
|
couleurTexte = new Color(245, 245, 245);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Au-dela":
|
|
|
|
|
|
fond = new Color(20, 30, 70);
|
|
|
|
|
|
couleurLigne = new Color(120, 155, 255);
|
|
|
|
|
|
couleurAvant = new Color(80, 205, 255);
|
|
|
|
|
|
couleurArriere = new Color(205, 95, 255);
|
|
|
|
|
|
couleurTexte = new Color(245, 245, 245);
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
fond = new Color(10, 15, 45);
|
|
|
|
|
|
couleurLigne = new Color(140, 120, 255);
|
|
|
|
|
|
couleurAvant = new Color(120, 225, 255);
|
|
|
|
|
|
couleurArriere = new Color(235, 95, 255);
|
|
|
|
|
|
couleurTexte = new Color(245, 245, 245);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ecran.setCouleurFond(fond);
|
|
|
|
|
|
ligne.setCouleurLigne(couleurLigne);
|
|
|
|
|
|
demiCercleAvant.setCouleur(couleurAvant);
|
|
|
|
|
|
demiCercleArriere.setCouleur(couleurArriere);
|
|
|
|
|
|
labScore.setForeground(couleurTexte);
|
|
|
|
|
|
labMeilleurScore.setForeground(couleurTexte);
|
|
|
|
|
|
labNiveau.setForeground(couleurTexte);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-25 20:54:24 +01:00
|
|
|
|
private boolean choisirNouveauCompte() {
|
|
|
|
|
|
List<String> pseudos = new ArrayList<>(db.getPseudos());
|
|
|
|
|
|
pseudos.add(0, "Sans compte");
|
|
|
|
|
|
|
|
|
|
|
|
String choix = (String) JOptionPane.showInputDialog(
|
|
|
|
|
|
null,
|
|
|
|
|
|
"Choisissez le compte pour la prochaine partie :",
|
|
|
|
|
|
"Changer de compte",
|
|
|
|
|
|
JOptionPane.QUESTION_MESSAGE,
|
|
|
|
|
|
null,
|
|
|
|
|
|
pseudos.toArray(String[]::new),
|
|
|
|
|
|
pseudos.get(0)
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (choix == null) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ("Sans compte".equals(choix)) {
|
|
|
|
|
|
idCompte = -1;
|
|
|
|
|
|
meilleurSansCompte = 0;
|
|
|
|
|
|
mortsSansCompte = 0;
|
|
|
|
|
|
tempsSansCompteSec = 0;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
idCompte = db.getIdParPseudo(choix);
|
|
|
|
|
|
}
|
|
|
|
|
|
rafraichirMeilleurScore();
|
|
|
|
|
|
return true;
|
2026-03-16 15:36:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-28 08:16:44 +01:00
|
|
|
|
private int choisirNouveauNiveau() {
|
|
|
|
|
|
// Générer les niveaux dynamiquement jusqu'à 100
|
|
|
|
|
|
String[] niveaux = new String[100];
|
|
|
|
|
|
for (int i = 1; i <= 100; i++) {
|
|
|
|
|
|
niveaux[i - 1] = genererLabelNiveau(i);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JList<String> list = new JList<>(niveaux);
|
|
|
|
|
|
list.setSelectedIndex(_niv - 1);
|
|
|
|
|
|
list.setVisibleRowCount(15);
|
|
|
|
|
|
JScrollPane scrollPane = new JScrollPane(list);
|
|
|
|
|
|
scrollPane.setPreferredSize(new java.awt.Dimension(350, 350));
|
|
|
|
|
|
|
|
|
|
|
|
int result = JOptionPane.showConfirmDialog(
|
|
|
|
|
|
null,
|
|
|
|
|
|
scrollPane,
|
|
|
|
|
|
"🎮 Sélection du Niveau - Linea",
|
|
|
|
|
|
JOptionPane.OK_CANCEL_OPTION,
|
|
|
|
|
|
JOptionPane.QUESTION_MESSAGE
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (result == JOptionPane.OK_OPTION) {
|
|
|
|
|
|
return list.getSelectedIndex() + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String genererLabelNiveau(int niveau) {
|
|
|
|
|
|
if (niveau <= 2) {
|
|
|
|
|
|
return "⭐ Niveau " + niveau + " - Facile" + (niveau == 2 ? "+" : "");
|
|
|
|
|
|
} else if (niveau <= 4) {
|
|
|
|
|
|
return "⭐⭐ Niveau " + niveau + " - Moyen" + (niveau == 4 ? "+" : "");
|
|
|
|
|
|
} else if (niveau <= 6) {
|
|
|
|
|
|
return "⭐⭐⭐ Niveau " + niveau + " - Difficile" + (niveau == 6 ? "+" : "");
|
|
|
|
|
|
} else if (niveau <= 8) {
|
|
|
|
|
|
return "⭐⭐⭐⭐ Niveau " + niveau + " - Très Difficile" + (niveau == 8 ? "+" : "");
|
|
|
|
|
|
} else if (niveau <= 10) {
|
|
|
|
|
|
return "⭐⭐⭐⭐⭐ Niveau " + niveau + " - Expert" + (niveau == 10 ? "+" : "");
|
|
|
|
|
|
} else if (niveau <= 12) {
|
|
|
|
|
|
return "🔥 Niveau " + niveau + " - Cauchemar" + (niveau == 12 ? "+" : "");
|
|
|
|
|
|
} else if (niveau <= 14) {
|
|
|
|
|
|
return "🔥 Niveau " + niveau + " - Chaos" + (niveau == 14 ? "+" : "");
|
|
|
|
|
|
} else if (niveau <= 16) {
|
|
|
|
|
|
return "💀 Niveau " + niveau + " - Infernal" + (niveau == 16 ? "+" : "");
|
|
|
|
|
|
} else if (niveau <= 18) {
|
|
|
|
|
|
return "💀 Niveau " + niveau + " - Apocalypse" + (niveau == 18 ? "+" : "");
|
|
|
|
|
|
} else if (niveau <= 20) {
|
|
|
|
|
|
return "⚡ Niveau " + niveau + " - Extrême" + (niveau == 20 ? "+" : "");
|
|
|
|
|
|
} else if (niveau <= 30) {
|
|
|
|
|
|
return "⚡ Niveau " + niveau + " - Infini";
|
|
|
|
|
|
} else if (niveau <= 50) {
|
|
|
|
|
|
return "∞ Niveau " + niveau + " - Au-delà";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return "🌌 Niveau " + niveau + " - Cosmos";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-03-28 14:18:17 +01:00
|
|
|
|
|
2026-03-28 08:16:44 +01:00
|
|
|
|
private void choisirModeImmortel() {
|
|
|
|
|
|
int result = JOptionPane.showConfirmDialog(
|
|
|
|
|
|
null,
|
|
|
|
|
|
"Activer le mode IMMORTEL ? 🛡️\n(Vous ne pourrez pas mourir)",
|
|
|
|
|
|
"Mode Immortel",
|
|
|
|
|
|
JOptionPane.YES_NO_OPTION,
|
|
|
|
|
|
JOptionPane.QUESTION_MESSAGE
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
immortel = (result == JOptionPane.YES_OPTION);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-16 15:36:24 +01:00
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
// METHODES DE GESTION DU JEU
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Centralise la création et la configuration des objets du jeu.
|
|
|
|
|
|
* Évite de répéter ce code dans demarrer() et resetLevel().
|
|
|
|
|
|
*/
|
|
|
|
|
|
private void initialiserPartie() {
|
|
|
|
|
|
// 1. Nettoyage de l'écran
|
|
|
|
|
|
ecran.reinitialiser();
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Création des instances
|
|
|
|
|
|
demiCercleAvant = new Cercle(90, -180);
|
|
|
|
|
|
demiCercleArriere = new Cercle(90, 180);
|
|
|
|
|
|
ligne = new Ligne(_niv);
|
2026-03-28 14:18:17 +01:00
|
|
|
|
ecran.setNiveau(_niv);
|
|
|
|
|
|
|
|
|
|
|
|
// 3. En mode immortel, positionner les cercles loin (la force les attirera vers la ligne)
|
|
|
|
|
|
// En mode normal, ils restent au centre (y = 200 par défaut du constructeur)
|
|
|
|
|
|
if (immortel) {
|
|
|
|
|
|
demiCercleAvant.y = -300;
|
|
|
|
|
|
demiCercleArriere.y = 300;
|
|
|
|
|
|
}
|
2026-03-16 15:36:24 +01:00
|
|
|
|
|
2026-03-28 14:18:17 +01:00
|
|
|
|
// 4. Configuration visuelle
|
|
|
|
|
|
appliquerThemeNiveau();
|
2026-03-16 15:36:24 +01:00
|
|
|
|
|
2026-03-28 14:18:17 +01:00
|
|
|
|
// 5. Ajout à l'écran (l'ordre définit la superposition)
|
2026-03-16 15:36:24 +01:00
|
|
|
|
ecran.ajouterObjet(demiCercleArriere);
|
|
|
|
|
|
ecran.ajouterObjet(ligne);
|
|
|
|
|
|
ecran.ajouterObjet(demiCercleAvant);
|
2026-03-28 14:18:17 +01:00
|
|
|
|
|
|
|
|
|
|
rafraichirNiveau();
|
2026-03-16 15:36:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void demarrer() {
|
2026-03-28 08:16:44 +01:00
|
|
|
|
// Demander si le mode immortel est activé
|
|
|
|
|
|
choisirModeImmortel();
|
|
|
|
|
|
|
|
|
|
|
|
// Passer le flag immortel à l'écran
|
|
|
|
|
|
ecran.setImmortel(immortel);
|
|
|
|
|
|
|
2026-03-28 14:18:17 +01:00
|
|
|
|
fenetre = new JFrame();
|
|
|
|
|
|
rafraichirTitreFenetre();
|
2026-03-16 15:36:24 +01:00
|
|
|
|
|
|
|
|
|
|
// Initialise les objets une première fois
|
|
|
|
|
|
initialiserPartie();
|
|
|
|
|
|
|
|
|
|
|
|
ecran.addKeyListener(this);
|
|
|
|
|
|
ecran.setFocusable(true);
|
|
|
|
|
|
fenetre.setContentPane(ecran);
|
|
|
|
|
|
fenetre.pack();
|
|
|
|
|
|
fenetre.setLocation(100, 100);
|
|
|
|
|
|
fenetre.setVisible(true);
|
|
|
|
|
|
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
|
|
|
|
|
|
|
// Création et lancement du timer
|
|
|
|
|
|
horloge = new Timer(40, this);
|
|
|
|
|
|
horloge.start();
|
2026-03-25 20:54:24 +01:00
|
|
|
|
debutPartieMs = System.currentTimeMillis();
|
2026-03-16 15:36:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void resetLevel() {
|
|
|
|
|
|
// Réinitialisation des variables de jeu
|
|
|
|
|
|
score = 0;
|
|
|
|
|
|
labScore.setText("<html><h3>score : 0</h3></html>");
|
2026-03-28 08:16:44 +01:00
|
|
|
|
|
|
|
|
|
|
// Passer le flag immortel à l'écran
|
|
|
|
|
|
ecran.setImmortel(immortel);
|
2026-03-28 14:18:17 +01:00
|
|
|
|
rafraichirTitreFenetre();
|
2026-03-28 08:16:44 +01:00
|
|
|
|
|
2026-03-16 15:36:24 +01:00
|
|
|
|
// Ré-initialisation des objets graphiques
|
|
|
|
|
|
initialiserPartie();
|
2026-03-25 20:54:24 +01:00
|
|
|
|
debutPartieMs = System.currentTimeMillis();
|
2026-03-16 15:36:24 +01:00
|
|
|
|
|
|
|
|
|
|
// Relance le timer existant et redonne le focus
|
|
|
|
|
|
if (horloge != null) horloge.restart();
|
|
|
|
|
|
ecran.requestFocusInWindow();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
// EVENEMENTS (Timer & Clavier)
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
|
ecran.traiterBoucleAnimation();
|
2026-03-28 08:16:44 +01:00
|
|
|
|
|
|
|
|
|
|
// Vérifier si un bonus a été récupéré
|
|
|
|
|
|
int bonus = ecran.getBonusRecupere();
|
|
|
|
|
|
if (bonus != 0) {
|
|
|
|
|
|
ecran.reinitialiserBonus();
|
2026-03-28 14:18:17 +01:00
|
|
|
|
int niveauActuel = _niv;
|
2026-03-28 08:16:44 +01:00
|
|
|
|
int nouveauNiveau = _niv + bonus;
|
|
|
|
|
|
|
|
|
|
|
|
// Limiter le niveau entre 1 et 100
|
|
|
|
|
|
if (nouveauNiveau < 1) {
|
|
|
|
|
|
nouveauNiveau = 1;
|
|
|
|
|
|
} else if (nouveauNiveau > 100) {
|
|
|
|
|
|
nouveauNiveau = 100;
|
|
|
|
|
|
}
|
2026-03-28 14:18:17 +01:00
|
|
|
|
|
|
|
|
|
|
if (modeCampagne && idCompte > 0 && bonus > 0) {
|
|
|
|
|
|
db.debloquerNiveauCampagne(idCompte, niveauActuel);
|
|
|
|
|
|
}
|
2026-03-28 08:16:44 +01:00
|
|
|
|
|
|
|
|
|
|
_niv = nouveauNiveau;
|
|
|
|
|
|
resetLevel();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-03-16 15:36:24 +01:00
|
|
|
|
|
2026-03-28 08:16:44 +01:00
|
|
|
|
if (ecran.aCollision() && !immortel) {
|
2026-03-16 15:36:24 +01:00
|
|
|
|
horloge.stop();
|
2026-03-25 20:54:24 +01:00
|
|
|
|
|
|
|
|
|
|
int scoreActuel = (int) score;
|
|
|
|
|
|
int tempsPartieSec = (int) ((System.currentTimeMillis() - debutPartieMs) / 1000L);
|
|
|
|
|
|
enregistrerPartie(scoreActuel, tempsPartieSec);
|
2026-03-16 15:36:24 +01:00
|
|
|
|
|
2026-03-25 20:54:24 +01:00
|
|
|
|
rafraichirMeilleurScore();
|
|
|
|
|
|
|
|
|
|
|
|
while (true) {
|
2026-03-28 14:18:17 +01:00
|
|
|
|
Object[] options = modeCampagne
|
|
|
|
|
|
? new Object[]{"▶️ Relancer", "📊 Statistiques", "❌ Quitter"}
|
|
|
|
|
|
: new Object[]{"▶️ Relancer", "👤 Compte", "📈 Niveau", "📊 Statistiques", "❌ Quitter"};
|
|
|
|
|
|
String message = "🏁 GAME OVER\n\n"
|
|
|
|
|
|
+ "Score: " + scoreActuel + "\n"
|
|
|
|
|
|
+ "Meilleur: " + meilleurActuel() + "\n"
|
|
|
|
|
|
+ "Durée: " + tempsPartieSec + "s";
|
|
|
|
|
|
|
2026-03-25 20:54:24 +01:00
|
|
|
|
int choix = JOptionPane.showOptionDialog(null,
|
2026-03-28 14:18:17 +01:00
|
|
|
|
message,
|
|
|
|
|
|
"🏁 Fin de Partie",
|
2026-03-25 20:54:24 +01:00
|
|
|
|
JOptionPane.DEFAULT_OPTION,
|
2026-03-28 14:18:17 +01:00
|
|
|
|
JOptionPane.PLAIN_MESSAGE,
|
2026-03-25 20:54:24 +01:00
|
|
|
|
null, options, options[0]);
|
|
|
|
|
|
|
|
|
|
|
|
if (choix == 0) {
|
2026-03-28 14:18:17 +01:00
|
|
|
|
int modeRelance = JOptionPane.showConfirmDialog(
|
|
|
|
|
|
null,
|
|
|
|
|
|
"Relancer en mode immortel ?",
|
|
|
|
|
|
"Relancer",
|
|
|
|
|
|
JOptionPane.YES_NO_CANCEL_OPTION,
|
|
|
|
|
|
JOptionPane.QUESTION_MESSAGE
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (modeRelance == JOptionPane.CANCEL_OPTION || modeRelance == JOptionPane.CLOSED_OPTION) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
immortel = (modeRelance == JOptionPane.YES_OPTION);
|
|
|
|
|
|
ecran.setImmortel(immortel);
|
2026-03-25 20:54:24 +01:00
|
|
|
|
resetLevel();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2026-03-28 14:18:17 +01:00
|
|
|
|
if (modeCampagne) {
|
|
|
|
|
|
if (choix == 1) {
|
|
|
|
|
|
JOptionPane.showMessageDialog(null, statsActuelles(), "📊 Statistiques", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
System.exit(0);
|
|
|
|
|
|
}
|
2026-03-25 20:54:24 +01:00
|
|
|
|
if (choix == 1) {
|
|
|
|
|
|
if (choisirNouveauCompte()) {
|
|
|
|
|
|
resetLevel();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (choix == 2) {
|
2026-03-28 08:16:44 +01:00
|
|
|
|
int nouveauNiveau = choisirNouveauNiveau();
|
|
|
|
|
|
if (nouveauNiveau > 0) {
|
|
|
|
|
|
_niv = nouveauNiveau;
|
|
|
|
|
|
resetLevel();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (choix == 3) {
|
2026-03-28 14:18:17 +01:00
|
|
|
|
JOptionPane.showMessageDialog(null, statsActuelles(), "📊 Statistiques", JOptionPane.INFORMATION_MESSAGE);
|
2026-03-25 20:54:24 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
System.exit(0);
|
|
|
|
|
|
}
|
2026-03-16 15:36:24 +01:00
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Calcul du score basé sur le temps écoulé
|
|
|
|
|
|
score += (0.05 + (0.05 * horloge.getDelay() / 100.0));
|
|
|
|
|
|
labScore.setText("<html><h3>score : " + (int)score + "</h3></html>");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void keyPressed(KeyEvent e) {
|
|
|
|
|
|
if (e.getKeyCode() == KeyEvent.VK_UP) {
|
|
|
|
|
|
demiCercleAvant.Monter();
|
|
|
|
|
|
demiCercleArriere.Monter();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void keyReleased(KeyEvent e) {
|
|
|
|
|
|
if (e.getKeyCode() == KeyEvent.VK_UP) {
|
|
|
|
|
|
demiCercleAvant.ArreterMonter();
|
|
|
|
|
|
demiCercleArriere.ArreterMonter();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void keyTyped(KeyEvent e) {}
|
|
|
|
|
|
}
|