forked from menault/TD3_DEV51_Qualite_Algo
Merge issue
This commit is contained in:
5
Makefile
5
Makefile
@@ -21,7 +21,7 @@ CLASSFILES = Pendu.class \
|
|||||||
$(OUT)Pendu.class : $(IN)Pendu.java $(OUT)Partie.class $(OUT)Fenetre.class
|
$(OUT)Pendu.class : $(IN)Pendu.java $(OUT)Partie.class $(OUT)Fenetre.class
|
||||||
$(JC) $(JCFLAGS) $<
|
$(JC) $(JCFLAGS) $<
|
||||||
|
|
||||||
$(OUT)Partie.class : $(IN)Partie.java
|
$(OUT)Partie.class : $(IN)Partie.java $(OUT)Mots.class
|
||||||
$(JC) $(JCFLAGS) $<
|
$(JC) $(JCFLAGS) $<
|
||||||
|
|
||||||
$(OUT)Fenetre.class : $(IN)Fenetre.java $(OUT)Partie.class $(OUT)Dessin.class
|
$(OUT)Fenetre.class : $(IN)Fenetre.java $(OUT)Partie.class $(OUT)Dessin.class
|
||||||
@@ -30,6 +30,9 @@ $(OUT)Fenetre.class : $(IN)Fenetre.java $(OUT)Partie.class $(OUT)Dessin.class
|
|||||||
$(OUT)Dessin.class : $(IN)Dessin.java
|
$(OUT)Dessin.class : $(IN)Dessin.java
|
||||||
$(JC) $(JCFLAGS) $<
|
$(JC) $(JCFLAGS) $<
|
||||||
|
|
||||||
|
$(OUT)Mots.class : $(IN)Mots.java
|
||||||
|
$(JC) $(JCFLAGS) $<
|
||||||
|
|
||||||
# Commandes
|
# Commandes
|
||||||
Pendu : $(OUT)Pendu.class
|
Pendu : $(OUT)Pendu.class
|
||||||
|
|
||||||
|
|||||||
58
src/Mots.java
Normal file
58
src/Mots.java
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* La classe <code>Mots</code>
|
||||||
|
*
|
||||||
|
* @version 1.0
|
||||||
|
* @author Aurélien
|
||||||
|
* Date : 08-10-25
|
||||||
|
* Licence :
|
||||||
|
*/
|
||||||
|
public final class Mots {
|
||||||
|
//Attributs
|
||||||
|
public static final short dictionarysize = 32 ;
|
||||||
|
public static final String[] dictionary = {
|
||||||
|
"Magnifique",
|
||||||
|
"Etoile",
|
||||||
|
"Voyage",
|
||||||
|
"Biscuit",
|
||||||
|
"Refrigerateur",
|
||||||
|
"Courage",
|
||||||
|
"Avion",
|
||||||
|
"Explorateur",
|
||||||
|
"Montagne",
|
||||||
|
"Philosophie",
|
||||||
|
"Lumiere",
|
||||||
|
"Ethernet",
|
||||||
|
"Architecture",
|
||||||
|
"Ocean",
|
||||||
|
"Liberte",
|
||||||
|
"Aventure",
|
||||||
|
"Cerise",
|
||||||
|
"Harmonieux",
|
||||||
|
"Informatique",
|
||||||
|
"Pluie",
|
||||||
|
"Equilibriste",
|
||||||
|
"Papillon",
|
||||||
|
"Saisons",
|
||||||
|
"Liberte",
|
||||||
|
"Alphabet",
|
||||||
|
"Musique",
|
||||||
|
"Translucent",
|
||||||
|
"Passion",
|
||||||
|
"Etreindre",
|
||||||
|
"Poetique",
|
||||||
|
"Serenite",
|
||||||
|
"Révolution"
|
||||||
|
};
|
||||||
|
|
||||||
|
//Constructeur
|
||||||
|
private Mots() { //N'a pas pour but d'être instanciée
|
||||||
|
throw new UnsupportedOperationException("The \"Fichier\" class cannot be instanced !");
|
||||||
|
}
|
||||||
|
//Méthodes
|
||||||
|
|
||||||
|
//Affichage
|
||||||
|
public String toString() {
|
||||||
|
return "" ;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* La classe <code>Partie</code>
|
* La classe <code>Partie</code>
|
||||||
*
|
*
|
||||||
@@ -8,7 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
public class Partie {
|
public class Partie {
|
||||||
//Contantes
|
//Contantes
|
||||||
private static final byte REMAININGTRY = 6 ;
|
private static final byte REMAININGTRY = 11 ;
|
||||||
private static final byte CARACTERCODESHIFT = 65 ; //Décalage ASCI > 'A'
|
private static final byte CARACTERCODESHIFT = 65 ; //Décalage ASCI > 'A'
|
||||||
|
|
||||||
//Attributs
|
//Attributs
|
||||||
@@ -24,23 +26,25 @@ public class Partie {
|
|||||||
this.wordsize = (byte) secretword.length ;
|
this.wordsize = (byte) secretword.length ;
|
||||||
this.foundletters = new boolean[wordsize] ;
|
this.foundletters = new boolean[wordsize] ;
|
||||||
}
|
}
|
||||||
|
//Méthodes
|
||||||
// Getters
|
public char[] getSecretWord() {
|
||||||
public char[] getSecretWord() { return this.secretword ; }
|
return this.secretword ;
|
||||||
public boolean[] getFoundLetters() { return this.foundletters ; }
|
|
||||||
public byte getRemainingTry() { return this.remainingtry ; }
|
|
||||||
|
|
||||||
/** Représentation masquée du mot, ex: "_ _ A _ _" */
|
|
||||||
public String getMaskedWord() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (int i = 0; i < secretword.length; i++) {
|
|
||||||
sb.append(foundletters[i] ? secretword[i] : '_');
|
|
||||||
if (i < secretword.length - 1) sb.append(' ');
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Vérifie l'état de la partie en cours. */
|
public boolean[] getFoundLetters() {
|
||||||
|
return this.foundletters ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte getRemainingTry() {
|
||||||
|
return this.remainingtry ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vérifie l'état de la partie en cours.
|
||||||
|
*
|
||||||
|
* @return true si le jeu est fini.
|
||||||
|
*/
|
||||||
public boolean gameIsEnding() {
|
public boolean gameIsEnding() {
|
||||||
if(this.remainingtry <= 0){
|
if(this.remainingtry <= 0){
|
||||||
return true ;
|
return true ;
|
||||||
@@ -52,9 +56,10 @@ public class Partie {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérifie si la lettre reçue a déjà été jouée puis met à jour
|
* Vérifie si la lettre reçu n'a pas déjà été joué puis, met à jour le tableau "entriesletters" et
|
||||||
* entriesletters / foundletters / remainingtry.
|
* "foundletters" le cas échéant.
|
||||||
* @return true si la lettre était déjà présente (doublon).
|
*
|
||||||
|
* @return true si la lettre était déjà présente.
|
||||||
*/
|
*/
|
||||||
public boolean isAlreadyEntries(char letter) {
|
public boolean isAlreadyEntries(char letter) {
|
||||||
short caractercode = (short) letter ; //Récupération du code du caractère
|
short caractercode = (short) letter ; //Récupération du code du caractère
|
||||||
@@ -77,21 +82,55 @@ public class Partie {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Génère un mot à partir d'un grand dictionnaire (enfin en principe).
|
||||||
|
*
|
||||||
|
* @return le mot généré.
|
||||||
|
*/
|
||||||
private char[] generateSecretWord() {
|
private char[] generateSecretWord() {
|
||||||
char[] word = {'P','I','Z','Z','A'};
|
Random random = new Random();
|
||||||
//À implémenter plus tard
|
byte grain = (byte) random.nextInt(Mots.dictionarysize);
|
||||||
|
char[] word = Mots.dictionary[grain].toUpperCase().toCharArray();
|
||||||
return word ;
|
return word ;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean wordIsFound() {
|
private boolean wordIsFound() {
|
||||||
for(byte i = 0 ; i < this.wordsize ; i++){
|
for(byte i = 0 ; i < this.wordsize ; i++){ //Parcours du "secretword"
|
||||||
if(!this.foundletters[i]){ //Si une lettre n'est pas trouvée
|
if(!this.foundletters[i]){ //Si une lettre n'est pas trouvé
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() { return "" ; }
|
//Affichage
|
||||||
|
public String toString() {
|
||||||
|
return "" ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Tests
|
||||||
|
public static void main(String[] args){
|
||||||
|
char[] test = {'E','O','M','I','E','D','A','Z','N','L','C','R','P','H','T','S'};
|
||||||
|
byte size = (byte) test.length ;
|
||||||
|
boolean status ;
|
||||||
|
|
||||||
|
Partie game = new Partie();
|
||||||
|
System.out.println("Trick > " + String.valueOf(game.secretword) + "\n");
|
||||||
|
for(byte i = 0 ; i < size && !game.gameIsEnding() ; i++){
|
||||||
|
System.out.println("Essais restants : " + game.getRemainingTry());
|
||||||
|
status = game.isAlreadyEntries(test[i]);
|
||||||
|
for(byte l = 0 ; l < game.wordsize ; l++){ //Parcours du "secretword"
|
||||||
|
if(game.foundletters[l] == true){
|
||||||
|
System.out.print(game.getSecretWord()[l] + " ");
|
||||||
|
}else{
|
||||||
|
System.out.print("_ ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(""); //Lisibilité
|
||||||
|
//System.out.println("Lettres : " + game.entriesletters);
|
||||||
|
}
|
||||||
|
System.out.println("Essais restants : " + game.getRemainingTry());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user