6 Commits

7 changed files with 22949 additions and 14 deletions

Binary file not shown.

22743
francais.txt Normal file

File diff suppressed because it is too large Load Diff

178
main a push sur le merge Normal file
View File

@@ -0,0 +1,178 @@
import java.util.Scanner;
public class main {
public String word = word_search.getRandomWord();
public Letter curentLetter = new Letter(word);
public int nbError=0;
public boolean winCondition=false;
//creer wincondtion (je lis le mot en construction (wordbuilding), compare avec word, si égal c'est gagné)
public boolean winCondition(){
if(curentLetter.wordBuilding.toString().equals(word)){
return true;
}else{
return false;
}
}
public static void displayHangman(int mistakes) {
String[] hangman = new String[7]; // 7 étapes du pendu
// Étape 0 : début du jeu
hangman[0] =
"------\n" +
"| |\n" +
" |\n" +
" |\n" +
" |\n" +
" |\n" +
"=========\n";
// Étape 1 : tête
hangman[1] =
"------\n" +
"| |\n" +
"O |\n" +
" |\n" +
" |\n" +
" |\n" +
"=========\n";
// Étape 2 : tronc
hangman[2] =
"------\n" +
"| |\n" +
"O |\n" +
"| |\n" +
" |\n" +
" |\n" +
"=========\n";
// Étape 3 : un bras
hangman[3] =
"------\n" +
"| |\n" +
"O |\n" +
"/| |\n" +
" |\n" +
" |\n" +
"=========\n";
// Étape 4 : deux bras
hangman[4] =
"------\n" +
"| |\n" +
"O |\n" +
"/|\\ |\n" +
" |\n" +
" |\n" +
"=========\n";
// Étape 5 : une jambe
hangman[5] =
"------\n" +
"| |\n" +
"O |\n" +
"/|\\ |\n" +
"/ |\n" +
" |\n" +
"=========\n";
// Étape 6 : pendu complet (défaite)
hangman[6] =
"------\n" +
"| |\n" +
"O |\n" +
"/|\\ |\n" +
"/ \\ |\n" +
" |\n" +
"=========\n";
// Affiche le pendu correspondant au nombre derreurs
System.out.println(hangman[mistakes]);
}
//Element toujours présent
public void showGame(){
System.out.println("lettre fausse : " + this.curentLetter.incorrectLetters);
displayHangman(nbError);
System.out.println("mot a trouver " + this.curentLetter.wordBuilding);
}
//Permet au jeu de fonctionner et de se terminer
public void game(){
while(nbError<6 && !winCondition()){
char letter = enter_word.getLetter();
this.curentLetter.setLetter(letter);
if (!this.curentLetter.letterInWord()){
nbError++;
}
showGame();
}
if (winCondition()){
// tu gagnes
System.out.println("victoir (celui qui a écris a 5 de QI)");
}
else{ //tu perds
System.out.println("ta perdu sale étron");
System.out.println(" le bon mot était : " + this.word);
}
}
public static void main(String[] args) {
main test =new main();
test.game();
}
}
//----------------------------------------------------------------------
import java.util.concurrent.*;
public class Compteur {
private int valeur = 0;
private ScheduledExecutorService scheduler;
// Démarre le compteur
public void start() {
if (scheduler != null && !scheduler.isShutdown()) {
return; // déjà lancé
}
scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(() -> {
valeur++;
System.out.println("temps : " + valeur);
}, 0, 1, TimeUnit.SECONDS);
}
public int getValeur(){
return valeur;
}
// Arrête le compteur
public void stop() {
if (scheduler != null) {
scheduler.shutdown();
System.out.println("Compteur arrêté.");
}
}
}

Binary file not shown.

View File

@@ -14,6 +14,7 @@ public class main {
return false;
}
}
public static void displayHangman(int mistakes) {
String[] hangman = new String[7]; // 7 étapes du pendu
@@ -91,12 +92,14 @@ public class main {
System.out.println(hangman[mistakes]);
}
//Element toujours présent
public void showGame(){
System.out.println("lettre fausse : " + this.curentLetter.incorrectLetters);
displayHangman(nbError);
System.out.println("mot a trouver " + this.curentLetter.wordBuilding);
}
//Permet au jeu de fonctionner et de se terminer
public void game(){
while(nbError<6 && !winCondition()){
char letter = enter_word.getLetter();
@@ -107,9 +110,10 @@ public class main {
showGame();
}
if (winCondition()){
// tu gagnes
System.out.println("victoir (celui qui a écris a 5 de QI)");
}
else{
else{ //tu perds
System.out.println("ta perdu sale étron");
System.out.println(" le bon mot était : " + this.word);
}

Binary file not shown.

View File

@@ -1,18 +1,28 @@
import java.util.Random;
import java.util.*;
import java.io.*;
public class word_search {
// Liste des mots
private static String[] WORDS = {
"singe", "google", "frapper", "haine", "dio", "java",
"felix vimalaratnam", "lebreton", "argent", "pauvre", "grocaillou"
};
/**
* Retourne un mot aléatoire du tableau WORDS
*/
public static String getRandomWord() {
List<String> words = new ArrayList<>(); // Liste dynamique de mots
Random random = new Random();
return WORDS[random.nextInt(WORDS.length)];
try { //lis le fichier, regarde si il existe avant de sélectionner un mot aléatoire
File file = new File("francais.txt");
Scanner scanner = new Scanner(file, "UTF-8");
while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim();
if (!line.isEmpty()) { // ignore les lignes vides
words.add(line.toLowerCase());
}
}
scanner.close();
if (words.isEmpty()) {
System.out.println(" Aucun mot trouvé dans le fichier français.txt !");
return "erreur";
}
return words.get(random.nextInt(words.size()));
} catch (FileNotFoundException e) {
System.out.println(" Fichier 'français.txt' introuvable !");
return "erreur";
}
}
}
}