forked from menault/TD3_DEV51_Qualite_Algo
branche jude
This commit is contained in:
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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user