forked from menault/TD3_DEV51_Qualite_Algo
ex4
This commit is contained in:
BIN
PenduJudeChrist/Display.class
Normal file
BIN
PenduJudeChrist/Display.class
Normal file
Binary file not shown.
@@ -1,43 +1,22 @@
|
|||||||
import java.util.Scanner;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class Display {
|
public class Display {
|
||||||
|
|
||||||
|
|
||||||
public static void showWord(String word, Set<Character> guessedLetters) {
|
public static void showWord(String word, Set<Character> guessedLetters) {
|
||||||
System.out.print("Mot :");
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < word.length(); i++) {
|
for (char c : word.toCharArray()) {
|
||||||
char letter = word.charAt(i);
|
if (c == ' ') {
|
||||||
if (guessedLetters.contains(letter)) {
|
sb.append(" ");
|
||||||
System.out.print(letter + " ");
|
} else if (guessedLetters.contains(c)) {
|
||||||
}
|
sb.append(c).append(" ");
|
||||||
else {
|
} else {
|
||||||
System.out.print("_ ");
|
sb.append("_ ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println(sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showLives(int lives, int maxLives) {
|
public static void showLives(int lives, int maxLives) {
|
||||||
System.out.print("Vies : ");
|
System.out.println("Lives: " + lives + " / " + maxLives);
|
||||||
for (int i = 0; i < lives; i++) {
|
|
||||||
System.out.print("♥︎ ");
|
|
||||||
}
|
|
||||||
System.out.println("(" + lives + "/" + maxLives + ")\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showEndGame(String word, int lives, int maxLives){
|
|
||||||
|
|
||||||
if (lives <= 0) {
|
|
||||||
System.out.println(" PERDU ! ");
|
|
||||||
System.out.println(" Vous n'avez plus de vies !");
|
|
||||||
System.out.println(" Le mot etait: " + word);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
System.out.println(" VICTOIRE ! ");
|
|
||||||
System.out.println(" Le mot était: " + word);
|
|
||||||
System.out.println(" Vies restantes: " + lives);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
BIN
PenduJudeChrist/GameLogic.class
Normal file
BIN
PenduJudeChrist/GameLogic.class
Normal file
Binary file not shown.
@@ -1,21 +1,22 @@
|
|||||||
import java.util.Scanner;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classe contenant la logique de vérification du jeu.
|
||||||
|
*/
|
||||||
public class GameLogic {
|
public class GameLogic {
|
||||||
|
/**
|
||||||
public static boolean isWordGuessed(String word, Set<Character> guessedLetters){
|
* Vérifie si toutes les lettres (hors espaces) du mot ont été devinées.
|
||||||
|
*/
|
||||||
for (int i = 0; i < word.length(); i++ ) {
|
public static boolean isWordGuessed(String word, Set<Character> guessedLetters) {
|
||||||
if(!guessedLetters.contains(word.charAt(i))) {
|
for (int i = 0; i < word.length(); i++) {
|
||||||
|
char c = word.charAt(i);
|
||||||
|
if (c == ' ') {
|
||||||
|
continue; // espace dans le mot
|
||||||
|
}
|
||||||
|
if (!guessedLetters.contains(c)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import java.util.Scanner;
|
/*import java.util.Scanner;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -36,4 +36,4 @@ public class HangedGame {
|
|||||||
Display.showEndGame(word, lives, MAX_LIVES);
|
Display.showEndGame(word, lives, MAX_LIVES);
|
||||||
scanner.close();
|
scanner.close();
|
||||||
}
|
}
|
||||||
}
|
}*/
|
BIN
PenduJudeChrist/HangedGameGUI$1.class
Normal file
BIN
PenduJudeChrist/HangedGameGUI$1.class
Normal file
Binary file not shown.
BIN
PenduJudeChrist/HangedGameGUI.class
Normal file
BIN
PenduJudeChrist/HangedGameGUI.class
Normal file
Binary file not shown.
@@ -1,20 +1,24 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.*;
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class HangedGameGUI {
|
public class HangedGameGUI {
|
||||||
private static final int MAX_LIVES = 12;
|
private static final int MAX_LIVES = 12;
|
||||||
|
|
||||||
|
// Game variables
|
||||||
private String word;
|
private String word;
|
||||||
private Set<Character> guessedLetters;
|
private Set<Character> guessedLetters;
|
||||||
private int lives;
|
private int lives;
|
||||||
|
private String difficulty; // "easy", "medium", "hard"
|
||||||
|
|
||||||
|
// Timer and scoring
|
||||||
|
private TimerManager timerManager;
|
||||||
|
|
||||||
// Composants de l'interface
|
// GUI components
|
||||||
private JFrame frame;
|
private JFrame frameMenu;
|
||||||
|
private JFrame frameGame;
|
||||||
private JLabel wordLabel;
|
private JLabel wordLabel;
|
||||||
private JLabel livesLabel;
|
private JLabel livesLabel;
|
||||||
private JLabel messageLabel;
|
private JLabel messageLabel;
|
||||||
@@ -22,28 +26,87 @@ public class HangedGameGUI {
|
|||||||
private JButton guessButton;
|
private JButton guessButton;
|
||||||
private JPanel hangmanPanel;
|
private JPanel hangmanPanel;
|
||||||
|
|
||||||
|
private JButton easyButton;
|
||||||
|
private JButton mediumButton;
|
||||||
|
private JButton hardButton;
|
||||||
|
|
||||||
public HangedGameGUI() {
|
public HangedGameGUI() {
|
||||||
word = WordSelector.pickRandomWord();
|
WordSelector.loadWordsForDifficulty("easy", "motsFacile.txt");
|
||||||
|
WordSelector.loadWordsForDifficulty("medium", "motsMoyen.txt");
|
||||||
|
WordSelector.loadWordsForDifficulty("hard", "motsDifficiles.txt");
|
||||||
|
|
||||||
guessedLetters = new HashSet<>();
|
guessedLetters = new HashSet<>();
|
||||||
lives = MAX_LIVES;
|
lives = MAX_LIVES;
|
||||||
|
timerManager = new TimerManager();
|
||||||
|
|
||||||
initializeGUI();
|
initializeMenuGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeGUI() {
|
private void initializeMenuGUI() {
|
||||||
frame = new JFrame("Jeu du Pendu");
|
frameMenu = new JFrame("Jeu du Pendu — Choix de difficulté");
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frameMenu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setLayout(new BorderLayout());
|
frameMenu.setSize(400, 200);
|
||||||
frame.setSize(500, 400);
|
frameMenu.setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
JLabel prompt = new JLabel("Sélectionnez une difficulté :", JLabel.CENTER);
|
||||||
|
prompt.setFont(new Font("Arial", Font.BOLD, 16));
|
||||||
|
frameMenu.add(prompt, BorderLayout.NORTH);
|
||||||
|
|
||||||
|
JPanel buttonPanel = new JPanel(new GridLayout(3, 1, 5, 5));
|
||||||
|
easyButton = new JButton("Easy");
|
||||||
|
mediumButton = new JButton("Medium");
|
||||||
|
hardButton = new JButton("Hard");
|
||||||
|
buttonPanel.add(easyButton);
|
||||||
|
buttonPanel.add(mediumButton);
|
||||||
|
buttonPanel.add(hardButton);
|
||||||
|
frameMenu.add(buttonPanel, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
setupMenuEvents();
|
||||||
|
|
||||||
|
frameMenu.setLocationRelativeTo(null);
|
||||||
|
frameMenu.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupMenuEvents() {
|
||||||
|
easyButton.addActionListener(e -> {
|
||||||
|
difficulty = "easy";
|
||||||
|
startNewGame();
|
||||||
|
});
|
||||||
|
mediumButton.addActionListener(e -> {
|
||||||
|
difficulty = "medium";
|
||||||
|
startNewGame();
|
||||||
|
});
|
||||||
|
hardButton.addActionListener(e -> {
|
||||||
|
difficulty = "hard";
|
||||||
|
startNewGame();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startNewGame() {
|
||||||
|
frameMenu.setVisible(false);
|
||||||
|
|
||||||
|
guessedLetters.clear();
|
||||||
|
lives = MAX_LIVES;
|
||||||
|
|
||||||
|
word = WordSelector.pickWord(difficulty);
|
||||||
|
|
||||||
|
initializeGameGUI();
|
||||||
|
|
||||||
|
timerManager.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeGameGUI() {
|
||||||
|
frameGame = new JFrame("Jeu du Pendu — " + difficulty);
|
||||||
|
frameGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
frameGame.setSize(600, 400);
|
||||||
|
frameGame.setLayout(new BorderLayout());
|
||||||
|
|
||||||
// Panel du haut - Affichage du mot et des vies
|
|
||||||
JPanel topPanel = new JPanel(new GridLayout(3, 1));
|
JPanel topPanel = new JPanel(new GridLayout(3, 1));
|
||||||
|
|
||||||
wordLabel = new JLabel("", JLabel.CENTER);
|
wordLabel = new JLabel("", JLabel.CENTER);
|
||||||
wordLabel.setFont(new Font("Arial", Font.BOLD, 24));
|
wordLabel.setFont(new Font("Arial", Font.BOLD, 24));
|
||||||
updateWordDisplay();
|
updateWordDisplay();
|
||||||
|
|
||||||
livesLabel = new JLabel("Vies: " + lives + "/" + MAX_LIVES, JLabel.CENTER);
|
livesLabel = new JLabel("Lives: " + lives + " / " + MAX_LIVES, JLabel.CENTER);
|
||||||
livesLabel.setFont(new Font("Arial", Font.PLAIN, 16));
|
livesLabel.setFont(new Font("Arial", Font.PLAIN, 16));
|
||||||
|
|
||||||
messageLabel = new JLabel("Devinez le mot !", JLabel.CENTER);
|
messageLabel = new JLabel("Devinez le mot !", JLabel.CENTER);
|
||||||
@@ -53,7 +116,6 @@ public class HangedGameGUI {
|
|||||||
topPanel.add(livesLabel);
|
topPanel.add(livesLabel);
|
||||||
topPanel.add(messageLabel);
|
topPanel.add(messageLabel);
|
||||||
|
|
||||||
// Panel du pendu (visuel simple)
|
|
||||||
hangmanPanel = new JPanel() {
|
hangmanPanel = new JPanel() {
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
@@ -61,95 +123,32 @@ public class HangedGameGUI {
|
|||||||
drawHangman(g);
|
drawHangman(g);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
hangmanPanel.setPreferredSize(new Dimension(200, 200));
|
hangmanPanel.setPreferredSize(new Dimension(300, 300));
|
||||||
hangmanPanel.setBackground(Color.WHITE);
|
hangmanPanel.setBackground(Color.WHITE);
|
||||||
|
|
||||||
// Panel de saisie
|
JPanel inputPanel = new JPanel(new FlowLayout());
|
||||||
JPanel inputPanel = new JPanel();
|
JLabel inputLabel = new JLabel("Enter a letter:");
|
||||||
inputPanel.setLayout(new FlowLayout());
|
|
||||||
|
|
||||||
JLabel inputLabel = new JLabel("Entrez une lettre:");
|
|
||||||
letterField = new JTextField(2);
|
letterField = new JTextField(2);
|
||||||
letterField.setFont(new Font("Arial", Font.BOLD, 18));
|
letterField.setFont(new Font("Arial", Font.BOLD, 18));
|
||||||
|
guessButton = new JButton("Guess");
|
||||||
guessButton = new JButton("Deviner");
|
|
||||||
|
|
||||||
inputPanel.add(inputLabel);
|
inputPanel.add(inputLabel);
|
||||||
inputPanel.add(letterField);
|
inputPanel.add(letterField);
|
||||||
inputPanel.add(guessButton);
|
inputPanel.add(guessButton);
|
||||||
|
|
||||||
// Ajout des composants à la fenêtre
|
frameGame.add(topPanel, BorderLayout.NORTH);
|
||||||
frame.add(topPanel, BorderLayout.NORTH);
|
frameGame.add(hangmanPanel, BorderLayout.CENTER);
|
||||||
frame.add(hangmanPanel, BorderLayout.CENTER);
|
frameGame.add(inputPanel, BorderLayout.SOUTH);
|
||||||
frame.add(inputPanel, BorderLayout.SOUTH);
|
|
||||||
|
|
||||||
// Gestion des événements
|
setupGameEvents();
|
||||||
setupEventHandlers();
|
|
||||||
|
|
||||||
frame.setVisible(true);
|
frameGame.setLocationRelativeTo(null);
|
||||||
|
frameGame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawHangman(Graphics g) {
|
private void setupGameEvents() {
|
||||||
int errors = MAX_LIVES - lives;
|
guessButton.addActionListener(e -> processGuess());
|
||||||
g.setColor(Color.BLACK);
|
letterField.addActionListener(e -> processGuess());
|
||||||
|
|
||||||
// Base
|
|
||||||
if (errors >= 1) g.drawLine(50, 150, 100, 150);
|
|
||||||
// Poteau
|
|
||||||
if (errors >= 2) g.drawLine(75, 150, 75, 50);
|
|
||||||
// Traverse
|
|
||||||
if (errors >= 3) g.drawLine(75, 50, 125, 50);
|
|
||||||
// Corde
|
|
||||||
if (errors >= 4) g.drawLine(125, 50, 125, 70);
|
|
||||||
// Tête
|
|
||||||
if (errors >= 5) g.drawOval(120, 70, 10, 10);
|
|
||||||
// Corps
|
|
||||||
if (errors >= 6) g.drawLine(125, 80, 125, 110);
|
|
||||||
// Bras gauche
|
|
||||||
if (errors >= 7) g.drawLine(125, 85, 115, 95);
|
|
||||||
// Bras droit
|
|
||||||
if (errors >= 8) g.drawLine(125, 85, 135, 95);
|
|
||||||
// Jambe gauche
|
|
||||||
if (errors >= 9) g.drawLine(125, 110, 115, 125);
|
|
||||||
// Jambe droite
|
|
||||||
if (errors >= 10) g.drawLine(125, 110, 135, 125);
|
|
||||||
// Visage triste
|
|
||||||
if (errors >= 11) {
|
|
||||||
g.drawArc(122, 73, 3, 3, 0, 180); // œil gauche
|
|
||||||
g.drawArc(127, 73, 3, 3, 0, 180); // œil droit
|
|
||||||
g.drawArc(122, 78, 6, 3, 0, -180); // bouche
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateWordDisplay() {
|
|
||||||
StringBuilder display = new StringBuilder();
|
|
||||||
for (int i = 0; i < word.length(); i++) {
|
|
||||||
char letter = word.charAt(i);
|
|
||||||
if (guessedLetters.contains(letter)) {
|
|
||||||
display.append(letter).append(" ");
|
|
||||||
} else {
|
|
||||||
display.append("_ ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wordLabel.setText(display.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupEventHandlers() {
|
|
||||||
// Bouton deviner
|
|
||||||
guessButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
processGuess();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Entrée dans le champ texte
|
|
||||||
letterField.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
processGuess();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processGuess() {
|
private void processGuess() {
|
||||||
@@ -157,14 +156,13 @@ public class HangedGameGUI {
|
|||||||
letterField.setText("");
|
letterField.setText("");
|
||||||
|
|
||||||
if (input.length() != 1 || !Character.isLetter(input.charAt(0))) {
|
if (input.length() != 1 || !Character.isLetter(input.charAt(0))) {
|
||||||
messageLabel.setText("Veuillez entrer une seule lettre !");
|
messageLabel.setText("Please enter a single letter.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char letter = input.charAt(0);
|
char letter = input.charAt(0);
|
||||||
|
|
||||||
if (guessedLetters.contains(letter)) {
|
if (guessedLetters.contains(letter)) {
|
||||||
messageLabel.setText("Vous avez déjà essayé cette lettre !");
|
messageLabel.setText("You already guessed that letter.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,23 +170,57 @@ public class HangedGameGUI {
|
|||||||
|
|
||||||
if (!word.contains(String.valueOf(letter))) {
|
if (!word.contains(String.valueOf(letter))) {
|
||||||
lives--;
|
lives--;
|
||||||
messageLabel.setText("Mauvaise lettre ! Il vous reste " + lives + " vies.");
|
messageLabel.setText("Wrong letter! Lives left: " + lives);
|
||||||
} else {
|
} else {
|
||||||
messageLabel.setText("Bonne lettre ! Continuez !");
|
messageLabel.setText("Good guess!");
|
||||||
}
|
}
|
||||||
|
|
||||||
updateWordDisplay();
|
updateWordDisplay();
|
||||||
livesLabel.setText("Vies: " + lives + "/" + MAX_LIVES);
|
livesLabel.setText("Lives: " + lives + " / " + MAX_LIVES);
|
||||||
hangmanPanel.repaint();
|
hangmanPanel.repaint();
|
||||||
|
|
||||||
checkGameStatus();
|
checkGameEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkGameStatus() {
|
private void updateWordDisplay() {
|
||||||
if (lives <= 0) {
|
StringBuilder sb = new StringBuilder();
|
||||||
endGame(false);
|
for (int i = 0; i < word.length(); i++) {
|
||||||
} else if (GameLogic.isWordGuessed(word, guessedLetters)) {
|
char c = word.charAt(i);
|
||||||
endGame(true);
|
if (c == ' ') {
|
||||||
|
sb.append(" ");
|
||||||
|
} else if (guessedLetters.contains(c)) {
|
||||||
|
sb.append(c).append(" ");
|
||||||
|
} else {
|
||||||
|
sb.append("_ ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wordLabel.setText(sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawHangman(Graphics g) {
|
||||||
|
int errors = MAX_LIVES - lives;
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
if (errors >= 1) g.drawLine(50, 250, 150, 250);
|
||||||
|
if (errors >= 2) g.drawLine(100, 250, 100, 50);
|
||||||
|
if (errors >= 3) g.drawLine(100, 50, 200, 50);
|
||||||
|
if (errors >= 4) g.drawLine(200, 50, 200, 80);
|
||||||
|
if (errors >= 5) g.drawOval(185, 80, 30, 30);
|
||||||
|
if (errors >= 6) g.drawLine(200, 110, 200, 160);
|
||||||
|
if (errors >= 7) g.drawLine(200, 120, 180, 140);
|
||||||
|
if (errors >= 8) g.drawLine(200, 120, 220, 140);
|
||||||
|
if (errors >= 9) g.drawLine(200, 160, 180, 190);
|
||||||
|
if (errors >= 10) g.drawLine(200, 160, 220, 190);
|
||||||
|
if (errors >= 11) {
|
||||||
|
g.drawArc(190, 90, 5, 5, 0, 180);
|
||||||
|
g.drawArc(205, 90, 5, 5, 0, 180);
|
||||||
|
g.drawArc(190, 105, 15, 8, 0, -180);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkGameEnd() {
|
||||||
|
boolean won = GameLogic.isWordGuessed(word, guessedLetters);
|
||||||
|
if (lives <= 0 || won) {
|
||||||
|
endGame(won);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,54 +228,29 @@ public class HangedGameGUI {
|
|||||||
guessButton.setEnabled(false);
|
guessButton.setEnabled(false);
|
||||||
letterField.setEnabled(false);
|
letterField.setEnabled(false);
|
||||||
|
|
||||||
|
long elapsedMillis = timerManager.getElapsedTimeMillis();
|
||||||
|
int errors = MAX_LIVES - lives;
|
||||||
|
int score = ScoreManager.calculateScore(errors, elapsedMillis, difficulty);
|
||||||
|
|
||||||
|
String message;
|
||||||
if (won) {
|
if (won) {
|
||||||
messageLabel.setText("VICTOIRE ! Le mot était: " + word);
|
message = "You win! Word: " + word + "\nLives left: " + lives + "\nScore: " + score;
|
||||||
JOptionPane.showMessageDialog(frame,
|
JOptionPane.showMessageDialog(frameGame, message, "Victory", JOptionPane.INFORMATION_MESSAGE);
|
||||||
"Félicitations ! Vous avez gagné !\n" +
|
|
||||||
"Le mot était: " + word + "\n" +
|
|
||||||
"Vies restantes: " + lives,
|
|
||||||
"Victoire !",
|
|
||||||
JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
} else {
|
} else {
|
||||||
messageLabel.setText("PERDU ! Le mot était: " + word);
|
message = "You lose! Word: " + word + "\nScore: " + score;
|
||||||
JOptionPane.showMessageDialog(frame,
|
JOptionPane.showMessageDialog(frameGame, message, "Defeat", JOptionPane.ERROR_MESSAGE);
|
||||||
"Désolé ! Vous avez perdu !\n" +
|
|
||||||
"Le mot était: " + word,
|
|
||||||
"Défaite",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bouton pour rejouer
|
int choice = JOptionPane.showConfirmDialog(frameGame, "Play again?", "Replay", JOptionPane.YES_NO_OPTION);
|
||||||
int choice = JOptionPane.showConfirmDialog(frame,
|
|
||||||
"Voulez-vous rejouer ?",
|
|
||||||
"Nouvelle partie",
|
|
||||||
JOptionPane.YES_NO_OPTION);
|
|
||||||
|
|
||||||
if (choice == JOptionPane.YES_OPTION) {
|
if (choice == JOptionPane.YES_OPTION) {
|
||||||
restartGame();
|
frameGame.dispose();
|
||||||
|
frameMenu.setVisible(true);
|
||||||
|
} else {
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restartGame() {
|
|
||||||
word = WordSelector.pickRandomWord();
|
|
||||||
guessedLetters.clear();
|
|
||||||
lives = MAX_LIVES;
|
|
||||||
|
|
||||||
guessButton.setEnabled(true);
|
|
||||||
letterField.setEnabled(true);
|
|
||||||
|
|
||||||
updateWordDisplay();
|
|
||||||
livesLabel.setText("Vies: " + lives + "/" + MAX_LIVES);
|
|
||||||
messageLabel.setText("Nouvelle partie - Devinez le mot !");
|
|
||||||
hangmanPanel.repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(HangedGameGUI::new);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
new HangedGameGUI();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
BIN
PenduJudeChrist/InputHandler.class
Normal file
BIN
PenduJudeChrist/InputHandler.class
Normal file
Binary file not shown.
BIN
PenduJudeChrist/ScoreManager.class
Normal file
BIN
PenduJudeChrist/ScoreManager.class
Normal file
Binary file not shown.
22
PenduJudeChrist/ScoreManager.java
Normal file
22
PenduJudeChrist/ScoreManager.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
public class ScoreManager {
|
||||||
|
/**
|
||||||
|
* Calcule le score selon le nombre d’erreurs (errors), le temps écoulé en ms, et la difficulté.
|
||||||
|
* Score de base dépend de la difficulté, puis on pénalise par erreurs et temps.
|
||||||
|
*/
|
||||||
|
public static int calculateScore(int errors, long elapsedMillis, String difficulty) {
|
||||||
|
int base;
|
||||||
|
switch (difficulty) {
|
||||||
|
case "Easy" : base = 1000;
|
||||||
|
case "Medium" :base = 1500;
|
||||||
|
case "Hard" : base = 2000;
|
||||||
|
default : base = 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
int errorPenalty = errors * 100;
|
||||||
|
int timePenalty = (int)(elapsedMillis / 1000); // en secondes
|
||||||
|
|
||||||
|
int score = base - errorPenalty - timePenalty;
|
||||||
|
if (score < 0) score = 0;
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
}
|
BIN
PenduJudeChrist/TimerManager.class
Normal file
BIN
PenduJudeChrist/TimerManager.class
Normal file
Binary file not shown.
20
PenduJudeChrist/TimerManager.java
Normal file
20
PenduJudeChrist/TimerManager.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* Classe simple pour gérer le chronomètre.
|
||||||
|
*/
|
||||||
|
public class TimerManager {
|
||||||
|
private long startTimeMillis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Démarre le chronomètre.
|
||||||
|
*/
|
||||||
|
public void start() {
|
||||||
|
startTimeMillis = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne le temps écoulé en millisecondes depuis le démarrage.
|
||||||
|
*/
|
||||||
|
public long getElapsedTimeMillis() {
|
||||||
|
return System.currentTimeMillis() - startTimeMillis;
|
||||||
|
}
|
||||||
|
}
|
BIN
PenduJudeChrist/WordSelector.class
Normal file
BIN
PenduJudeChrist/WordSelector.class
Normal file
Binary file not shown.
@@ -1,33 +1,40 @@
|
|||||||
import java.util.Scanner;
|
import java.io.*;
|
||||||
import java.util.Random;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class WordSelector {
|
public class WordSelector {
|
||||||
|
|
||||||
private static final String[] WORDS = {
|
private static final Map<String, List<String>> wordsByDifficulty = new HashMap<>();
|
||||||
"java", "python", "programmation", "ordinateur", "clavier",
|
|
||||||
"souris", "ecran", "internet", "logiciel", "algorithme",
|
|
||||||
"maison", "jardin", "livre", "table", "chaise", "porte",
|
|
||||||
"fenetre", "lampe", "bureau", "stylo", "crayon", "papier",
|
|
||||||
"fleur", "arbre", "oiseau", "chat", "chien", "poisson",
|
|
||||||
"soleil", "lune", "etoile", "ciel", "nuage", "pluie",
|
|
||||||
"vent", "neige", "terre", "eau", "feu", "air", "pierre",
|
|
||||||
"sable", "route", "ville", "rue", "voiture", "velo",
|
|
||||||
"train", "avion", "bateau", "musique", "chanson", "danse",
|
|
||||||
"peinture", "couleur", "forme", "image", "photo", "film",
|
|
||||||
"histoire", "conte", "reve", "idee", "pensee", "mot",
|
|
||||||
"phrase", "texte", "histoire", "nombre", "chiffre",
|
|
||||||
"calcul", "probleme", "solution", "question", "reponse",
|
|
||||||
"temps", "heure", "minute", "seconde", "jour", "nuit",
|
|
||||||
"matin", "soir", "semaine", "mois", "annee", "saison",
|
|
||||||
"printemps", "ete", "automne", "hiver", "famille", "ami",
|
|
||||||
"frere", "soeur", "parent", "enfant", "ecole", "classe",
|
|
||||||
"cours", "lecon", "devoir", "travail", "repos", "jeu"
|
|
||||||
};
|
|
||||||
|
|
||||||
public static String pickRandomWord(){
|
/**
|
||||||
Random random = new Random();
|
* Charge la liste de mots pour une difficulté donnée depuis un fichier.
|
||||||
return WORDS[random.nextInt(WORDS.length)];
|
*/
|
||||||
|
public static void loadWordsForDifficulty(String difficulty, String filename) {
|
||||||
|
List<String> words = new ArrayList<>();
|
||||||
|
try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
String word = line.trim().toLowerCase();
|
||||||
|
if (!word.isEmpty()) {
|
||||||
|
words.add(word);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Error loading words from " + filename);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
wordsByDifficulty.put(difficulty.toLowerCase(), words);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne un mot aléatoire selon la difficulté ("easy", "medium", "hard").
|
||||||
|
* Retourne "default" si aucun mot trouvé.
|
||||||
|
*/
|
||||||
|
public static String pickWord(String difficulty) {
|
||||||
|
List<String> words = wordsByDifficulty.get(difficulty.toLowerCase());
|
||||||
|
if (words == null || words.isEmpty()) {
|
||||||
|
return "default";
|
||||||
|
}
|
||||||
|
Random rand = new Random();
|
||||||
|
return words.get(rand.nextInt(words.size()));
|
||||||
}
|
}
|
||||||
}
|
}
|
87
PenduJudeChrist/motsDifficiles.txt
Normal file
87
PenduJudeChrist/motsDifficiles.txt
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
petit chat
|
||||||
|
grand arbre
|
||||||
|
voiture rouge
|
||||||
|
soleil brillant
|
||||||
|
fleur jaune
|
||||||
|
eau claire
|
||||||
|
montagne haute
|
||||||
|
ciel bleu
|
||||||
|
oiseau chanteur
|
||||||
|
jardin secret
|
||||||
|
livre ancien
|
||||||
|
musique douce
|
||||||
|
temps froid
|
||||||
|
rue calme
|
||||||
|
pont vieux
|
||||||
|
chien fidèle
|
||||||
|
nuit noire
|
||||||
|
lune pleine
|
||||||
|
feu rapide
|
||||||
|
vent fort
|
||||||
|
mer agitée
|
||||||
|
plage dorée
|
||||||
|
neige blanche
|
||||||
|
herbe verte
|
||||||
|
clé perdue
|
||||||
|
main droite
|
||||||
|
pied gauche
|
||||||
|
nez fin
|
||||||
|
main froide
|
||||||
|
jour gris
|
||||||
|
fête joyeuse
|
||||||
|
rire franc
|
||||||
|
sac lourd
|
||||||
|
boue épaisse
|
||||||
|
seau plein
|
||||||
|
bête sauvage
|
||||||
|
chaton joueur
|
||||||
|
fromage frais
|
||||||
|
café noir
|
||||||
|
bois dur
|
||||||
|
miel doux
|
||||||
|
âne têtu
|
||||||
|
nager vite
|
||||||
|
jouet cassé
|
||||||
|
roi puissant
|
||||||
|
reine belle
|
||||||
|
vase fragile
|
||||||
|
fleur fanée
|
||||||
|
voix douce
|
||||||
|
temps perdu
|
||||||
|
sable chaud
|
||||||
|
neuf brillant
|
||||||
|
souris rapide
|
||||||
|
pont solide
|
||||||
|
coeur tendre
|
||||||
|
lait frais
|
||||||
|
pied nu
|
||||||
|
faux plat
|
||||||
|
rare gemme
|
||||||
|
tôt matin
|
||||||
|
lent pas
|
||||||
|
fin courte
|
||||||
|
rue étroite
|
||||||
|
rose rouge
|
||||||
|
arête dure
|
||||||
|
doux parfum
|
||||||
|
sec désert
|
||||||
|
haut sommet
|
||||||
|
bas fond
|
||||||
|
lent mouvement
|
||||||
|
fer solide
|
||||||
|
vers libre
|
||||||
|
vent froid
|
||||||
|
sel fin
|
||||||
|
sou dur
|
||||||
|
rat gris
|
||||||
|
vin rouge
|
||||||
|
oui clair
|
||||||
|
non net
|
||||||
|
jus sucré
|
||||||
|
riz blanc
|
||||||
|
sel épais
|
||||||
|
jeu amusant
|
||||||
|
air frais
|
||||||
|
eau pure
|
||||||
|
sol dur
|
||||||
|
feu vif
|
694
PenduJudeChrist/motsFacile.txt
Normal file
694
PenduJudeChrist/motsFacile.txt
Normal file
File diff suppressed because it is too large
Load Diff
110
PenduJudeChrist/motsMoyen.txt
Normal file
110
PenduJudeChrist/motsMoyen.txt
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
ordinateur
|
||||||
|
téléphone
|
||||||
|
bibliothèque
|
||||||
|
calendrier
|
||||||
|
aventure
|
||||||
|
document
|
||||||
|
ordinateur
|
||||||
|
musicien
|
||||||
|
ordinateur
|
||||||
|
philosophie
|
||||||
|
restaurant
|
||||||
|
chocolat
|
||||||
|
photographie
|
||||||
|
laboratoire
|
||||||
|
impression
|
||||||
|
pédagogique
|
||||||
|
température
|
||||||
|
municipale
|
||||||
|
conversation
|
||||||
|
influence
|
||||||
|
architecture
|
||||||
|
horizon
|
||||||
|
incroyable
|
||||||
|
profession
|
||||||
|
développement
|
||||||
|
expérience
|
||||||
|
recherche
|
||||||
|
université
|
||||||
|
télévision
|
||||||
|
ordinateur
|
||||||
|
démocratie
|
||||||
|
connaissance
|
||||||
|
créativité
|
||||||
|
éducation
|
||||||
|
électronique
|
||||||
|
exercice
|
||||||
|
information
|
||||||
|
intelligence
|
||||||
|
organisation
|
||||||
|
participation
|
||||||
|
présentation
|
||||||
|
recommandation
|
||||||
|
réussite
|
||||||
|
situation
|
||||||
|
stratégie
|
||||||
|
technologie
|
||||||
|
travail
|
||||||
|
valeur
|
||||||
|
véhicule
|
||||||
|
vocabulaire
|
||||||
|
vulnérable
|
||||||
|
architecture
|
||||||
|
automobile
|
||||||
|
bibliothèque
|
||||||
|
biographie
|
||||||
|
catégorie
|
||||||
|
champion
|
||||||
|
climatique
|
||||||
|
collection
|
||||||
|
communication
|
||||||
|
compétence
|
||||||
|
conférence
|
||||||
|
connaissance
|
||||||
|
construction
|
||||||
|
consultation
|
||||||
|
contribution
|
||||||
|
coordination
|
||||||
|
déclaration
|
||||||
|
démonstration
|
||||||
|
développement
|
||||||
|
différence
|
||||||
|
difficulté
|
||||||
|
diplomatie
|
||||||
|
économie
|
||||||
|
éducation
|
||||||
|
électrique
|
||||||
|
électronique
|
||||||
|
élément
|
||||||
|
émotion
|
||||||
|
entreprise
|
||||||
|
équipe
|
||||||
|
espace
|
||||||
|
essentiel
|
||||||
|
exemple
|
||||||
|
expérience
|
||||||
|
exposition
|
||||||
|
fabrication
|
||||||
|
famille
|
||||||
|
fonction
|
||||||
|
formation
|
||||||
|
génération
|
||||||
|
gestion
|
||||||
|
habitation
|
||||||
|
histoire
|
||||||
|
identité
|
||||||
|
immédiat
|
||||||
|
importance
|
||||||
|
individu
|
||||||
|
industrie
|
||||||
|
information
|
||||||
|
initiative
|
||||||
|
instruction
|
||||||
|
intégration
|
||||||
|
intérêt
|
||||||
|
introduction
|
||||||
|
investissement
|
||||||
|
invitation
|
||||||
|
journaliste
|
||||||
|
justification
|
||||||
|
langue
|
Reference in New Issue
Block a user