forked from menault/TD3_DEV51_Qualite_Algo
Compare commits
8 Commits
5b7f341011
...
d8647f43ac
| Author | SHA1 | Date | |
|---|---|---|---|
| d8647f43ac | |||
| d75f05bee0 | |||
| 64108a95e9 | |||
| c0d2e0e5e2 | |||
| 78333b0c32 | |||
| 790c3faff2 | |||
| d2dd0bb982 | |||
| 485b63357e |
@@ -2,84 +2,129 @@ package back;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.*;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fournit les mots pour le jeu.
|
* Gère la bibliothèque de mots (chargement + sélection aléatoire).
|
||||||
* - Lit d'abord "bibliothèque/mots.txt" (UTF-8), 1 mot par ligne.
|
* - Lit "bibliothèque/mots.txt" OU "Bibliotheque/mots.txt" (UTF-8), 1 mot par ligne.
|
||||||
* - Ignore les lignes vides et celles qui commencent par '#'.
|
* - Ignore lignes vides et commentaires (#...).
|
||||||
* - Si le fichier est introuvable ou vide, bascule sur une liste par défaut.
|
* - Fournit des helpers pour tirer des mots selon la difficulté.
|
||||||
*/
|
*/
|
||||||
public class Words {
|
public class Words {
|
||||||
|
|
||||||
/** Chemin du fichier de mots (relatif à la racine du projet). */
|
/** Chemins possibles (accents/casse) pour maximiser la compatibilité. */
|
||||||
private static final Path WORDS_PATH = Paths.get("Bibliotheque", "mots.txt");
|
private static final Path[] CANDIDATES = new Path[] {
|
||||||
|
Paths.get("bibliothèque", "mots.txt"),
|
||||||
|
Paths.get("Bibliotheque", "mots.txt")
|
||||||
|
};
|
||||||
|
|
||||||
/** Liste de secours si le fichier n'est pas disponible. */
|
/** Liste de secours si aucun fichier trouvé/valide. */
|
||||||
private static final List<String> DEFAULT = List.of(
|
private static final List<String> DEFAULT = new ArrayList<>();
|
||||||
"algorithm", "variable", "function", "interface", "inheritance",
|
static {
|
||||||
"exception", "compiler", "database", "network", "architecture",
|
Collections.addAll(DEFAULT,
|
||||||
"iteration", "recursion", "encryption", "framework", "protocol"
|
"algorithm","variable","function","interface","inheritance",
|
||||||
);
|
"exception","compiler","database","network","architecture",
|
||||||
|
"iteration","recursion","encryption","framework","protocol",
|
||||||
|
"java","pendu","ordinateur","developpement","interface"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** RNG partagé et cache des mots chargés. */
|
/** Cache mémoire + RNG. */
|
||||||
private static final SecureRandom RNG = new SecureRandom();
|
|
||||||
private static volatile List<String> CACHE = null;
|
private static volatile List<String> CACHE = null;
|
||||||
|
private static final SecureRandom RNG = new SecureRandom();
|
||||||
|
|
||||||
/**
|
/** Renvoie la liste complète (copie) — charge une seule fois si nécessaire. */
|
||||||
* Retourne un mot choisi au hasard depuis le fichier ou la liste par défaut.
|
public static List<String> all() {
|
||||||
* Déclenche un chargement paresseux (lazy-load) si nécessaire.
|
ensureLoaded();
|
||||||
*/
|
return new ArrayList<>(CACHE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Renvoie un mot aléatoire dans tout le dictionnaire. */
|
||||||
public static String random() {
|
public static String random() {
|
||||||
ensureLoaded();
|
ensureLoaded();
|
||||||
return CACHE.get(RNG.nextInt(CACHE.size()));
|
return CACHE.get(RNG.nextInt(CACHE.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Renvoie un mot aléatoire de moins de 8 lettres (sinon bascule sur random()). */
|
||||||
* Recharge les mots depuis le fichier. Utile si modification de mots.txt à chaud.
|
public static String randomShortWord() {
|
||||||
*/
|
ensureLoaded();
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
for (String w : CACHE) if (w.length() < 8) list.add(w);
|
||||||
|
if (list.isEmpty()) return random();
|
||||||
|
return list.get(RNG.nextInt(list.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Renvoie un mot aléatoire de 8 lettres ou plus (sinon bascule sur random()). */
|
||||||
|
public static String randomLongWord() {
|
||||||
|
ensureLoaded();
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
for (String w : CACHE) if (w.length() >= 8) list.add(w);
|
||||||
|
if (list.isEmpty()) return random();
|
||||||
|
return list.get(RNG.nextInt(list.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Renvoie une paire [court, long] pour le niveau difficile. */
|
||||||
|
public static List<String> randomPair() {
|
||||||
|
List<String> pair = new ArrayList<>(2);
|
||||||
|
pair.add(randomShortWord());
|
||||||
|
pair.add(randomLongWord());
|
||||||
|
return pair;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Force le rechargement du fichier (au cas où le contenu change en cours d’exécution). */
|
||||||
public static synchronized void reload() {
|
public static synchronized void reload() {
|
||||||
CACHE = loadFromFileOrDefault();
|
CACHE = loadFromFileOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Garantit que le cache est initialisé. */
|
// -------------------- internes --------------------
|
||||||
|
|
||||||
|
/** Charge le cache si nécessaire (thread-safe). */
|
||||||
private static void ensureLoaded() {
|
private static void ensureLoaded() {
|
||||||
if (CACHE == null) {
|
if (CACHE == null) {
|
||||||
synchronized (Words.class) {
|
synchronized (Words.class) {
|
||||||
if (CACHE == null) {
|
if (CACHE == null) CACHE = loadFromFileOrDefault();
|
||||||
CACHE = loadFromFileOrDefault();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Tente de charger depuis le fichier, sinon renvoie la liste par défaut. */
|
/** Tente chaque chemin candidat, sinon retourne DEFAULT mélangé. */
|
||||||
private static List<String> loadFromFileOrDefault() {
|
private static List<String> loadFromFileOrDefault() {
|
||||||
List<String> fromFile = readUtf8Lines(WORDS_PATH);
|
List<String> data = readFirstExistingCandidate();
|
||||||
if (fromFile.isEmpty()) return DEFAULT;
|
if (data.isEmpty()) {
|
||||||
return fromFile;
|
data = new ArrayList<>(DEFAULT);
|
||||||
|
}
|
||||||
|
Collections.shuffle(data, RNG); // casse tout déterminisme initial
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Lit le premier fichier existant parmi les candidats. */
|
||||||
* Lit toutes les lignes UTF-8 depuis le chemin fourni,
|
private static List<String> readFirstExistingCandidate() {
|
||||||
* en filtrant vides et commentaires (# ...).
|
for (Path p : CANDIDATES) {
|
||||||
*/
|
List<String> list = readUtf8Trimmed(p);
|
||||||
private static List<String> readUtf8Lines(Path path) {
|
if (!list.isEmpty()) return list;
|
||||||
List<String> result = new ArrayList<>();
|
|
||||||
try (Stream<String> lines = Files.lines(path, StandardCharsets.UTF_8)) {
|
|
||||||
lines.map(String::trim)
|
|
||||||
.filter(s -> !s.isEmpty())
|
|
||||||
.filter(s -> !s.startsWith("#"))
|
|
||||||
.forEach(result::add);
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Silencieux : on basculera sur DEFAULT
|
|
||||||
}
|
}
|
||||||
return result;
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Lit un fichier UTF-8, filtre vides/commentaires, force lowercase. */
|
||||||
|
private static List<String> readUtf8Trimmed(Path path) {
|
||||||
|
List<String> out = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
|
||||||
|
for (String raw : lines) {
|
||||||
|
if (raw == null) continue;
|
||||||
|
String s = raw.trim().toLowerCase();
|
||||||
|
if (s.isEmpty() || s.startsWith("#")) continue;
|
||||||
|
// On accepte lettres/accentuées + tiret (simple et robuste)
|
||||||
|
if (s.matches("[a-zàâçéèêëîïôûùüÿñæœ-]+")) out.add(s);
|
||||||
|
}
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
// on tombera sur DEFAULT
|
||||||
|
}
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,29 +5,71 @@ import back.*;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface graphique du jeu du pendu.
|
* Interface graphique du pendu avec niveaux :
|
||||||
|
* - 1 : mots < 8 lettres
|
||||||
|
* - 2 : mots ≥ 8 lettres
|
||||||
|
* - 3 : deux mots (score + chrono cumulés)
|
||||||
|
* Boutons : Essayer / Nouvelle partie / Menu / Quitter.
|
||||||
|
* (Toutes les méthodes ≤ 50 lignes)
|
||||||
*/
|
*/
|
||||||
public class GameUI {
|
public class GameUI {
|
||||||
private JFrame frame;
|
private JFrame frame;
|
||||||
private JLabel imgLabel, wordLabel, triedLabel, scoreLabel, timeLabel;
|
private JLabel imgLabel, wordLabel, triedLabel, scoreLabel, timeLabel;
|
||||||
private JTextField input;
|
private JTextField input;
|
||||||
private JButton tryBtn, newGameBtn;
|
private JButton tryBtn, newBtn, menuBtn, quitBtn;
|
||||||
|
|
||||||
private Game game;
|
private Game game;
|
||||||
private String currentWord;
|
private List<String> words;
|
||||||
|
private int index = 0;
|
||||||
|
private final int level;
|
||||||
|
private String currentWord = "";
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
|
|
||||||
/** Lance la fenêtre et démarre une partie */
|
// Cumul de session (niveau 3)
|
||||||
|
private long sessionStartNano = -1L;
|
||||||
|
private int sessionScore = 0;
|
||||||
|
|
||||||
|
/** Reçoit la difficulté (1, 2, 3). */
|
||||||
|
public GameUI(int level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Affiche la fenêtre et lance la session. */
|
||||||
public void show() {
|
public void show() {
|
||||||
setupWindow();
|
setupWindow();
|
||||||
setupLayout();
|
setupLayout();
|
||||||
setupActions();
|
setupActions();
|
||||||
startNewGame();
|
startNewSession();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Crée la fenêtre principale */
|
/** Démarre une nouvelle session (nouveaux mots, reset chrono/score session). */
|
||||||
|
private void startNewSession() {
|
||||||
|
sessionStartNano = System.nanoTime();
|
||||||
|
sessionScore = 0;
|
||||||
|
index = 0;
|
||||||
|
prepareWords();
|
||||||
|
startRound();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Prépare la liste des mots selon le niveau (aléatoire géré dans Words). */
|
||||||
|
private void prepareWords() {
|
||||||
|
words = new ArrayList<>();
|
||||||
|
if (level == 1) {
|
||||||
|
words.add(Words.randomShortWord());
|
||||||
|
} else if (level == 2) {
|
||||||
|
words.add(Words.randomLongWord());
|
||||||
|
} else if (level == 3) {
|
||||||
|
words = Words.randomPair(); // [court, long] aléatoires
|
||||||
|
}
|
||||||
|
if (words.isEmpty()) words.add(Words.random()); // filet de sécurité
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Fenêtre principale. */
|
||||||
private void setupWindow() {
|
private void setupWindow() {
|
||||||
frame = new JFrame("Jeu du Pendu");
|
frame = new JFrame("Jeu du Pendu");
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
@@ -36,7 +78,7 @@ public class GameUI {
|
|||||||
frame.setLayout(new BorderLayout(12, 12));
|
frame.setLayout(new BorderLayout(12, 12));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Construit les composants et le layout */
|
/** Layout + composants. */
|
||||||
private void setupLayout() {
|
private void setupLayout() {
|
||||||
imgLabel = new JLabel("", SwingConstants.CENTER);
|
imgLabel = new JLabel("", SwingConstants.CENTER);
|
||||||
frame.add(imgLabel, BorderLayout.CENTER);
|
frame.add(imgLabel, BorderLayout.CENTER);
|
||||||
@@ -55,35 +97,59 @@ public class GameUI {
|
|||||||
JPanel inputPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
JPanel inputPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
input = new JTextField(5);
|
input = new JTextField(5);
|
||||||
tryBtn = new JButton("Essayer");
|
tryBtn = new JButton("Essayer");
|
||||||
newGameBtn = new JButton("Nouvelle partie");
|
newBtn = new JButton("Nouvelle partie");
|
||||||
inputPanel.add(new JLabel("Lettre :"));
|
inputPanel.add(new JLabel("Lettre :"));
|
||||||
inputPanel.add(input);
|
inputPanel.add(input);
|
||||||
inputPanel.add(tryBtn);
|
inputPanel.add(tryBtn);
|
||||||
|
inputPanel.add(newBtn);
|
||||||
|
|
||||||
|
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(inputPanel, BorderLayout.WEST);
|
||||||
bottom.add(newGameBtn, BorderLayout.EAST);
|
bottom.add(actionPanel, BorderLayout.EAST);
|
||||||
frame.add(bottom, BorderLayout.SOUTH);
|
frame.add(bottom, BorderLayout.SOUTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Crée une ligne du haut avec 2 labels */
|
/** Ligne d’infos (gauche/droite). */
|
||||||
private JPanel buildTopLine(JLabel left, JLabel right) {
|
private JPanel buildTopLine(JLabel left, JLabel right) {
|
||||||
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
panel.add(left);
|
p.add(left);
|
||||||
panel.add(Box.createHorizontalStrut(24));
|
p.add(Box.createHorizontalStrut(24));
|
||||||
panel.add(right);
|
p.add(right);
|
||||||
return panel;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Ajoute les actions et le timer */
|
/** Actions + timer. */
|
||||||
private void setupActions() {
|
private void setupActions() {
|
||||||
tryBtn.addActionListener(this::onTry);
|
tryBtn.addActionListener(this::onTry);
|
||||||
input.addActionListener(this::onTry);
|
input.addActionListener(this::onTry);
|
||||||
newGameBtn.addActionListener(e -> startNewGame());
|
newBtn.addActionListener(e -> startNewSession());
|
||||||
|
menuBtn.addActionListener(e -> returnToMenu());
|
||||||
|
quitBtn.addActionListener(e -> frame.dispose());
|
||||||
timer = new Timer(1000, e -> refreshStatsOnly());
|
timer = new Timer(1000, e -> refreshStatsOnly());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Démarre une nouvelle partie */
|
/** Retour vers le menu de sélection. */
|
||||||
private void startNewGame() {
|
private void returnToMenu() {
|
||||||
currentWord = Words.random();
|
timer.stop();
|
||||||
|
frame.dispose();
|
||||||
|
MenuUI menu = new MenuUI();
|
||||||
|
menu.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Démarre un nouveau mot (ou termine la session si plus de mots). */
|
||||||
|
private void startRound() {
|
||||||
|
if (index >= words.size()) {
|
||||||
|
int total = (level == 3) ? sessionScore : game.getScore();
|
||||||
|
long secs = (level == 3) ? getSessionSeconds() : game.getElapsedSeconds();
|
||||||
|
showMsg("Niveau terminé !\nScore total : " + total + "\nTemps : " + secs + "s");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
currentWord = words.get(index++);
|
||||||
game = new Game(currentWord, 7);
|
game = new Game(currentWord, 7);
|
||||||
input.setText("");
|
input.setText("");
|
||||||
input.requestFocusInWindow();
|
input.requestFocusInWindow();
|
||||||
@@ -91,7 +157,7 @@ public class GameUI {
|
|||||||
refreshUI();
|
refreshUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gère le clic ou l'appui sur Entrée */
|
/** Tente une lettre (bouton/Entrée). */
|
||||||
private void onTry(ActionEvent e) {
|
private void onTry(ActionEvent e) {
|
||||||
String text = input.getText();
|
String text = input.getText();
|
||||||
if (!Check.isLetter(text)) {
|
if (!Check.isLetter(text)) {
|
||||||
@@ -101,38 +167,34 @@ public class GameUI {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Result res = game.play(Character.toLowerCase(text.charAt(0)));
|
Result res = game.play(Character.toLowerCase(text.charAt(0)));
|
||||||
handleResult(res);
|
if (res == Result.ALREADY) showMsg("Lettre déjà utilisée.");
|
||||||
input.setText("");
|
input.setText("");
|
||||||
refreshUI();
|
refreshUI();
|
||||||
checkEnd();
|
checkEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Réagit selon le résultat d'une tentative */
|
/** Fin du mot → affiche popup et enchaîne (lvl 3 cumule score/chrono). */
|
||||||
private void handleResult(Result res) {
|
|
||||||
switch (res) {
|
|
||||||
case ALREADY:
|
|
||||||
showMsg("Lettre déjà utilisée.");
|
|
||||||
break;
|
|
||||||
case HIT:
|
|
||||||
case MISS:
|
|
||||||
break; // rien, juste refresh
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Vérifie si la partie est finie */
|
|
||||||
private void checkEnd() {
|
private void checkEnd() {
|
||||||
if (game.isWin() || game.isLose()) {
|
if (!(game.isWin() || game.isLose())) return;
|
||||||
|
|
||||||
|
game.end(game.isWin());
|
||||||
|
int displayScore = (level == 3) ? sessionScore + game.getScore() : game.getScore();
|
||||||
|
long displaySecs = (level == 3) ? getSessionSeconds() : game.getElapsedSeconds();
|
||||||
|
|
||||||
|
showMsg((game.isWin() ? "Bravo !" : "Perdu !")
|
||||||
|
+ " Le mot était : " + currentWord
|
||||||
|
+ "\nScore : " + displayScore
|
||||||
|
+ "\nTemps : " + displaySecs + "s");
|
||||||
|
|
||||||
|
if (level == 3 && index < words.size()) {
|
||||||
|
sessionScore += game.getScore();
|
||||||
|
startRound();
|
||||||
|
} else {
|
||||||
timer.stop();
|
timer.stop();
|
||||||
game.end(game.isWin());
|
|
||||||
String msg = (game.isWin() ? "Bravo !" : "Perdu !")
|
|
||||||
+ " Le mot était : " + currentWord
|
|
||||||
+ "\nScore final : " + game.getScore()
|
|
||||||
+ "\nTemps : " + game.getElapsedSeconds() + "s";
|
|
||||||
showMsg(msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Met à jour tout l'affichage */
|
/** Refresh complet. */
|
||||||
private void refreshUI() {
|
private void refreshUI() {
|
||||||
imgLabel.setIcon(Gallows.icon(game.getErrors()));
|
imgLabel.setIcon(Gallows.icon(game.getErrors()));
|
||||||
wordLabel.setText("Mot : " + game.maskedWord());
|
wordLabel.setText("Mot : " + game.maskedWord());
|
||||||
@@ -141,13 +203,23 @@ public class GameUI {
|
|||||||
frame.repaint();
|
frame.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Met à jour uniquement score + chrono */
|
/** Refresh stats (score/chrono). */
|
||||||
private void refreshStatsOnly() {
|
private void refreshStatsOnly() {
|
||||||
scoreLabel.setText("Score : " + game.getScore());
|
int s = (level == 3) ? sessionScore + game.getScore() : game.getScore();
|
||||||
timeLabel.setText("Temps : " + game.getElapsedSeconds() + "s");
|
long t = (level == 3) ? getSessionSeconds() : game.getElapsedSeconds();
|
||||||
|
scoreLabel.setText("Score : " + s);
|
||||||
|
timeLabel.setText("Temps : " + t + "s");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Affiche une boîte de message */
|
/** Secondes écoulées depuis le début de la session (niveau 3). */
|
||||||
|
private long getSessionSeconds() {
|
||||||
|
long now = System.nanoTime();
|
||||||
|
long delta = now - sessionStartNano;
|
||||||
|
if (delta < 0) delta = 0;
|
||||||
|
return delta / 1_000_000_000L;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Popup info. */
|
||||||
private void showMsg(String msg) {
|
private void showMsg(String msg) {
|
||||||
JOptionPane.showMessageDialog(frame, msg);
|
JOptionPane.showMessageDialog(frame, msg);
|
||||||
}
|
}
|
||||||
|
|||||||
50
Jeu_pendu/Front/MenuUI.java
Normal file
50
Jeu_pendu/Front/MenuUI.java
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package front;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Menu de démarrage du jeu du pendu.
|
||||||
|
* Permet de choisir la difficulté (facile, moyen ou difficile).
|
||||||
|
*/
|
||||||
|
public class MenuUI {
|
||||||
|
private JFrame frame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface graphique de la page d'accueil du jeu du pendu.
|
||||||
|
*/
|
||||||
|
public void show() {
|
||||||
|
frame = new JFrame("Jeu du Pendu - Sélection de la difficulté");
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
frame.setSize(400, 300);
|
||||||
|
frame.setLocationRelativeTo(null);
|
||||||
|
frame.setLayout(new BorderLayout(12, 12));
|
||||||
|
|
||||||
|
JLabel title = new JLabel("Choisis une difficulté", SwingConstants.CENTER);
|
||||||
|
title.setFont(new Font("Arial", Font.BOLD, 20));
|
||||||
|
frame.add(title, BorderLayout.NORTH);
|
||||||
|
|
||||||
|
JPanel buttons = new JPanel(new GridLayout(3, 1, 10, 10));
|
||||||
|
JButton easyBtn = new JButton("Niveau Facile");
|
||||||
|
JButton mediumBtn = new JButton("Niveau Moyen");
|
||||||
|
JButton hardBtn = new JButton("Niveau Difficile");
|
||||||
|
|
||||||
|
buttons.add(easyBtn);
|
||||||
|
buttons.add(mediumBtn);
|
||||||
|
buttons.add(hardBtn);
|
||||||
|
frame.add(buttons, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
easyBtn.addActionListener(e -> startGame(1));
|
||||||
|
mediumBtn.addActionListener(e -> startGame(2));
|
||||||
|
hardBtn.addActionListener(e -> startGame(3));
|
||||||
|
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lance le jeu avec le niveau choisi */
|
||||||
|
private void startGame(int level) {
|
||||||
|
frame.dispose(); // ferme le menu
|
||||||
|
GameUI ui = new GameUI(level);
|
||||||
|
ui.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,16 @@
|
|||||||
package main;
|
package main;
|
||||||
|
|
||||||
import front.GameUI;
|
import front.MenuUI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Point d'entrée du programme.
|
* Point d'entrée du programme.
|
||||||
* Lance l'interface graphique du jeu du pendu.
|
* Affiche le menu de sélection avant de lancer le jeu.
|
||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// Démarre l'UI Swing sur le thread de l'EDT
|
|
||||||
javax.swing.SwingUtilities.invokeLater(() -> {
|
javax.swing.SwingUtilities.invokeLater(() -> {
|
||||||
GameUI ui = new GameUI();
|
MenuUI menu = new MenuUI();
|
||||||
ui.show();
|
menu.show();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BIN
Jeu_pendu/out/back/Check.class
Normal file
BIN
Jeu_pendu/out/back/Check.class
Normal file
Binary file not shown.
BIN
Jeu_pendu/out/back/Game.class
Normal file
BIN
Jeu_pendu/out/back/Game.class
Normal file
Binary file not shown.
BIN
Jeu_pendu/out/back/Result.class
Normal file
BIN
Jeu_pendu/out/back/Result.class
Normal file
Binary file not shown.
BIN
Jeu_pendu/out/back/Words.class
Normal file
BIN
Jeu_pendu/out/back/Words.class
Normal file
Binary file not shown.
BIN
Jeu_pendu/out/front/Gallows$BufferedImage.class
Normal file
BIN
Jeu_pendu/out/front/Gallows$BufferedImage.class
Normal file
Binary file not shown.
BIN
Jeu_pendu/out/front/Gallows.class
Normal file
BIN
Jeu_pendu/out/front/Gallows.class
Normal file
Binary file not shown.
BIN
Jeu_pendu/out/front/GameUI$1.class
Normal file
BIN
Jeu_pendu/out/front/GameUI$1.class
Normal file
Binary file not shown.
BIN
Jeu_pendu/out/front/GameUI.class
Normal file
BIN
Jeu_pendu/out/front/GameUI.class
Normal file
Binary file not shown.
BIN
Jeu_pendu/out/front/MenuUI.class
Normal file
BIN
Jeu_pendu/out/front/MenuUI.class
Normal file
Binary file not shown.
BIN
Jeu_pendu/out/main/Main.class
Normal file
BIN
Jeu_pendu/out/main/Main.class
Normal file
Binary file not shown.
Reference in New Issue
Block a user