Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
2f3ec8b804 | |||
3547ccfc10 | |||
|
9058650339 | ||
|
7270ba1a20 | ||
|
9869c9b289 | ||
c14e481572 | |||
86537ff528 |
BIN
PenduJudeChrist/Display.class
Normal file
BIN
PenduJudeChrist/Display.class
Normal file
Binary file not shown.
22
PenduJudeChrist/Display.java
Normal file
22
PenduJudeChrist/Display.java
Normal file
@@ -0,0 +1,22 @@
|
||||
import java.util.Set;
|
||||
|
||||
public class Display {
|
||||
|
||||
public static void showWord(String word, Set<Character> guessedLetters) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (char c : word.toCharArray()) {
|
||||
if (c == ' ') {
|
||||
sb.append(" ");
|
||||
} else if (guessedLetters.contains(c)) {
|
||||
sb.append(c).append(" ");
|
||||
} else {
|
||||
sb.append("_ ");
|
||||
}
|
||||
}
|
||||
System.out.println(sb.toString());
|
||||
}
|
||||
|
||||
public static void showLives(int lives, int maxLives) {
|
||||
System.out.println("Lives: " + lives + " / " + maxLives);
|
||||
}
|
||||
}
|
BIN
PenduJudeChrist/GameLogic.class
Normal file
BIN
PenduJudeChrist/GameLogic.class
Normal file
Binary file not shown.
22
PenduJudeChrist/GameLogic.java
Normal file
22
PenduJudeChrist/GameLogic.java
Normal file
@@ -0,0 +1,22 @@
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Classe contenant la logique de vérification du jeu.
|
||||
*/
|
||||
public class GameLogic {
|
||||
/**
|
||||
* Vérifie si toutes les lettres (hors espaces) du mot ont été devinées.
|
||||
*/
|
||||
public static boolean isWordGuessed(String word, Set<Character> guessedLetters) {
|
||||
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 true;
|
||||
}
|
||||
}
|
39
PenduJudeChrist/HangedGame.java
Normal file
39
PenduJudeChrist/HangedGame.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*import java.util.Scanner;
|
||||
import java.util.Random;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class HangedGame {
|
||||
|
||||
private static final int MAX_LIVES = 12;
|
||||
|
||||
public static void main(String[] args){
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String word = WordSelector.pickRandomWord();
|
||||
Set<Character> guessedLetters = new HashSet<>();
|
||||
int lives = MAX_LIVES;
|
||||
|
||||
System.out.println("Bienvenu dans le jeu du pendu");
|
||||
|
||||
while ( lives > 0 && !GameLogic.isWordGuessed(word, guessedLetters)) {
|
||||
Display.showWord(word, guessedLetters);
|
||||
Display.showLives(lives, MAX_LIVES);
|
||||
|
||||
char letter = InputHandler.getLetter(scanner, guessedLetters);
|
||||
guessedLetters.add(letter);
|
||||
|
||||
if (!word.contains(String.valueOf(letter))) {
|
||||
lives = lives -1;
|
||||
System.out.println("Mauvaise lettre vous avez maintenant " + lives + " vies !");
|
||||
|
||||
}
|
||||
else {
|
||||
System.out.println("Bonne lettre ! ");
|
||||
}
|
||||
}
|
||||
|
||||
Display.showEndGame(word, lives, MAX_LIVES);
|
||||
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.
256
PenduJudeChrist/HangedGameGUI.java
Normal file
256
PenduJudeChrist/HangedGameGUI.java
Normal file
@@ -0,0 +1,256 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class HangedGameGUI {
|
||||
private static final int MAX_LIVES = 12;
|
||||
|
||||
// Game variables
|
||||
private String word;
|
||||
private Set<Character> guessedLetters;
|
||||
private int lives;
|
||||
private String difficulty; // "easy", "medium", "hard"
|
||||
|
||||
// Timer and scoring
|
||||
private TimerManager timerManager;
|
||||
|
||||
// GUI components
|
||||
private JFrame frameMenu;
|
||||
private JFrame frameGame;
|
||||
private JLabel wordLabel;
|
||||
private JLabel livesLabel;
|
||||
private JLabel messageLabel;
|
||||
private JTextField letterField;
|
||||
private JButton guessButton;
|
||||
private JPanel hangmanPanel;
|
||||
|
||||
private JButton easyButton;
|
||||
private JButton mediumButton;
|
||||
private JButton hardButton;
|
||||
|
||||
public HangedGameGUI() {
|
||||
WordSelector.loadWordsForDifficulty("easy", "motsFacile.txt");
|
||||
WordSelector.loadWordsForDifficulty("medium", "motsMoyen.txt");
|
||||
WordSelector.loadWordsForDifficulty("hard", "motsDifficiles.txt");
|
||||
|
||||
guessedLetters = new HashSet<>();
|
||||
lives = MAX_LIVES;
|
||||
timerManager = new TimerManager();
|
||||
|
||||
initializeMenuGUI();
|
||||
}
|
||||
|
||||
private void initializeMenuGUI() {
|
||||
frameMenu = new JFrame("Jeu du Pendu — Choix de difficulté");
|
||||
frameMenu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frameMenu.setSize(400, 200);
|
||||
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());
|
||||
|
||||
JPanel topPanel = new JPanel(new GridLayout(3, 1));
|
||||
wordLabel = new JLabel("", JLabel.CENTER);
|
||||
wordLabel.setFont(new Font("Arial", Font.BOLD, 24));
|
||||
updateWordDisplay();
|
||||
|
||||
livesLabel = new JLabel("Lives: " + lives + " / " + MAX_LIVES, JLabel.CENTER);
|
||||
livesLabel.setFont(new Font("Arial", Font.PLAIN, 16));
|
||||
|
||||
messageLabel = new JLabel("Devinez le mot !", JLabel.CENTER);
|
||||
messageLabel.setFont(new Font("Arial", Font.ITALIC, 14));
|
||||
|
||||
topPanel.add(wordLabel);
|
||||
topPanel.add(livesLabel);
|
||||
topPanel.add(messageLabel);
|
||||
|
||||
hangmanPanel = new JPanel() {
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
drawHangman(g);
|
||||
}
|
||||
};
|
||||
hangmanPanel.setPreferredSize(new Dimension(300, 300));
|
||||
hangmanPanel.setBackground(Color.WHITE);
|
||||
|
||||
JPanel inputPanel = new JPanel(new FlowLayout());
|
||||
JLabel inputLabel = new JLabel("Enter a letter:");
|
||||
letterField = new JTextField(2);
|
||||
letterField.setFont(new Font("Arial", Font.BOLD, 18));
|
||||
guessButton = new JButton("Guess");
|
||||
|
||||
inputPanel.add(inputLabel);
|
||||
inputPanel.add(letterField);
|
||||
inputPanel.add(guessButton);
|
||||
|
||||
frameGame.add(topPanel, BorderLayout.NORTH);
|
||||
frameGame.add(hangmanPanel, BorderLayout.CENTER);
|
||||
frameGame.add(inputPanel, BorderLayout.SOUTH);
|
||||
|
||||
setupGameEvents();
|
||||
|
||||
frameGame.setLocationRelativeTo(null);
|
||||
frameGame.setVisible(true);
|
||||
}
|
||||
|
||||
private void setupGameEvents() {
|
||||
guessButton.addActionListener(e -> processGuess());
|
||||
letterField.addActionListener(e -> processGuess());
|
||||
}
|
||||
|
||||
private void processGuess() {
|
||||
String input = letterField.getText().toLowerCase().trim();
|
||||
letterField.setText("");
|
||||
|
||||
if (input.length() != 1 || !Character.isLetter(input.charAt(0))) {
|
||||
messageLabel.setText("Please enter a single letter.");
|
||||
return;
|
||||
}
|
||||
|
||||
char letter = input.charAt(0);
|
||||
if (guessedLetters.contains(letter)) {
|
||||
messageLabel.setText("You already guessed that letter.");
|
||||
return;
|
||||
}
|
||||
|
||||
guessedLetters.add(letter);
|
||||
|
||||
if (!word.contains(String.valueOf(letter))) {
|
||||
lives--;
|
||||
messageLabel.setText("Wrong letter! Lives left: " + lives);
|
||||
} else {
|
||||
messageLabel.setText("Good guess!");
|
||||
}
|
||||
|
||||
updateWordDisplay();
|
||||
livesLabel.setText("Lives: " + lives + " / " + MAX_LIVES);
|
||||
hangmanPanel.repaint();
|
||||
|
||||
checkGameEnd();
|
||||
}
|
||||
|
||||
private void updateWordDisplay() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < word.length(); i++) {
|
||||
char c = word.charAt(i);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void endGame(boolean won) {
|
||||
guessButton.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) {
|
||||
message = "You win! Word: " + word + "\nLives left: " + lives + "\nScore: " + score;
|
||||
JOptionPane.showMessageDialog(frameGame, message, "Victory", JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
message = "You lose! Word: " + word + "\nScore: " + score;
|
||||
JOptionPane.showMessageDialog(frameGame, message, "Defeat", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
int choice = JOptionPane.showConfirmDialog(frameGame, "Play again?", "Replay", JOptionPane.YES_NO_OPTION);
|
||||
if (choice == JOptionPane.YES_OPTION) {
|
||||
frameGame.dispose();
|
||||
frameMenu.setVisible(true);
|
||||
} else {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(HangedGameGUI::new);
|
||||
}
|
||||
}
|
BIN
PenduJudeChrist/InputHandler.class
Normal file
BIN
PenduJudeChrist/InputHandler.class
Normal file
Binary file not shown.
32
PenduJudeChrist/InputHandler.java
Normal file
32
PenduJudeChrist/InputHandler.java
Normal file
@@ -0,0 +1,32 @@
|
||||
import java.util.Random;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Scanner;
|
||||
|
||||
|
||||
public class InputHandler {
|
||||
|
||||
public static char getLetter(Scanner scanner, Set<Character> guessedLetters) {
|
||||
char letter;
|
||||
while (true) {
|
||||
System.out.print("Entrez une lettre: ");
|
||||
String input = scanner.nextLine().toLowerCase().trim();
|
||||
|
||||
if (input.length() != 1 || !Character.isLetter(input.charAt(0))) {
|
||||
System.out.println("Veuillez entrer une seule lettre ! ");
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
letter = input.charAt(0);
|
||||
if (guessedLetters.contains(letter)) {
|
||||
System.out.println("Vous avez déjà essayé cette lettre ! ");
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
return letter;
|
||||
|
||||
}
|
||||
}
|
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/TD3 - DEV5.1.pdf
Normal file
BIN
PenduJudeChrist/TD3 - DEV5.1.pdf
Normal file
Binary file not shown.
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.
40
PenduJudeChrist/WordSelector.java
Normal file
40
PenduJudeChrist/WordSelector.java
Normal file
@@ -0,0 +1,40 @@
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class WordSelector {
|
||||
|
||||
private static final Map<String, List<String>> wordsByDifficulty = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Charge la liste de mots pour une difficulté donnée depuis un fichier.
|
||||
*/
|
||||
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
|
BIN
PenduWIlfried/ChooseWord.class
Normal file
BIN
PenduWIlfried/ChooseWord.class
Normal file
Binary file not shown.
55
PenduWIlfried/ChooseWord.java
Normal file
55
PenduWIlfried/ChooseWord.java
Normal file
@@ -0,0 +1,55 @@
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class ChooseWord {
|
||||
|
||||
/*Fonction pour choisir le mot selon la difficulté*/
|
||||
public static String chooseTheWord(String difficulty) {
|
||||
String filename = getFilenameByDifficulty(difficulty);
|
||||
List<String> words = new ArrayList<>();
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (!line.trim().isEmpty()) {
|
||||
String word = line.trim().toLowerCase();
|
||||
// Filtre selon la difficulté
|
||||
if (isValidForDifficulty(word, difficulty)) {
|
||||
words.add(word);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (words.isEmpty()) {
|
||||
return "default";
|
||||
}
|
||||
|
||||
Random rand = new Random();
|
||||
return words.get(rand.nextInt(words.size()));
|
||||
}
|
||||
|
||||
private static String getFilenameByDifficulty(String difficulty) {
|
||||
switch (difficulty.toLowerCase()) {
|
||||
case "facile": return "motsFacile.txt";
|
||||
case "moyen": return "motsMoyen.txt";
|
||||
case "difficile": return "motsDifficiles.txt";
|
||||
default: return "motsFacile.txt";
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isValidForDifficulty(String word, String difficulty) {
|
||||
switch (difficulty.toLowerCase()) {
|
||||
case "facile":
|
||||
return word.length() < 8 && !word.contains(" ");
|
||||
case "moyen":
|
||||
return word.length() >= 8 && !word.contains(" ");
|
||||
case "difficile":
|
||||
return word.contains(" "); // Phrases avec espaces
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
BIN
PenduWIlfried/GameState.class
Normal file
BIN
PenduWIlfried/GameState.class
Normal file
Binary file not shown.
143
PenduWIlfried/GameState.java
Normal file
143
PenduWIlfried/GameState.java
Normal file
@@ -0,0 +1,143 @@
|
||||
import java.util.*;
|
||||
|
||||
public class GameState {
|
||||
|
||||
private String word;
|
||||
private char[] hiddenWord;
|
||||
private int errors;
|
||||
private Set<Character> triedLetters;
|
||||
private static final int MAX_ERRORS = 9;
|
||||
private long startTime;
|
||||
private int score;
|
||||
private String difficulty;
|
||||
|
||||
public GameState(String wordToGuess, String difficulty) {
|
||||
this.word = wordToGuess.toLowerCase();
|
||||
this.difficulty = difficulty;
|
||||
this.hiddenWord = new char[word.length()];
|
||||
|
||||
// INITIALISATION CORRIGÉE : montrer les espaces directement
|
||||
for (int i = 0; i < word.length(); i++) {
|
||||
char c = word.charAt(i);
|
||||
if (c == ' ') {
|
||||
hiddenWord[i] = ' '; // Espace visible dès le début
|
||||
} else {
|
||||
hiddenWord[i] = '_'; // Lettres cachées
|
||||
}
|
||||
}
|
||||
|
||||
this.triedLetters = new HashSet<>();
|
||||
this.errors = 0;
|
||||
this.score = 0;
|
||||
this.startTime = System.currentTimeMillis();
|
||||
|
||||
// Ajouter l'espace comme lettre déjà "devinée"
|
||||
triedLetters.add(' ');
|
||||
}
|
||||
|
||||
/*Fonction pour essayer une lettre*/
|
||||
public void tryLetter(char letter) {
|
||||
letter = Character.toLowerCase(letter);
|
||||
|
||||
// Ne pas compter l'espace comme une tentative
|
||||
if (letter == ' ') {
|
||||
return;
|
||||
}
|
||||
|
||||
triedLetters.add(letter);
|
||||
boolean found = false;
|
||||
|
||||
for (int i = 0; i < word.length(); i++) {
|
||||
if (word.charAt(i) == letter) {
|
||||
hiddenWord[i] = letter;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
errors++;
|
||||
}
|
||||
|
||||
// Mettre à jour le score après chaque tentative
|
||||
updateScore();
|
||||
}
|
||||
|
||||
/*Calculer le score*/
|
||||
private void updateScore() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long timeElapsed = (currentTime - startTime) / 1000; // en secondes
|
||||
|
||||
int baseScore = 1000;
|
||||
int timeBonus = Math.max(0, 300 - (int)timeElapsed) * 2; // Bonus temps
|
||||
int errorPenalty = errors * 50; // Pénalité erreurs
|
||||
int difficultyMultiplier = getDifficultyMultiplier();
|
||||
|
||||
score = Math.max(0, (baseScore + timeBonus - errorPenalty) * difficultyMultiplier);
|
||||
}
|
||||
|
||||
private int getDifficultyMultiplier() {
|
||||
switch (difficulty.toLowerCase()) {
|
||||
case "facile": return 1;
|
||||
case "moyen": return 2;
|
||||
case "difficile": return 3;
|
||||
default: return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*Fonction pour obtenir le score final*/
|
||||
public int getFinalScore() {
|
||||
if (isWon()) {
|
||||
updateScore(); // Dernier calcul
|
||||
return score;
|
||||
}
|
||||
return 0; // Score 0 si perdu
|
||||
}
|
||||
|
||||
/*Fonction pour obtenir le temps écoulé*/
|
||||
public long getTimeElapsed() {
|
||||
return (System.currentTimeMillis() - startTime) / 1000;
|
||||
}
|
||||
|
||||
/*Fonction pour obtenir la difficulté*/
|
||||
public String getDifficulty() {
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public boolean hasTriedLetter(char letter) {
|
||||
letter = Character.toLowerCase(letter);
|
||||
return triedLetters.contains(letter);
|
||||
}
|
||||
|
||||
public boolean isWon() {
|
||||
for (int i = 0; i < hiddenWord.length; i++) {
|
||||
// Ignorer les espaces dans la vérification
|
||||
if (word.charAt(i) != ' ' && hiddenWord[i] == '_') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isLost() {
|
||||
return errors >= MAX_ERRORS;
|
||||
}
|
||||
|
||||
public int getErrors() {
|
||||
return errors;
|
||||
}
|
||||
|
||||
public String getHiddenWord() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < hiddenWord.length; i++) {
|
||||
sb.append(hiddenWord[i]);
|
||||
if (i < hiddenWord.length - 1) {
|
||||
sb.append(' ');
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getWord() {
|
||||
return word;
|
||||
}
|
||||
}
|
BIN
PenduWIlfried/HangmanPanel.class
Normal file
BIN
PenduWIlfried/HangmanPanel.class
Normal file
Binary file not shown.
54
PenduWIlfried/HangmanPanel.java
Normal file
54
PenduWIlfried/HangmanPanel.java
Normal file
@@ -0,0 +1,54 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class HangmanPanel extends JPanel {
|
||||
|
||||
private int errors = 0;
|
||||
|
||||
public HangmanPanel() {
|
||||
setPreferredSize(new Dimension(300, 400));
|
||||
setBackground(Color.WHITE);
|
||||
}
|
||||
|
||||
/*mettre à jour les erreurs*/
|
||||
public void setErrors(int errors) {
|
||||
this.errors = errors;
|
||||
repaint();
|
||||
}
|
||||
|
||||
/*Dessiner le pendu*/
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
|
||||
// Amélioration visuelle
|
||||
g.setColor(Color.BLACK);
|
||||
g.setFont(new Font("Arial", Font.BOLD, 16));
|
||||
g.drawString("Erreurs: " + errors + "/9", 50, 30);
|
||||
|
||||
// Dessin du pendu
|
||||
g.drawLine(50, 300, 200, 300); // Base
|
||||
g.drawLine(125, 300, 125, 50); // Poteau vertical
|
||||
g.drawLine(125, 50, 250, 50); // Poteau horizontal
|
||||
g.drawLine(250, 50, 250, 80); // Corde
|
||||
|
||||
// Parties du bonhomme
|
||||
if (errors > 0) g.drawOval(230, 80, 40, 40); // Tête
|
||||
if (errors > 1) g.drawLine(250, 120, 250, 200); // Corps
|
||||
if (errors > 2) g.drawLine(250, 140, 220, 170); // Bras gauche
|
||||
if (errors > 3) g.drawLine(250, 140, 280, 170); // Bras droit
|
||||
if (errors > 4) g.drawLine(250, 200, 220, 250); // Jambe gauche
|
||||
if (errors > 5) g.drawLine(250, 200, 280, 250); // Jambe droite
|
||||
|
||||
// VISAGE TRISTE quand il meurt :
|
||||
if (errors > 6) {
|
||||
g.drawLine(235, 95, 245, 95); // Œil gauche
|
||||
}
|
||||
if (errors > 7) {
|
||||
g.drawLine(255, 95, 265, 95); // Œil droit
|
||||
}
|
||||
if (errors > 8) {
|
||||
// Bouche TRISTE (arc vers le bas)
|
||||
g.drawArc(235, 110, 30, 15, 0, 180);
|
||||
}
|
||||
}
|
||||
}
|
BIN
PenduWIlfried/main$1.class
Normal file
BIN
PenduWIlfried/main$1.class
Normal file
Binary file not shown.
BIN
PenduWIlfried/main$2.class
Normal file
BIN
PenduWIlfried/main$2.class
Normal file
Binary file not shown.
BIN
PenduWIlfried/main$3.class
Normal file
BIN
PenduWIlfried/main$3.class
Normal file
Binary file not shown.
BIN
PenduWIlfried/main.class
Normal file
BIN
PenduWIlfried/main.class
Normal file
Binary file not shown.
193
PenduWIlfried/main.java
Normal file
193
PenduWIlfried/main.java
Normal file
@@ -0,0 +1,193 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class main {
|
||||
|
||||
public static GameState gameState;
|
||||
public static JLabel wordLabel;
|
||||
public static HangmanPanel hangmanPanel;
|
||||
public static JTextField inputField;
|
||||
public static JLabel messageLabel;
|
||||
public static JLabel scoreLabel;
|
||||
public static JLabel timeLabel;
|
||||
public static Timer timer;
|
||||
|
||||
/*Fonction main*/
|
||||
public static void main(String[] args) {
|
||||
showDifficultySelection();
|
||||
}
|
||||
|
||||
/*Fonction pour sélectionner la difficulté*/
|
||||
public static void showDifficultySelection() {
|
||||
JFrame selectionFrame = new JFrame("Sélection de Difficulté");
|
||||
selectionFrame.setSize(400, 300);
|
||||
selectionFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
selectionFrame.setLayout(new GridLayout(4, 1));
|
||||
|
||||
JLabel titleLabel = new JLabel("Choisissez la difficulté:", SwingConstants.CENTER);
|
||||
titleLabel.setFont(new Font("Arial", Font.BOLD, 20));
|
||||
|
||||
JButton easyButton = new JButton("FACILE - Mots courts (< 8 lettres)");
|
||||
JButton mediumButton = new JButton("MOYEN - Mots longs (≥ 8 lettres)");
|
||||
JButton hardButton = new JButton("DIFFICILE - Phrases (2 mots)");
|
||||
|
||||
easyButton.addActionListener(e -> startGame("facile", selectionFrame));
|
||||
mediumButton.addActionListener(e -> startGame("moyen", selectionFrame));
|
||||
hardButton.addActionListener(e -> startGame("difficile", selectionFrame));
|
||||
|
||||
selectionFrame.add(titleLabel);
|
||||
selectionFrame.add(easyButton);
|
||||
selectionFrame.add(mediumButton);
|
||||
selectionFrame.add(hardButton);
|
||||
|
||||
selectionFrame.setVisible(true);
|
||||
}
|
||||
|
||||
/*Fonction pour démarrer le jeu*/
|
||||
public static void startGame(String difficulty, JFrame selectionFrame) {
|
||||
selectionFrame.dispose();
|
||||
String selectedWord = ChooseWord.chooseTheWord(difficulty);
|
||||
gameState = new GameState(selectedWord, difficulty);
|
||||
createInterface();
|
||||
startTimer();
|
||||
}
|
||||
|
||||
/*Fonction pour créer l'interface*/
|
||||
public static void createInterface() {
|
||||
JFrame window = new JFrame("HangmanGame - Difficulté: " + gameState.getDifficulty());
|
||||
window.setSize(800, 600);
|
||||
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
window.setLayout(new BorderLayout());
|
||||
|
||||
// Panel d'information (score et temps)
|
||||
JPanel infoPanel = new JPanel(new GridLayout(1, 3));
|
||||
|
||||
JLabel difficultyLabel = new JLabel("Difficulté: " + gameState.getDifficulty(), SwingConstants.CENTER);
|
||||
difficultyLabel.setFont(new Font("Arial", Font.BOLD, 16));
|
||||
|
||||
scoreLabel = new JLabel("Score: 0", SwingConstants.CENTER);
|
||||
scoreLabel.setFont(new Font("Arial", Font.BOLD, 16));
|
||||
|
||||
timeLabel = new JLabel("Temps: 0s", SwingConstants.CENTER);
|
||||
timeLabel.setFont(new Font("Arial", Font.BOLD, 16));
|
||||
|
||||
infoPanel.add(difficultyLabel);
|
||||
infoPanel.add(scoreLabel);
|
||||
infoPanel.add(timeLabel);
|
||||
|
||||
wordLabel = new JLabel(gameState.getHiddenWord(), SwingConstants.CENTER);
|
||||
wordLabel.setFont(new Font("Arial", Font.BOLD, 40));
|
||||
|
||||
hangmanPanel = new HangmanPanel();
|
||||
|
||||
JPanel inputPanel = new JPanel();
|
||||
inputField = new JTextField(2);
|
||||
inputField.setFont(new Font("Arial", Font.BOLD, 20));
|
||||
JButton submitButton = new JButton("Essayer la lettre");
|
||||
|
||||
messageLabel = new JLabel("Entrez une lettre:");
|
||||
inputPanel.add(messageLabel);
|
||||
inputPanel.add(inputField);
|
||||
inputPanel.add(submitButton);
|
||||
|
||||
window.add(infoPanel, BorderLayout.NORTH);
|
||||
window.add(wordLabel, BorderLayout.CENTER);
|
||||
window.add(hangmanPanel, BorderLayout.WEST);
|
||||
window.add(inputPanel, BorderLayout.SOUTH);
|
||||
|
||||
/*événement du bouton*/
|
||||
submitButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleLetterInput();
|
||||
}
|
||||
});
|
||||
|
||||
/*événement de la touche Entrée*/
|
||||
inputField.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleLetterInput();
|
||||
}
|
||||
});
|
||||
|
||||
window.setVisible(true);
|
||||
inputField.requestFocus();
|
||||
}
|
||||
|
||||
/*Fonction pour démarrer le chronomètre*/
|
||||
public static void startTimer() {
|
||||
timer = new Timer(1000, new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
updateDisplay();
|
||||
}
|
||||
});
|
||||
timer.start();
|
||||
}
|
||||
|
||||
/*Fonction pour mettre à jour l'affichage*/
|
||||
public static void updateDisplay() {
|
||||
timeLabel.setText("Temps: " + gameState.getTimeElapsed() + "s");
|
||||
scoreLabel.setText("Score: " + gameState.getFinalScore());
|
||||
}
|
||||
|
||||
/*Fonction pour gérer la saisie de lettre*/
|
||||
public static void handleLetterInput() {
|
||||
String input = inputField.getText().toLowerCase();
|
||||
if (input.length() != 1 || !Character.isLetter(input.charAt(0))) {
|
||||
messageLabel.setText("Entrez une seule lettre valide.");
|
||||
return;
|
||||
}
|
||||
|
||||
char letter = input.charAt(0);
|
||||
inputField.setText("");
|
||||
|
||||
if (gameState.hasTriedLetter(letter)) {
|
||||
messageLabel.setText("Lettre déjà essayée.");
|
||||
return;
|
||||
}
|
||||
|
||||
gameState.tryLetter(letter);
|
||||
wordLabel.setText(gameState.getHiddenWord());
|
||||
hangmanPanel.setErrors(gameState.getErrors());
|
||||
updateDisplay();
|
||||
|
||||
if (gameState.isWon()) {
|
||||
timer.stop();
|
||||
int finalScore = gameState.getFinalScore();
|
||||
messageLabel.setText("Félicitations ! Vous avez gagné ! Score: " + finalScore);
|
||||
inputField.setEditable(false);
|
||||
showEndGameMessage(true, finalScore);
|
||||
} else if (gameState.isLost()) {
|
||||
timer.stop();
|
||||
messageLabel.setText("Perdu ! Le mot était: " + gameState.getWord());
|
||||
inputField.setEditable(false);
|
||||
showEndGameMessage(false, 0);
|
||||
} else {
|
||||
messageLabel.setText("Continuez... Erreurs: " + gameState.getErrors() + "/" + 9);
|
||||
}
|
||||
}
|
||||
|
||||
/*Fonction pour afficher le message de fin de jeu*/
|
||||
public static void showEndGameMessage(boolean won, int score) {
|
||||
String message = won ?
|
||||
"FÉLICITATIONS !\nVous avez gagné !\nScore final: " + score + "\nTemps: " + gameState.getTimeElapsed() + "s" :
|
||||
"DOMAGE !\nVous avez perdu.\nLe mot était: " + gameState.getWord() + "\nVoulez-vous réessayer ?";
|
||||
|
||||
int optionType = won ? JOptionPane.INFORMATION_MESSAGE : JOptionPane.QUESTION_MESSAGE;
|
||||
|
||||
int choice = JOptionPane.showConfirmDialog(null,
|
||||
message,
|
||||
"Partie Terminée",
|
||||
JOptionPane.DEFAULT_OPTION,
|
||||
optionType);
|
||||
|
||||
if (!won || choice == JOptionPane.OK_OPTION) {
|
||||
// Retour au menu principal
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
JFrame currentFrame = (JFrame) SwingUtilities.getWindowAncestor(inputField);
|
||||
currentFrame.dispose();
|
||||
showDifficultySelection();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
87
PenduWIlfried/motsDifficiles.txt
Normal file
87
PenduWIlfried/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
PenduWIlfried/motsFacile.txt
Normal file
694
PenduWIlfried/motsFacile.txt
Normal file
File diff suppressed because it is too large
Load Diff
110
PenduWIlfried/motsMoyen.txt
Normal file
110
PenduWIlfried/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
|
54
readme.md
Normal file
54
readme.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Exercice 5 – Mesure de métriques et profiling du programme Hangman
|
||||
|
||||
# PenduWilfried
|
||||
|
||||
## 1. Calcul de la complexité cyclomatique
|
||||
|
||||
| Classe / Méthode | Description | Complexité cyclomatique |
|
||||
|------------------|------------|------------------------|
|
||||
| `ChooseWord.chooseTheWord(String)` | Choisit un mot selon la difficulté | 4 |
|
||||
| `ChooseWord.getFilenameByDifficulty(String)` | Retourne le fichier selon difficulté | 4 |
|
||||
| `ChooseWord.isValidForDifficulty(String, String)` | Vérifie si le mot est valide pour la difficulté | 4 |
|
||||
| `GameState.tryLetter(char)` | Essaie une lettre et met à jour le score | 3 |
|
||||
| `GameState.updateScore()` | Calcule le score en fonction du temps et des erreurs | 3 |
|
||||
| `GameState.getDifficultyMultiplier()` | Retourne multiplicateur selon difficulté | 4 |
|
||||
| `GameState.isWon()` | Vérifie si le joueur a gagné | 2 |
|
||||
| `HangmanPanel.paintComponent(Graphics)` | Dessine le pendu selon erreurs | 9 |
|
||||
| `main.handleLetterInput()` | Gestion saisie utilisateur et mise à jour UI | 9 |
|
||||
| `main.showEndGameMessage(boolean, int)` | Affiche message de fin de jeu | 3 |
|
||||
| `main.main(String[])` | Point d’entrée du programme | 1 |
|
||||
|
||||
**Conclusion :**
|
||||
La majorité des fonctions ont une complexité modérée (<10). Les fonctions `paintComponent` et `handleLetterInput` sont plus complexes, ce qui pourrait justifier une refactorisation pour améliorer la lisibilité.
|
||||
|
||||
|
||||
# PenduJude
|
||||
|
||||
## 1. Calcul de la complexité cyclomatique
|
||||
|
||||
|
||||
| Classe / Méthode | Description | Complexité cyclomatique |
|
||||
|------------------|------------|------------------------|
|
||||
| `Display.showWord(String, Set<Character>)` | Affiche le mot avec lettres devinées | 3 (for + if/else) |
|
||||
| `Display.showLives(int, int)` | Affiche le nombre de vies | 1 |
|
||||
| `GameLogic.isWordGuessed(String, Set<Character>)` | Vérifie si le mot est deviné | 3 (for + if + continue) |
|
||||
| `InputHandler.getLetter(Scanner, Set<Character>)` | Gestion de la saisie utilisateur | 5 (while + if multiples + continue) |
|
||||
| `ScoreManager.calculateScore(int, long, String)` | Calcule le score final | 5 (switch + if) |
|
||||
| `TimerManager.start()` | Démarre le chronomètre | 1 |
|
||||
| `TimerManager.getElapsedTimeMillis()` | Retourne le temps écoulé | 1 |
|
||||
| `WordSelector.loadWordsForDifficulty(String, String)` | Charge les mots depuis un fichier | 3 (try/catch + while) |
|
||||
| `WordSelector.pickWord(String)` | Retourne un mot aléatoire selon difficulté | 2 (if) |
|
||||
| `HangedGameGUI.processGuess()` | Traitement d’une lettre saisie | 9 (if/else multiples + for) |
|
||||
| `HangedGameGUI.updateWordDisplay()` | Met à jour l’affichage du mot | 3 (for + if/else) |
|
||||
| `HangedGameGUI.drawHangman(Graphics)` | Dessine le pendu selon erreurs | 11 (chaîne de if) |
|
||||
| `HangedGameGUI.checkGameEnd()` | Vérifie la fin du jeu | 2 (if) |
|
||||
| `HangedGameGUI.endGame(boolean)` | Affiche le message de fin et score | 5 (if/else + JOptionPane) |
|
||||
| `HangedGameGUI.main(String[])` | Point d’entrée | 1 |
|
||||
|
||||
**Conclusion :**
|
||||
Certaines méthodes GUI (`drawHangman`, `processGuess`) ont une complexité élevée (>9). Les autres fonctions sont simples et bien encapsulées. Une refactorisation pourrait améliorer la lisibilité et la maintenabilité.
|
||||
Le code est **fonctionnel et structuré**, avec quelques méthodes complexes qui pourraient bénéficier d’une simplification. La séparation logique (game logic, affichage, gestion du timer) est bien faite, ce qui facilite la maintenance et l’évolution.
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user