7 Commits

Author SHA1 Message Date
c70c2b73ad fix 2025-10-08 16:34:45 +02:00
d4d8249c8b Vérif fait 2025-10-08 16:26:47 +02:00
94e7394494 add: Difficulty Mode 2025-10-08 16:11:40 +02:00
111dcad559 Merge branch 'Hochlaf-Vue' 2025-10-08 13:32:11 +02:00
dbeed240d1 Merge remote-tracking branch 'origin/master' 2025-10-08 13:31:24 +02:00
bc4aa06445 Merge pull request 'Add: Controllers' 2025-10-08 12:16:25 +02:00
d05f9594d8 Add: Controllers 2025-10-08 12:12:57 +02:00
3 changed files with 93 additions and 5 deletions

View File

@@ -0,0 +1,80 @@
package fr.iutfbleau.TD3_DEV51_Qualite_Algo.Controllers;
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models.Difficulty;
import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models.Word;
import java.util.*;
public class Game {
private Word word;
private int errors;
private List<Word> allwords;
private Difficulty difficulty;
private final int maxErrors = 6;
/* Hangmam Game */
public Game(Word word ,List<Word> allWord) {
this.word = word;
this.errors = 0;
switch (difficulty) {
case EASY:
this.word = selectWord(allWord, 0 , 7 );
break;
case MEDIUM:
this.word = selectWord(allWord, 0, Integer.MAX_VALUE);
break;
case HARD:
this.allwords = selectTwoWords(allWord);
break;
}
}
/* Selected Word with conditions */
private Word selectWord(List<Word> list, int min, int max) {
for (Word word : list) {
int length = word.getWord().length();
if (length >= min && length <= max) {
return word;
}
}
return list.getFirst();
}
/* Selected word level Difficult */
private List<Word> selectTwoWords(List<Word> list) {
return list.subList(0, Math.min(2, list.size()));
}
public boolean playLetter(char caractere) {
boolean correct;
if(difficulty == Difficulty.HARD){
correct = this.allwords.get(0).VerifyLetter(caractere) || this.allwords.get(1).VerifyLetter(caractere);
} else{
correct = word.VerifyLetter(caractere);
}
if (!correct) errors++;
return correct;
}
/* Verify error number */
public int getErrors() {
return this.errors;
}
/* Put error max */
public int getMaxErrors() {
return this.maxErrors;
}
/* All letter is completed : Won */
public boolean isWon() {
return word.IsComplete();
}
/* Lost if maxErrors is greater than or egal to errors */
public boolean isLost() {
return errors >= maxErrors;
}
}

View File

@@ -0,0 +1,5 @@
package fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models;
public enum Difficulty {
EASY, MEDIUM, HARD
}

View File

@@ -4,8 +4,8 @@ import java.util.*;
public class Word { public class Word {
private final String word; private final String word;
private Letter[] tabLetter; private Letter[] tabLetter;
private String c; private String character;
private Word(String word){ private Word(String word){
this.word = word; this.word = word;
@@ -14,11 +14,11 @@ public class Word {
} }
} }
/* Lettre dans le mot */ /* Lettre dans le mot */
private boolean VerifyLetter(char c){ public boolean VerifyLetter(char character){
boolean return_bool = false; boolean return_bool = false;
for(Letter letter : this.tabLetter){ for(Letter letter : this.tabLetter){
if(!letter.getStatus()){ if(!letter.getStatus()){
if(letter.isGood(c)){ if(letter.isGood(character)){
return_bool = true; return_bool = true;
} }
} }
@@ -27,7 +27,7 @@ public class Word {
} }
/* Le mot a été deviné */ /* Le mot a été deviné */
private boolean IsComplet(){ public boolean IsComplete(){
for(Letter letter : this.tabLetter){ for(Letter letter : this.tabLetter){
if(!letter.getStatus()){ if(!letter.getStatus()){
return false; return false;
@@ -36,5 +36,8 @@ public class Word {
} }
return true; return true;
} }
public String getWord() {
return word;
}
} }