From c8a83e963733803ad146efb9d5748145282b4e05 Mon Sep 17 00:00:00 2001 From: James Boutaric Date: Wed, 15 Oct 2025 10:26:53 +0200 Subject: [PATCH] . --- Letter.java | 50 + enter_word.class | Bin 0 -> 941 bytes enter_word.java | 22 + francais.txt | 22743 ++++++++++++++++++++++++++++++++++++++++++++ main.class | Bin 0 -> 2669 bytes main.java | 126 + word_search.class | Bin 0 -> 1317 bytes word_search.java | 28 + 8 files changed, 22969 insertions(+) create mode 100644 Letter.java create mode 100644 enter_word.class create mode 100644 enter_word.java create mode 100644 francais.txt create mode 100644 main.class create mode 100644 main.java create mode 100644 word_search.class create mode 100644 word_search.java diff --git a/Letter.java b/Letter.java new file mode 100644 index 0000000..cdd8e28 --- /dev/null +++ b/Letter.java @@ -0,0 +1,50 @@ +import java.util.*; + +public class Letter { + public String wordToFind; + public char selectedLetter; + public StringBuilder wordBuilding; + public StringBuilder incorrectLetters = new StringBuilder(); + + // Constructeur + public Letter(String mot) { + this.wordToFind = mot; + this.wordBuilding = new StringBuilder(); + // Initialise le mot caché avec des underscores + for (int i = 0; i < mot.length(); i++) { + if (mot.charAt(i) == ' ') { + this.wordBuilding.append(' '); // garde les espaces + } else { + this.wordBuilding.append('_'); + } + } + } + + // Setter pour la lettre sélectionnée + public void setLetter(char currentLetter) { + this.selectedLetter = currentLetter; + } + + // Vérifie si la lettre est dans le mot + public boolean letterInWord() { + boolean found = false; + + for (int i = 0; i < this.wordToFind.length(); i++) { + if (this.selectedLetter == this.wordToFind.charAt(i)) { + // Remplace l'underscore par la lettre correcte + this.wordBuilding.setCharAt(i, this.selectedLetter); + found = true; + } + } + + // Si la lettre n'est pas trouvée, on l'ajoute aux incorrectes + if (!found) { + if (this.incorrectLetters.length() > 0) { + this.incorrectLetters.append(" "); + } + this.incorrectLetters.append(this.selectedLetter); + } + + return found; + } +} diff --git a/enter_word.class b/enter_word.class new file mode 100644 index 0000000000000000000000000000000000000000..c8c05427c8234608ddb8d3e1f7ed9b75579e0760 GI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iAg!Bj10WNC5g$|zKI1;zL-WdX546oF*0xk=a&{G zr@Cc=ba8^pRXtEjVPp_+%Fiz;E-6YZ@J%hr$WJNeU}#`u5Cr+UC{-aXv9!22Rl!Pu zk%OU$k%2!qzeFKXp`<9kv@EpXys{)Qvjn7ppN*l7i=myN zgPoxhlrXv&8B{=4LMo8Vyt4f4RDDPqfTR_-#N?9vqDn@F8OTWvsu1EhkHox`oYZ0! zpZxsn(gJHtuOf+{Xbh<=NX4QYIk2##ZKx5>i8(pJnI);#j0`-Ud3mWt&N+$2#i_;Y z484pDsu+I4=2Uiuentj4{7OMJ8Q5P8iVS=VObiSREDVgGijaYUfe}<|foVAgc`&WS zpv=I)z{bD`s+$=Y87deU7<|Dx7#LKwwlgql?OvTo%89|nEKUkq%5plA|csD^q%mw^c!O}x7q_#(G6l=x_GV<<(00VJxc z7&sWJ8F(0K8JHPrz{#MNp^kxpL4<*sp_PG=p&m>&g2`rvZUzPhE(S)19)>=K2@H|| Dc?et= literal 0 HcmV?d00001 diff --git a/main.java b/main.java new file mode 100644 index 0000000..f3f1140 --- /dev/null +++ b/main.java @@ -0,0 +1,126 @@ +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; + } + } + + 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]); + } + + //Element toujours présent + public void showGame(){ + System.out.println("lettre fausse : " + this.curentLetter.incorrectLetters); + displayHangman(nbError); + System.out.println("mot a trouver " + this.curentLetter.wordBuilding); + } + + //Permet au jeu de fonctionner et de se terminer + public void game(){ + while(nbError<6 && !winCondition()){ + char letter = enter_word.getLetter(); + this.curentLetter.setLetter(letter); + if (!this.curentLetter.letterInWord()){ + nbError++; + } + showGame(); + } + if (winCondition()){ + // tu gagnes + System.out.println("victoir (celui qui a écris a 5 de QI)"); + } + else{ //tu perds + System.out.println("ta perdu sale étron"); + System.out.println(" le bon mot était : " + this.word); + } + } + + public static void main(String[] args) { + main test =new main(); + test.game(); + + } +} diff --git a/word_search.class b/word_search.class new file mode 100644 index 0000000000000000000000000000000000000000..b594e42c85eb16e84e977d3d15c9e2bb190c3f2e GIT binary patch literal 1317 zcmX^0Z`VEs1_mdFcrFGe24;2!79Ivx1~x_pfvm)`ME#t^ymWp4q^#8B5=I6#o6Nk- z5<5l)W)00Sb_Nbc24S$G(vr*^eaE7r#7dvc;u0{+ux6GVW4h8{62A;H{#JuFh%woNgiV`jcUIrnMLxdR_L^XWCios3^E-A{) zOScADFUrUu2$ld_5S*NtmzP?^!644az#1Cjrfb2)Ai^LCGDC`yK^bZW)Iw`)CW6$< z@G!_S$T2c-XCxN;rB;;qWag!Uy&DCRRp4PzWKd#c;K+kZiD+nIn#IMS!l25|pvJ?X z4pNR3k`U)JGO&~sW#)pEY4R{=fh=UtEOyN;D5(UA>F_YGE z=rb6wGZ^wP7%><#GVmch4hnKc2Ij<+6ttj%#G17x*y*M`3}&EMWlhe>hnS|x$zaJ~ z#m->O!(hW;3yUmBAXgTbq~+>szO?3azs3^6x2owSyJPe);UW^PZ#hF#9;CS%_B`F^s z244n0Mh13Jym;o7Ffy=ccxrlrbOi7)1Tq9MGBBs7g1n;Pi5y+f5MpNtVPud6hbT0C z_~nm7L;V>=W#HEF*2wrxIz7-j^ZhGh0Hv#?-P@9QWX^086p@NxXbg4 zQsRqK6N{2F7#Ucc^HWk88TdiT$*(jwDYYmBq?VC^H$Alkk~PBfi&7XFc!Nt4le2vj z3!w5`!TF^{$*G`B!pIOX&LG0Tpv)xxpFx;`2_nkC$j%VVz{n8Gz`(%75C;G&)hdVp literal 0 HcmV?d00001 diff --git a/word_search.java b/word_search.java new file mode 100644 index 0000000..1cd8479 --- /dev/null +++ b/word_search.java @@ -0,0 +1,28 @@ +import java.util.*; +import java.io.*; + +public class word_search { + public static String getRandomWord() { + List words = new ArrayList<>(); // Liste dynamique de mots + Random random = new Random(); + try { //lis le fichier, regarde si il existe avant de sélectionner un mot aléatoire + File file = new File("francais.txt"); + Scanner scanner = new Scanner(file, "UTF-8"); + while (scanner.hasNextLine()) { + String line = scanner.nextLine().trim(); + if (!line.isEmpty()) { // ignore les lignes vides + words.add(line.toLowerCase()); + } + } + scanner.close(); + if (words.isEmpty()) { + System.out.println(" Aucun mot trouvé dans le fichier français.txt !"); + return "erreur"; + } + return words.get(random.nextInt(words.size())); + } catch (FileNotFoundException e) { + System.out.println(" Fichier 'français.txt' introuvable !"); + return "erreur"; + } + } +} \ No newline at end of file