Skip to content
Snippets Groups Projects
Commit 35746501 authored by joel.cavat's avatar joel.cavat
Browse files

Add Hangman for iteration 2

parent 60e55f59
No related branches found
No related tags found
No related merge requests found
......@@ -275,6 +275,44 @@ qui sera une alternative de `Vector.linespace(0.0, 5.0, 20)`.
## Fonctionnalités à réaliser sur le pendu
Modifiez le jeux pour une utilisation suivante :
```java
Hangman h = HangmanGame.withSecretWord("mystere");
/*
* variante: Hangman h = HangmanGame.randomWord();
* (choisit aléatoirement un mot dans une liste)
* doit être implémenté !
*/
String currentWord = h.currentWord(); // currentWord = "_______";
h = h.tryWith('h');
int attempts = h.attempts(); // attempts = 1
int failedAttempts = h.failedAttepts(); // attempts = 1
currentWord = h.currentWord(); // currentWord = "_______";
h.printGallowsIfError(); // affiche la potence uniquement si le dernier essai est mauvais
h = h.tryWith('s');
attempts = h.attempts(); // attempts = 2
failedAttempts = h.failedAttepts(); // attempts = 1
currentWord = h.currentWord(); // currentWord = "____e_e";
h.printGallowsIfError();
h.printGallows(); // affiche la potence même si aucune erreur
// Utilisation finale
while ( !h.isFinished() ) {
String letter = askLetter(); // demande une lettre à l'utilisateur
h = h.tryWith( letter );
h.printCurrentWord();
h.printGallowIfError();
}
if( h.hasWon() ) {
System.out.println("Bravo");
} else {
System.out.println("Failed");
}
```
## Fonctionnalités à réaliser sur les structures
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment