Ajout menu et boule(Bug sur cette derniere)
This commit is contained in:
122
linea/Jeu.java
122
linea/Jeu.java
@@ -11,8 +11,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.Timer;
|
||||
|
||||
public class Jeu implements KeyListener, ActionListener {
|
||||
@@ -25,7 +27,7 @@ public class Jeu implements KeyListener, ActionListener {
|
||||
protected Cercle demiCercleArriere;
|
||||
protected Ligne ligne;
|
||||
|
||||
private int _niv = 1;
|
||||
private int _niv;
|
||||
protected Timer horloge;
|
||||
protected double score = 0;
|
||||
protected JLabel labScore;
|
||||
@@ -36,6 +38,7 @@ public class Jeu implements KeyListener, ActionListener {
|
||||
private int mortsSansCompte = 0;
|
||||
private int tempsSansCompteSec = 0;
|
||||
private long debutPartieMs = 0;
|
||||
private boolean immortel = false;
|
||||
|
||||
private int meilleurActuel() {
|
||||
return idCompte > 0 ? db.getMeilleurScoreParCompte(idCompte) : meilleurSansCompte;
|
||||
@@ -63,9 +66,10 @@ public class Jeu implements KeyListener, ActionListener {
|
||||
//-------------------------------------------------------------------------
|
||||
// CONSTRUCTEUR
|
||||
//-------------------------------------------------------------------------
|
||||
public Jeu(DatabaseConnection db, int idCompte) {
|
||||
public Jeu(DatabaseConnection db, int idCompte, int niveau) {
|
||||
this.db = db;
|
||||
this.idCompte = idCompte;
|
||||
this._niv = niveau;
|
||||
labScore = new JLabel();
|
||||
labScore.setText("<html><h3>score : 0</h3></html>");
|
||||
|
||||
@@ -113,6 +117,75 @@ public class Jeu implements KeyListener, ActionListener {
|
||||
return true;
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// METHODES DE GESTION DU JEU
|
||||
//-------------------------------------------------------------------------
|
||||
@@ -141,7 +214,13 @@ public class Jeu implements KeyListener, ActionListener {
|
||||
}
|
||||
|
||||
public void demarrer() {
|
||||
JFrame fenetre = new JFrame("Linea Game");
|
||||
// Demander si le mode immortel est activé
|
||||
choisirModeImmortel();
|
||||
|
||||
// Passer le flag immortel à l'écran
|
||||
ecran.setImmortel(immortel);
|
||||
|
||||
JFrame fenetre = new JFrame("Linea Game" + (immortel ? " [MODE IMMORTEL 🛡️]" : ""));
|
||||
|
||||
// Initialise les objets une première fois
|
||||
initialiserPartie();
|
||||
@@ -165,6 +244,12 @@ public class Jeu implements KeyListener, ActionListener {
|
||||
score = 0;
|
||||
labScore.setText("<html><h3>score : 0</h3></html>");
|
||||
|
||||
// Demander le mode immortel à chaque reset
|
||||
choisirModeImmortel();
|
||||
|
||||
// Passer le flag immortel à l'écran
|
||||
ecran.setImmortel(immortel);
|
||||
|
||||
// Ré-initialisation des objets graphiques
|
||||
initialiserPartie();
|
||||
debutPartieMs = System.currentTimeMillis();
|
||||
@@ -181,8 +266,26 @@ public class Jeu implements KeyListener, ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ecran.traiterBoucleAnimation();
|
||||
|
||||
// Vérifier si un bonus a été récupéré
|
||||
int bonus = ecran.getBonusRecupere();
|
||||
if (bonus != 0) {
|
||||
ecran.reinitialiserBonus();
|
||||
int nouveauNiveau = _niv + bonus;
|
||||
|
||||
// Limiter le niveau entre 1 et 100
|
||||
if (nouveauNiveau < 1) {
|
||||
nouveauNiveau = 1;
|
||||
} else if (nouveauNiveau > 100) {
|
||||
nouveauNiveau = 100;
|
||||
}
|
||||
|
||||
_niv = nouveauNiveau;
|
||||
resetLevel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (ecran.aCollision()) {
|
||||
if (ecran.aCollision() && !immortel) {
|
||||
horloge.stop();
|
||||
|
||||
int scoreActuel = (int) score;
|
||||
@@ -192,7 +295,7 @@ public class Jeu implements KeyListener, ActionListener {
|
||||
rafraichirMeilleurScore();
|
||||
|
||||
while (true) {
|
||||
Object[] options = {"Relancer", "Changer de compte", "Voir stats", "Quitter"};
|
||||
Object[] options = {"Relancer", "Changer de compte", "Changer de niveau", "Voir stats", "Quitter"};
|
||||
int choix = JOptionPane.showOptionDialog(null,
|
||||
"Perdu\nScore : " + scoreActuel + "\nMeilleur : " + meilleurActuel(),
|
||||
"Game Over",
|
||||
@@ -212,6 +315,15 @@ public class Jeu implements KeyListener, ActionListener {
|
||||
continue;
|
||||
}
|
||||
if (choix == 2) {
|
||||
int nouveauNiveau = choisirNouveauNiveau();
|
||||
if (nouveauNiveau > 0) {
|
||||
_niv = nouveauNiveau;
|
||||
resetLevel();
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (choix == 3) {
|
||||
JOptionPane.showMessageDialog(null, statsActuelles(), "Statistiques", JOptionPane.INFORMATION_MESSAGE);
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user