forked from menault/TD3_DEV51_Qualite_Algo
		
	?
This commit is contained in:
		| @@ -1,85 +0,0 @@ | ||||
| package back; | ||||
|  | ||||
| import java.io.IOException; | ||||
| import java.nio.charset.StandardCharsets; | ||||
| import java.nio.file.Files; | ||||
| import java.nio.file.Path; | ||||
| import java.nio.file.Paths; | ||||
| import java.security.SecureRandom; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import java.util.stream.Stream; | ||||
|  | ||||
| /** | ||||
|  * Fournit les mots pour le jeu. | ||||
|  * - Lit d'abord "bibliothèque/mots.txt" (UTF-8), 1 mot par ligne. | ||||
|  * - Ignore les lignes vides et celles qui commencent par '#'. | ||||
|  * - Si le fichier est introuvable ou vide, bascule sur une liste par défaut. | ||||
|  */ | ||||
| public class Words { | ||||
|  | ||||
|     /** Chemin du fichier de mots (relatif à la racine du projet). */ | ||||
|     private static final Path WORDS_PATH = Paths.get("Bibliotheque", "mots.txt"); | ||||
|  | ||||
|     /** Liste de secours si le fichier n'est pas disponible. */ | ||||
|     private static final List<String> DEFAULT = List.of( | ||||
|         "algorithm", "variable", "function", "interface", "inheritance", | ||||
|         "exception", "compiler", "database", "network", "architecture", | ||||
|         "iteration", "recursion", "encryption", "framework", "protocol" | ||||
|     ); | ||||
|  | ||||
|     /** RNG partagé et cache des mots chargés. */ | ||||
|     private static final SecureRandom RNG = new SecureRandom(); | ||||
|     private static volatile List<String> CACHE = null; | ||||
|  | ||||
|     /** | ||||
|      * Retourne un mot choisi au hasard depuis le fichier ou la liste par défaut. | ||||
|      * Déclenche un chargement paresseux (lazy-load) si nécessaire. | ||||
|      */ | ||||
|     public static String random() { | ||||
|         ensureLoaded(); | ||||
|         return CACHE.get(RNG.nextInt(CACHE.size())); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Recharge les mots depuis le fichier. Utile si modification de mots.txt à chaud. | ||||
|      */ | ||||
|     public static synchronized void reload() { | ||||
|         CACHE = loadFromFileOrDefault(); | ||||
|     } | ||||
|  | ||||
|     /** Garantit que le cache est initialisé. */ | ||||
|     private static void ensureLoaded() { | ||||
|         if (CACHE == null) { | ||||
|             synchronized (Words.class) { | ||||
|                 if (CACHE == null) { | ||||
|                     CACHE = loadFromFileOrDefault(); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** Tente de charger depuis le fichier, sinon renvoie la liste par défaut. */ | ||||
|     private static List<String> loadFromFileOrDefault() { | ||||
|         List<String> fromFile = readUtf8Lines(WORDS_PATH); | ||||
|         if (fromFile.isEmpty()) return DEFAULT; | ||||
|         return fromFile; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Lit toutes les lignes UTF-8 depuis le chemin fourni, | ||||
|      * en filtrant vides et commentaires (# ...). | ||||
|      */ | ||||
|     private static List<String> readUtf8Lines(Path path) { | ||||
|         List<String> result = new ArrayList<>(); | ||||
|         try (Stream<String> lines = Files.lines(path, StandardCharsets.UTF_8)) { | ||||
|             lines.map(String::trim) | ||||
|                  .filter(s -> !s.isEmpty()) | ||||
|                  .filter(s -> !s.startsWith("#")) | ||||
|                  .forEach(result::add); | ||||
|         } catch (IOException e) { | ||||
|             // Silencieux : on basculera sur DEFAULT | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
| } | ||||
| @@ -1,26 +0,0 @@ | ||||
| - **bibliothèque/mots.txt** → liste des mots à deviner (1 par ligne)   | ||||
| - **assets/images/** → images du pendu (de 0.png à 6.png)   | ||||
|  | ||||
| --- | ||||
|  | ||||
| ## Fonctionnalités | ||||
|   | ||||
| Affichage d’une **image différente du pendu** à chaque erreur   | ||||
| Lecture de mots depuis un **fichier externe** (`bibliothèque/mots.txt`)   | ||||
| Validation des entrées (une seule LETTRE à la fois)   | ||||
| Bouton **“Nouvelle partie”** pour rejouer sans relancer le programme   | ||||
| Messages de victoire / défaite | ||||
|  | ||||
| --- | ||||
|  | ||||
| ## Compilation et exécution | ||||
|  | ||||
| ### Compilation | ||||
| ```javac -d out $(find -name "*.java")``` | ||||
|  | ||||
| ### Exécution | ||||
| ```java -cp out main.Main``` | ||||
|  | ||||
| --- | ||||
|  | ||||
| Mini projet effectuer par Clément JANNAIRE et Clémence DUCREUX. | ||||
							
								
								
									
										
											BIN
										
									
								
								out/back/Check.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								out/back/Check.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								out/back/Game.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								out/back/Game.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								out/back/Result.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								out/back/Result.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								out/back/Words.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								out/back/Words.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								out/front/Gallows$BufferedImage.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								out/front/Gallows$BufferedImage.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								out/front/Gallows.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								out/front/Gallows.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								out/front/GameUI$1.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								out/front/GameUI$1.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								out/front/GameUI.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								out/front/GameUI.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								out/main/Main.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								out/main/Main.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user