forked from menault/TD3_DEV51_Qualite_Algo
ajout d'un bouton retour
This commit is contained in:
@@ -10,16 +10,16 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Interface graphique du jeu du pendu avec gestion des difficultés.
|
||||
* - Niveau Facile : mots de moins de 8 lettres
|
||||
* - Niveau Moyen : mots de 8 lettres ou plus
|
||||
* - Niveau Difficile : deux mots à deviner à la suite (un court + un long)
|
||||
* - Niveau 1 : mots de moins de 8 lettres
|
||||
* - Niveau 2 : mots de 8 lettres ou plus
|
||||
* - Niveau 3 : deux mots à deviner à la suite (un court + un long)
|
||||
* Toutes les méthodes ≤ 50 lignes.
|
||||
*/
|
||||
public class GameUI {
|
||||
private JFrame frame;
|
||||
private JLabel imgLabel, wordLabel, triedLabel, scoreLabel, timeLabel;
|
||||
private JTextField input;
|
||||
private JButton tryBtn, quitBtn;
|
||||
private JButton tryBtn, quitBtn, menuBtn;
|
||||
|
||||
private Game game;
|
||||
private List<String> words;
|
||||
@@ -63,7 +63,7 @@ public class GameUI {
|
||||
if (longW != null) words.add(longW);
|
||||
}
|
||||
|
||||
if (words.isEmpty()) words.add(Words.random()); // fallback si rien
|
||||
if (words.isEmpty()) words.add(Words.random());
|
||||
}
|
||||
|
||||
/** Crée la fenêtre principale */
|
||||
@@ -90,16 +90,23 @@ public class GameUI {
|
||||
top.add(buildTopLine(triedLabel, timeLabel));
|
||||
frame.add(top, BorderLayout.NORTH);
|
||||
|
||||
// --- Bas : boutons + saisie
|
||||
JPanel bottom = new JPanel(new BorderLayout(8, 8));
|
||||
JPanel inputPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
input = new JTextField(5);
|
||||
tryBtn = new JButton("Essayer");
|
||||
quitBtn = new JButton("Quitter");
|
||||
inputPanel.add(new JLabel("Lettre :"));
|
||||
inputPanel.add(input);
|
||||
inputPanel.add(tryBtn);
|
||||
|
||||
JPanel actionPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
menuBtn = new JButton("Menu");
|
||||
quitBtn = new JButton("Quitter");
|
||||
actionPanel.add(menuBtn);
|
||||
actionPanel.add(quitBtn);
|
||||
|
||||
bottom.add(inputPanel, BorderLayout.WEST);
|
||||
bottom.add(quitBtn, BorderLayout.EAST);
|
||||
bottom.add(actionPanel, BorderLayout.EAST);
|
||||
frame.add(bottom, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
@@ -117,13 +124,22 @@ public class GameUI {
|
||||
tryBtn.addActionListener(this::onTry);
|
||||
input.addActionListener(this::onTry);
|
||||
quitBtn.addActionListener(e -> frame.dispose());
|
||||
menuBtn.addActionListener(e -> returnToMenu());
|
||||
timer = new Timer(1000, e -> refreshStatsOnly());
|
||||
}
|
||||
|
||||
/** Retour au menu principal */
|
||||
private void returnToMenu() {
|
||||
timer.stop();
|
||||
frame.dispose();
|
||||
MenuUI menu = new MenuUI();
|
||||
menu.show();
|
||||
}
|
||||
|
||||
/** Démarre un nouveau mot (ou termine au niveau 3) */
|
||||
private void startRound() {
|
||||
if (index >= words.size()) {
|
||||
showMsg("Niveau terminé !");
|
||||
showMsg("🎉 Niveau terminé !");
|
||||
frame.dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user