forked from menault/TD3_DEV51_Qualite_Algo
Compare commits
2 Commits
3_Marvin_P
...
1_Marvin_r
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d7c8bc909 | |||
| 81b821484f |
BIN
Letter.class
BIN
Letter.class
Binary file not shown.
50
Letter.java
50
Letter.java
@@ -1,50 +0,0 @@
|
||||
import java.util.*;
|
||||
|
||||
public class Letter {
|
||||
public String wordToFind;
|
||||
public char selectedLetter;
|
||||
public StringBuilder wordBuilding;
|
||||
public StringBuilder incorrectLetters = new StringBuilder();
|
||||
|
||||
// Constructeur
|
||||
public Letter(String mot) {
|
||||
this.wordToFind = mot;
|
||||
this.wordBuilding = new StringBuilder();
|
||||
// Initialise le mot caché avec des underscores
|
||||
for (int i = 0; i < mot.length(); i++) {
|
||||
if (mot.charAt(i) == ' ') {
|
||||
this.wordBuilding.append(' '); // garde les espaces
|
||||
} else {
|
||||
this.wordBuilding.append('_');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setter pour la lettre sélectionnée
|
||||
public void setLetter(char currentLetter) {
|
||||
this.selectedLetter = currentLetter;
|
||||
}
|
||||
|
||||
// Vérifie si la lettre est dans le mot
|
||||
public boolean letterInWord() {
|
||||
boolean found = false;
|
||||
|
||||
for (int i = 0; i < this.wordToFind.length(); i++) {
|
||||
if (this.selectedLetter == this.wordToFind.charAt(i)) {
|
||||
// Remplace l'underscore par la lettre correcte
|
||||
this.wordBuilding.setCharAt(i, this.selectedLetter);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Si la lettre n'est pas trouvée, on l'ajoute aux incorrectes
|
||||
if (!found) {
|
||||
if (this.incorrectLetters.length() > 0) {
|
||||
this.incorrectLetters.append(" ");
|
||||
}
|
||||
this.incorrectLetters.append(this.selectedLetter);
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
}
|
||||
BIN
TD3 - DEV5.1.pdf
Normal file
BIN
TD3 - DEV5.1.pdf
Normal file
Binary file not shown.
BIN
enter_word.class
BIN
enter_word.class
Binary file not shown.
@@ -1,22 +0,0 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class enter_word {
|
||||
|
||||
public static char getLetter() {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
char letter = ' ';
|
||||
|
||||
while (true) {
|
||||
System.out.print("Mets UNE (genre 1) lettre frero: ");
|
||||
String input = scanner.nextLine().toLowerCase();
|
||||
if (input.length() == 1 && Character.isLetter(input.charAt(0))) {
|
||||
letter = input.charAt(0);
|
||||
break;
|
||||
} else {
|
||||
System.out.println("Frero ? 1 lettre, comment tu as pu rater ça , Quel singe");
|
||||
}
|
||||
}
|
||||
|
||||
return letter;
|
||||
}
|
||||
}
|
||||
22743
francais.txt
22743
francais.txt
File diff suppressed because it is too large
Load Diff
BIN
main.class
BIN
main.class
Binary file not shown.
126
main.java
126
main.java
@@ -1,126 +0,0 @@
|
||||
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 d’erreurs
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1,28 +1,19 @@
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class word_search {
|
||||
public static String getRandomWord() {
|
||||
List<String> words = new ArrayList<>(); // Liste dynamique de mots
|
||||
//Liste des mots
|
||||
private static String[] WORDS = {
|
||||
"Singe", "Google", "Frapper", "Haine", "Dio", "Java",
|
||||
"Felix Vimalaratnam", "Lebreton", "Argent", "Pauvre", "Grocaillou"
|
||||
};
|
||||
|
||||
public static void main(String[] args) {
|
||||
//Permet de random
|
||||
Random random = new Random();
|
||||
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";
|
||||
}
|
||||
//Prends le mot aléatoirement
|
||||
String randomword = WORDS[random.nextInt(WORDS.length)];
|
||||
// Affiche l'mot
|
||||
System.out.println("Mot qu'on prend d'facon random : " + randomword);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user