diff --git a/Makefile b/Makefile
index 6301970..8833e5c 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@ CLASSFILES = Pendu.class \
$(OUT)Pendu.class : $(IN)Pendu.java $(OUT)Partie.class $(OUT)Fenetre.class
$(JC) $(JCFLAGS) $<
-$(OUT)Partie.class : $(IN)Partie.java
+$(OUT)Partie.class : $(IN)Partie.java $(OUT)Mots.class
$(JC) $(JCFLAGS) $<
$(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
$(JC) $(JCFLAGS) $<
+$(OUT)Mots.class : $(IN)Mots.java
+ $(JC) $(JCFLAGS) $<
+
# Commandes
Pendu : $(OUT)Pendu.class
diff --git a/src/Mots.java b/src/Mots.java
new file mode 100644
index 0000000..233e9fc
--- /dev/null
+++ b/src/Mots.java
@@ -0,0 +1,58 @@
+
+/**
+* La classe Mots
+*
+* @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 "" ;
+ }
+}
diff --git a/src/Partie.java b/src/Partie.java
index 05dbde9..f6421b5 100644
--- a/src/Partie.java
+++ b/src/Partie.java
@@ -1,3 +1,5 @@
+import java.util.Random;
+
/**
* La classe Partie
*
@@ -8,7 +10,7 @@
*/
public class Partie {
//Contantes
- private static final byte REMAININGTRY = 6 ;
+ private static final byte REMAININGTRY = 11 ;
private static final byte CARACTERCODESHIFT = 65 ; //Décalage ASCI > 'A'
//Attributs
@@ -24,23 +26,25 @@ public class Partie {
this.wordsize = (byte) secretword.length ;
this.foundletters = new boolean[wordsize] ;
}
-
- // Getters
- public char[] getSecretWord() { 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();
+ //Méthodes
+ public char[] getSecretWord() {
+ return this.secretword ;
}
- /** 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() {
if(this.remainingtry <= 0){
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
- * entriesletters / foundletters / remainingtry.
- * @return true si la lettre était déjà présente (doublon).
+ * Vérifie si la lettre reçu n'a pas déjà été joué puis, met à jour le tableau "entriesletters" et
+ * "foundletters" le cas échéant.
+ *
+ * @return true si la lettre était déjà présente.
*/
public boolean isAlreadyEntries(char letter) {
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() {
- char[] word = {'P','I','Z','Z','A'};
- //À implémenter plus tard
+ Random random = new Random();
+ byte grain = (byte) random.nextInt(Mots.dictionarysize);
+ char[] word = Mots.dictionary[grain].toUpperCase().toCharArray();
return word ;
}
private boolean wordIsFound() {
- for(byte i = 0 ; i < this.wordsize ; i++){
- if(!this.foundletters[i]){ //Si une lettre n'est pas trouvée
+ for(byte i = 0 ; i < this.wordsize ; i++){ //Parcours du "secretword"
+ if(!this.foundletters[i]){ //Si une lettre n'est pas trouvé
return false ;
}
}
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());
+ }
}
+