forked from menault/TD3_DEV51_Qualite_Algo
Compare commits
3 Commits
2f3a6df740
...
Dificulty_
Author | SHA1 | Date | |
---|---|---|---|
c70c2b73ad | |||
d4d8249c8b | |||
94e7394494 |
@@ -1,15 +1,62 @@
|
||||
package Controllers;
|
||||
package fr.iutfbleau.TD3_DEV51_Qualite_Algo.Controllers;
|
||||
|
||||
import Models.Word;
|
||||
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;
|
||||
|
||||
public Game(Word word) {
|
||||
/* 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 */
|
||||
@@ -21,17 +68,6 @@ public class Game {
|
||||
return this.maxErrors;
|
||||
}
|
||||
|
||||
/* Vue call method VerifyLetter, check status letter false/True */
|
||||
public boolean playLetter(char c) {
|
||||
boolean correct = word.VerifyLetter(c);
|
||||
|
||||
if (!correct) {
|
||||
errors++;
|
||||
}
|
||||
|
||||
return correct;
|
||||
}
|
||||
|
||||
/* All letter is completed : Won */
|
||||
public boolean isWon() {
|
||||
return word.IsComplete();
|
||||
@@ -40,5 +76,5 @@ public class Game {
|
||||
/* Lost if maxErrors is greater than or egal to errors */
|
||||
public boolean isLost() {
|
||||
return errors >= maxErrors;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,5 @@
|
||||
package fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models;
|
||||
|
||||
public enum Difficulty {
|
||||
EASY, MEDIUM, HARD
|
||||
}
|
@@ -4,8 +4,8 @@ import java.util.*;
|
||||
|
||||
public class Word {
|
||||
private final String word;
|
||||
private Letter[] tabLetter;
|
||||
private String c;
|
||||
private Letter[] tabLetter;
|
||||
private String character;
|
||||
|
||||
private Word(String word){
|
||||
this.word = word;
|
||||
@@ -14,11 +14,11 @@ public class Word {
|
||||
}
|
||||
}
|
||||
/* Lettre dans le mot */
|
||||
private boolean VerifyLetter(char c){
|
||||
public boolean VerifyLetter(char character){
|
||||
boolean return_bool = false;
|
||||
for(Letter letter : this.tabLetter){
|
||||
if(!letter.getStatus()){
|
||||
if(letter.isGood(c)){
|
||||
if(letter.isGood(character)){
|
||||
return_bool = true;
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public class Word {
|
||||
}
|
||||
|
||||
/* Le mot a été deviné */
|
||||
private boolean IsComplet(){
|
||||
public boolean IsComplete(){
|
||||
for(Letter letter : this.tabLetter){
|
||||
if(!letter.getStatus()){
|
||||
return false;
|
||||
@@ -36,5 +36,8 @@ public class Word {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public String getWord() {
|
||||
return word;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user