This commit is contained in:
2025-10-08 15:33:06 +02:00
parent 9058650339
commit 3547ccfc10
18 changed files with 1175 additions and 248 deletions

View File

@@ -1,33 +1,40 @@
import java.util.Scanner;
import java.util.Random;
import java.util.HashSet;
import java.util.Set;
import java.io.*;
import java.util.*;
public class WordSelector {
private static final String[] WORDS = {
"java", "python", "programmation", "ordinateur", "clavier",
"souris", "ecran", "internet", "logiciel", "algorithme",
"maison", "jardin", "livre", "table", "chaise", "porte",
"fenetre", "lampe", "bureau", "stylo", "crayon", "papier",
"fleur", "arbre", "oiseau", "chat", "chien", "poisson",
"soleil", "lune", "etoile", "ciel", "nuage", "pluie",
"vent", "neige", "terre", "eau", "feu", "air", "pierre",
"sable", "route", "ville", "rue", "voiture", "velo",
"train", "avion", "bateau", "musique", "chanson", "danse",
"peinture", "couleur", "forme", "image", "photo", "film",
"histoire", "conte", "reve", "idee", "pensee", "mot",
"phrase", "texte", "histoire", "nombre", "chiffre",
"calcul", "probleme", "solution", "question", "reponse",
"temps", "heure", "minute", "seconde", "jour", "nuit",
"matin", "soir", "semaine", "mois", "annee", "saison",
"printemps", "ete", "automne", "hiver", "famille", "ami",
"frere", "soeur", "parent", "enfant", "ecole", "classe",
"cours", "lecon", "devoir", "travail", "repos", "jeu"
};
public static String pickRandomWord(){
Random random = new Random();
return WORDS[random.nextInt(WORDS.length)];
private static final Map<String, List<String>> 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<String> 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<String> words = wordsByDifficulty.get(difficulty.toLowerCase());
if (words == null || words.isEmpty()) {
return "default";
}
Random rand = new Random();
return words.get(rand.nextInt(words.size()));
}
}