forked from menault/TD3_DEV51_Qualite_Algo
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c476e3ae53 | |||
| 52aa0d6137 | |||
| 2760d87804 | |||
| 6cbe15f3cf | |||
| ca6cabe021 | |||
| bd88e54ee2 |
Binary file not shown.
+22743
File diff suppressed because it is too large
Load Diff
BIN
Binary file not shown.
@@ -1,11 +1,60 @@
|
||||
import java.util.Scanner;
|
||||
import java.util.*;
|
||||
|
||||
public class main {
|
||||
public String word = word_search.getRandomWord();
|
||||
public Letter curentLetter = new Letter(word);
|
||||
public int nbError=0;
|
||||
public boolean winCondition=false;
|
||||
public String word; // mot courant
|
||||
public Letter curentLetter; // gestion lettres
|
||||
public int nbError = 0; // erreurs
|
||||
public boolean winCondition = false;
|
||||
|
||||
// Stockage des mots par difficulté
|
||||
public String easyWord;
|
||||
public String mediumWord;
|
||||
public String hardWord1;
|
||||
public String hardWord2;
|
||||
|
||||
public main() {
|
||||
// ---------------------------------------------------
|
||||
// 1️⃣ Récupération des mots aléatoires pour chaque difficulté
|
||||
// ---------------------------------------------------
|
||||
ArrayList<String> allWords = new ArrayList<>();
|
||||
allWords.add(word_search.getRandomWord()); // exemple simple
|
||||
allWords.add(word_search.getRandomWord());
|
||||
allWords.add(word_search.getRandomWord());
|
||||
allWords.add(word_search.getRandomWord());
|
||||
|
||||
// Trier par longueur pour facile/moyen
|
||||
for (String w : allWords) {
|
||||
if (w.length() < 8 && easyWord == null) easyWord = w;
|
||||
else if (w.length() >= 8 && mediumWord == null) mediumWord = w;
|
||||
else if (hardWord1 == null) hardWord1 = w;
|
||||
else if (hardWord2 == null) hardWord2 = w;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
// 2️⃣ Choix de la difficulté
|
||||
// ---------------------------------------------------
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("Choisis la difficulté : facile / moyen / difficile");
|
||||
String choice = sc.nextLine().toLowerCase();
|
||||
|
||||
switch (choice) {
|
||||
case "facile":
|
||||
word = easyWord;
|
||||
break;
|
||||
case "moyen":
|
||||
word = mediumWord;
|
||||
break;
|
||||
case "difficile":
|
||||
// Ici on choisira les 2 mots pour faire deviner
|
||||
word = hardWord1 + " " + hardWord2;
|
||||
break;
|
||||
default:
|
||||
System.out.println("Difficulté invalide, on prend facile par défaut");
|
||||
word = easyWord;
|
||||
}
|
||||
|
||||
curentLetter = new Letter(word);
|
||||
}
|
||||
//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)){
|
||||
@@ -91,13 +140,16 @@ public class main {
|
||||
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);
|
||||
}
|
||||
|
||||
//Ligne 100
|
||||
//Permet au jeu de fonctionner et de se terminer
|
||||
public void game(){
|
||||
showGame();
|
||||
while(nbError<6 && !winCondition()){
|
||||
char letter = enter_word.getLetter();
|
||||
this.curentLetter.setLetter(letter);
|
||||
@@ -107,9 +159,10 @@ public class main {
|
||||
showGame();
|
||||
}
|
||||
if (winCondition()){
|
||||
// tu gagnes
|
||||
System.out.println("victoir (celui qui a écris a 5 de QI)");
|
||||
}
|
||||
else{
|
||||
else{ //tu perds
|
||||
System.out.println("ta perdu sale étron");
|
||||
System.out.println(" le bon mot était : " + this.word);
|
||||
}
|
||||
|
||||
Binary file not shown.
+23
-13
@@ -1,18 +1,28 @@
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class word_search {
|
||||
|
||||
// Liste des mots
|
||||
private static String[] WORDS = {
|
||||
"singe", "google", "frapper", "haine", "dio", "java",
|
||||
"felix vimalaratnam", "lebreton", "argent", "pauvre", "grocaillou"
|
||||
};
|
||||
|
||||
/**
|
||||
* Retourne un mot aléatoire du tableau WORDS
|
||||
*/
|
||||
public static String getRandomWord() {
|
||||
List<String> words = new ArrayList<>(); // Liste dynamique de mots
|
||||
Random random = new Random();
|
||||
return WORDS[random.nextInt(WORDS.length)];
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user