forked from menault/TD3_DEV51_Qualite_Algo
tkt
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user