forked from menault/TD3_DEV51_Qualite_Algo
Compare commits
2 Commits
05a85124e0
...
Controller
Author | SHA1 | Date | |
---|---|---|---|
d05f9594d8 | |||
905787e83d |
@@ -0,0 +1,44 @@
|
|||||||
|
package Controllers;
|
||||||
|
|
||||||
|
import Models.Word;
|
||||||
|
|
||||||
|
public class Game {
|
||||||
|
private Word word;
|
||||||
|
private int errors;
|
||||||
|
private final int maxErrors = 6;
|
||||||
|
|
||||||
|
public Game(Word word) {
|
||||||
|
this.word = word;
|
||||||
|
this.errors = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Verify error number */
|
||||||
|
public int getErrors() {
|
||||||
|
return this.errors;
|
||||||
|
}
|
||||||
|
/* Put error max */
|
||||||
|
public int getMaxErrors() {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lost if maxErrors is greater than or egal to errors */
|
||||||
|
public boolean isLost() {
|
||||||
|
return errors >= maxErrors;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,17 +1,7 @@
|
|||||||
package fr.iutfbleau.TD3_DEV51_Qualite_Algo;
|
package fr.iutfbleau.TD3_DEV51_Qualite_Algo;
|
||||||
|
|
||||||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
|
||||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
|
|
||||||
// to see how IntelliJ IDEA suggests fixing it.
|
|
||||||
System.out.printf("Hello and welcome!");
|
|
||||||
|
|
||||||
for (int i = 1; i <= 5; i++) {
|
|
||||||
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
|
|
||||||
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
|
|
||||||
System.out.println("i = " + i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,30 +1,20 @@
|
|||||||
|
public class Letter{
|
||||||
|
private char letter;
|
||||||
public class Lettre{
|
|
||||||
private char lettre;
|
|
||||||
private boolean status = false;
|
private boolean status = false;
|
||||||
|
|
||||||
public Lettre(char lettre){
|
public Letter(char letter){
|
||||||
this.lettre = lettre;
|
this.letter = letter;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/* Show status */
|
||||||
/* Status bool */
|
|
||||||
private boolean getStatus(){
|
private boolean getStatus(){
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
/* Verify status true, false */
|
||||||
|
|
||||||
private boolean isGood(char c){
|
private boolean isGood(char c){
|
||||||
if( this.lettre == c){
|
if( this.letter == c){
|
||||||
this.status = true;
|
this.status = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@@ -1,22 +0,0 @@
|
|||||||
import java.util.*;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class Mot {
|
|
||||||
public String mot;
|
|
||||||
public Lettre[] chaine;
|
|
||||||
|
|
||||||
|
|
||||||
public Mot(String mot){
|
|
||||||
this.mot = mot;
|
|
||||||
for(int i = 0; i< this.mot.length();i++){
|
|
||||||
this.chaine[i] = Lettre(this.mot.charAt(i))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@@ -0,0 +1,49 @@
|
|||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Word {
|
||||||
|
private String word;
|
||||||
|
private Letter[] tabLetter;
|
||||||
|
private String c;
|
||||||
|
|
||||||
|
private Word(String word){
|
||||||
|
this.word = word;
|
||||||
|
for(int i = 0; i< this.word.length();i++){
|
||||||
|
this.tabLetter[i] = Letter(this.word.charAt(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Lettre dans le mot */
|
||||||
|
private boolean VerifyLetter(String c){
|
||||||
|
boolean return_bool = false;
|
||||||
|
for(Letter letter in this.tabLetter){
|
||||||
|
if(!letter.getStatus()){
|
||||||
|
if(letter.isGood(c)){
|
||||||
|
return_bool = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return return_bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Le mot a été deviné */
|
||||||
|
private boolean IsComplet(){
|
||||||
|
if(Letter letter : this.tabLetter){
|
||||||
|
if(!letter.getStatus()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user