2025-10-08 14:25:38 +02:00
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
|
|
|
|
|
public class main {
|
|
|
|
|
|
public String word = word_search.getRandomWord();
|
|
|
|
|
|
public Letter curentLetter = new Letter(word);
|
|
|
|
|
|
public int nbError=0;
|
|
|
|
|
|
public boolean winCondition=false;
|
|
|
|
|
|
|
|
|
|
|
|
//creer wincondtion (je lis le mot en construction (wordbuilding), compare avec word, si égal c'est gagné)
|
|
|
|
|
|
public boolean winCondition(){
|
|
|
|
|
|
if(curentLetter.wordBuilding.toString().equals(word)){
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-08 17:56:27 +02:00
|
|
|
|
|
2025-10-08 14:25:38 +02:00
|
|
|
|
|
|
|
|
|
|
public static void displayHangman(int mistakes) {
|
|
|
|
|
|
String[] hangman = new String[7]; // 7 étapes du pendu
|
|
|
|
|
|
|
|
|
|
|
|
// Étape 0 : début du jeu
|
|
|
|
|
|
hangman[0] =
|
|
|
|
|
|
"------\n" +
|
|
|
|
|
|
"| |\n" +
|
|
|
|
|
|
" |\n" +
|
|
|
|
|
|
" |\n" +
|
|
|
|
|
|
" |\n" +
|
|
|
|
|
|
" |\n" +
|
|
|
|
|
|
"=========\n";
|
|
|
|
|
|
|
|
|
|
|
|
// Étape 1 : tête
|
|
|
|
|
|
hangman[1] =
|
|
|
|
|
|
"------\n" +
|
|
|
|
|
|
"| |\n" +
|
|
|
|
|
|
"O |\n" +
|
|
|
|
|
|
" |\n" +
|
|
|
|
|
|
" |\n" +
|
|
|
|
|
|
" |\n" +
|
|
|
|
|
|
"=========\n";
|
|
|
|
|
|
|
|
|
|
|
|
// Étape 2 : tronc
|
|
|
|
|
|
hangman[2] =
|
|
|
|
|
|
"------\n" +
|
|
|
|
|
|
"| |\n" +
|
|
|
|
|
|
"O |\n" +
|
|
|
|
|
|
"| |\n" +
|
|
|
|
|
|
" |\n" +
|
|
|
|
|
|
" |\n" +
|
|
|
|
|
|
"=========\n";
|
|
|
|
|
|
|
|
|
|
|
|
// Étape 3 : un bras
|
|
|
|
|
|
hangman[3] =
|
|
|
|
|
|
"------\n" +
|
|
|
|
|
|
"| |\n" +
|
|
|
|
|
|
"O |\n" +
|
|
|
|
|
|
"/| |\n" +
|
|
|
|
|
|
" |\n" +
|
|
|
|
|
|
" |\n" +
|
|
|
|
|
|
"=========\n";
|
|
|
|
|
|
|
|
|
|
|
|
// Étape 4 : deux bras
|
|
|
|
|
|
hangman[4] =
|
|
|
|
|
|
"------\n" +
|
|
|
|
|
|
"| |\n" +
|
|
|
|
|
|
"O |\n" +
|
|
|
|
|
|
"/|\\ |\n" +
|
|
|
|
|
|
" |\n" +
|
|
|
|
|
|
" |\n" +
|
|
|
|
|
|
"=========\n";
|
|
|
|
|
|
|
|
|
|
|
|
// Étape 5 : une jambe
|
|
|
|
|
|
hangman[5] =
|
|
|
|
|
|
"------\n" +
|
|
|
|
|
|
"| |\n" +
|
|
|
|
|
|
"O |\n" +
|
|
|
|
|
|
"/|\\ |\n" +
|
|
|
|
|
|
"/ |\n" +
|
|
|
|
|
|
" |\n" +
|
|
|
|
|
|
"=========\n";
|
|
|
|
|
|
// Étape 6 : pendu complet (défaite)
|
|
|
|
|
|
hangman[6] =
|
|
|
|
|
|
"------\n" +
|
|
|
|
|
|
"| |\n" +
|
|
|
|
|
|
"O |\n" +
|
|
|
|
|
|
"/|\\ |\n" +
|
|
|
|
|
|
"/ \\ |\n" +
|
|
|
|
|
|
" |\n" +
|
|
|
|
|
|
"=========\n";
|
|
|
|
|
|
|
|
|
|
|
|
// Affiche le pendu correspondant au nombre d’erreurs
|
|
|
|
|
|
System.out.println(hangman[mistakes]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-08 14:44:57 +02:00
|
|
|
|
//Element toujours présent
|
2025-10-08 14:25:38 +02:00
|
|
|
|
public void showGame(){
|
|
|
|
|
|
System.out.println("lettre fausse : " + this.curentLetter.incorrectLetters);
|
|
|
|
|
|
displayHangman(nbError);
|
|
|
|
|
|
System.out.println("mot a trouver " + this.curentLetter.wordBuilding);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-08 14:44:57 +02:00
|
|
|
|
//Permet au jeu de fonctionner et de se terminer
|
2025-10-08 14:25:38 +02:00
|
|
|
|
public void game(){
|
|
|
|
|
|
while(nbError<6 && !winCondition()){
|
|
|
|
|
|
char letter = enter_word.getLetter();
|
|
|
|
|
|
this.curentLetter.setLetter(letter);
|
|
|
|
|
|
if (!this.curentLetter.letterInWord()){
|
|
|
|
|
|
nbError++;
|
|
|
|
|
|
}
|
|
|
|
|
|
showGame();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (winCondition()){
|
2025-10-08 14:44:57 +02:00
|
|
|
|
// tu gagnes
|
2025-10-08 14:25:38 +02:00
|
|
|
|
System.out.println("victoir (celui qui a écris a 5 de QI)");
|
|
|
|
|
|
}
|
2025-10-08 14:44:57 +02:00
|
|
|
|
else{ //tu perds
|
2025-10-08 14:25:38 +02:00
|
|
|
|
System.out.println("ta perdu sale étron");
|
2025-10-08 14:34:20 +02:00
|
|
|
|
System.out.println(" le bon mot était : " + this.word);
|
2025-10-08 14:25:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
main test =new main();
|
|
|
|
|
|
test.game();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|