Files
TD3_DEV51_brigitte_aissi/PenduWIlfried/ChooseWord.java
2025-10-08 12:28:34 +02:00

29 lines
766 B
Java

import java.io.*;
import java.util.*;
public class ChooseWord {
/*Fonction pour choisir le mot aléatoirement*/
public static String chooseTheWord() {
List<String> words = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader("motsFacile.txt"))) {
String line;
while ((line = reader.readLine()) != null) {
if (!line.trim().isEmpty()) {
words.add(line.trim().toLowerCase());
}
}
} catch (IOException e) {
e.printStackTrace();
}
if (words.isEmpty()) {
return "default";
}
Random rand = new Random();
return words.get(rand.nextInt(words.size()));
}
}