This commit is contained in:
2025-10-08 12:28:34 +02:00
parent 86537ff528
commit c14e481572
9 changed files with 40 additions and 85 deletions

View File

@@ -3,25 +3,16 @@ import java.util.*;
public class ChooseWord {
/* Fonction pour choisir un mot selon la difficulté */
public static String chooseTheWordByDifficulty(String difficulty) {
/*Fonction pour choisir le mot aléatoirement*/
public static String chooseTheWord() {
List<String> words = new ArrayList<>();
String difficultyDictio = "motsFacile.txt"; // par défaut
if (difficulty.equals("easy")) {
difficultyDictio = "motsFacile.txt";
} else if (difficulty.equals("medium")) {
difficultyDictio = "motsMoyen.txt";
} else if (difficulty.equals("hard")) {
difficultyDictio = "motsDifficiles.txt";
}
try (BufferedReader reader = new BufferedReader(new FileReader(difficultyDictio))) {
try (BufferedReader reader = new BufferedReader(new FileReader("motsFacile.txt"))) {
String line;
while ((line = reader.readLine()) != null) {
String word = line.trim().toLowerCase();
if (word.isEmpty()) continue;
words.add(word);
if (!line.trim().isEmpty()) {
words.add(line.trim().toLowerCase());
}
}
} catch (IOException e) {
e.printStackTrace();
@@ -32,14 +23,6 @@ public class ChooseWord {
}
Random rand = new Random();
if (difficulty.equals("hard")) {
// Pour "hard", on peut choisir deux mots concaténés
String first = words.get(rand.nextInt(words.size()));
String second = words.get(rand.nextInt(words.size()));
return first + " " + second;
} else {
return words.get(rand.nextInt(words.size()));
}
return words.get(rand.nextInt(words.size()));
}
}