import java.io.*; import java.util.*; public class WordSelector { private static final Map> wordsByDifficulty = new HashMap<>(); /** * Charge la liste de mots pour une difficulté donnée depuis un fichier. */ public static void loadWordsForDifficulty(String difficulty, String filename) { List words = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(new FileReader(filename))) { String line; while ((line = reader.readLine()) != null) { String word = line.trim().toLowerCase(); if (!word.isEmpty()) { words.add(word); } } } catch (IOException e) { System.err.println("Error loading words from " + filename); e.printStackTrace(); } wordsByDifficulty.put(difficulty.toLowerCase(), words); } /** * Retourne un mot aléatoire selon la difficulté ("easy", "medium", "hard"). * Retourne "default" si aucun mot trouvé. */ public static String pickWord(String difficulty) { List words = wordsByDifficulty.get(difficulty.toLowerCase()); if (words == null || words.isEmpty()) { return "default"; } Random rand = new Random(); return words.get(rand.nextInt(words.size())); } }