re correction

This commit is contained in:
Aissi Jude Christ
2025-10-08 15:28:55 +02:00
parent 7270ba1a20
commit 9058650339
9 changed files with 54 additions and 19 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -15,16 +15,35 @@ public class GameState {
this.word = wordToGuess.toLowerCase();
this.difficulty = difficulty;
this.hiddenWord = new char[word.length()];
Arrays.fill(hiddenWord, '_');
// 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;
@@ -84,15 +103,15 @@ public class GameState {
return difficulty;
}
// Les autres méthodes restent inchangées...
public boolean hasTriedLetter(char letter) {
letter = Character.toLowerCase(letter);
return triedLetters.contains(letter);
}
public boolean isWon() {
for (char c : hiddenWord) {
if (c == '_') {
for (int i = 0; i < hiddenWord.length; i++) {
// Ignorer les espaces dans la vérification
if (word.charAt(i) != ' ' && hiddenWord[i] == '_') {
return false;
}
}

Binary file not shown.

View File

@@ -5,6 +5,11 @@ 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;
@@ -17,22 +22,33 @@ public class HangmanPanel extends JPanel {
// Amélioration visuelle
g.setColor(Color.BLACK);
g.setFont(new Font("Arial", Font.BOLD, 12));
g.drawString("Erreurs: " + errors + "/9", 10, 20);
g.setFont(new Font("Arial", Font.BOLD, 16));
g.drawString("Erreurs: " + errors + "/9", 50, 30);
g.drawLine(50, 300, 200, 300);
g.drawLine(125, 300, 125, 50);
g.drawLine(125, 50, 250, 50);
g.drawLine(250, 50, 250, 80);
// 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
if (errors > 0) g.drawOval(230, 80, 40, 40);
if (errors > 1) g.drawLine(250, 120, 250, 200);
if (errors > 2) g.drawLine(250, 140, 220, 170);
if (errors > 3) g.drawLine(250, 140, 280, 170);
if (errors > 4) g.drawLine(250, 200, 220, 250);
if (errors > 5) g.drawLine(250, 200, 280, 250);
if (errors > 6) g.drawLine(230, 90, 270, 90);
if (errors > 7) g.drawString("X", 240, 100);
if (errors > 8) g.drawString("X", 255, 100);
// 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

Binary file not shown.

BIN
PenduWIlfried/main$2.class Normal file

Binary file not shown.

BIN
PenduWIlfried/main$3.class Normal file

Binary file not shown.

BIN
PenduWIlfried/main.class Normal file

Binary file not shown.