From 2a8eac072046053eabcc0c05695fc633098795e3 Mon Sep 17 00:00:00 2001 From: amary Date: Wed, 8 Oct 2025 16:07:03 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Gestion=20de=20partie=20(sans=20g=C3=A9n?= =?UTF-8?q?=C3=A9ration)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Console.java | 51 +++++++++++++++++++++ src/Partie.java | 113 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 src/Console.java diff --git a/src/Console.java b/src/Console.java new file mode 100644 index 0000000..1e5a6e4 --- /dev/null +++ b/src/Console.java @@ -0,0 +1,51 @@ +import java.io.*; +/* +Auteur : Aurélien Date : 25-03-24 Version : 1.0 Liscence : Usage Personnel + +Pour se servir de cette classe, il faut créer au préalable un objet unique qui nous +servira d'intermédiaire avec la console. +Ex : Console connect = new Console() ; +*/ +public class Console { + // attribut + private BufferedReader entree ; //nécessaire à la lecture en une ligne + private BufferedWriter sortie ; //nécessaire à l'écriture en une ligne + // constructeur + public Console() { +// InputStreamReader fluxe = new InputStreamReader(System.in) ; + this.entree = new BufferedReader(new InputStreamReader(System.in)) ; +// OutputStreamWriter fluxs = new OutputStreamWriter(System.out) ; + this.sortie = new BufferedWriter(new OutputStreamWriter(System.out)) ; + } + // méthodes + public void ConsoleOut(String text) { + try{ + this.sortie.write(text) ; + this.sortie.flush() ; //affiche le texte à la console + }catch(IOException er){ + System.err.println("Console down, please relaunch program") ; + } + } + public void ConsoleOutln(String text) { + try{ + this.sortie.write(text) ; + this.sortie.newLine() ; + this.sortie.flush() ; //affiche le texte à la console + }catch(IOException er){ + System.err.println("Console down, please relaunch program") ; + } + } + public String ConsoleIn() { + String ligne = "" ; //initialisation avant le try + try{ + ligne = this.entree.readLine() ; //bloquant tant qu'il n'y à rien à lire + }catch(IOException er){ + System.err.println("Console down, please relaunch program") ; + } + return ligne ; //à placer en dehors du try + } + // affichage + public String toString() { + return "" ; + } +} \ No newline at end of file diff --git a/src/Partie.java b/src/Partie.java index 619f719..8e9ba8f 100644 --- a/src/Partie.java +++ b/src/Partie.java @@ -2,22 +2,127 @@ /** * La classe Partie * -* @version -* @author -* Date : +* @version 0.1 +* @author Aurélien +* Date : 08-10-25 * Licence : */ public class Partie { + //Contantes + private static final byte REMAININGTRY = 11 ; + private static final byte CARACTERCODESHIFT = 65 ; //Décalage ASCI > 'A' + //Attributs + private char[] secretword ; + private byte wordsize ; + private boolean[] foundletters ; + private boolean[] entriesletters = new boolean[26] ; //Pseudo Alphabée + private byte remainingtry = REMAININGTRY ; //Constructeur public Partie() { - + this.secretword = generateSecretWord() ; + this.wordsize = (byte) secretword.length ; + this.foundletters = new boolean[wordsize] ; } //Méthodes + public char[] getSecretWord() { + return this.secretword ; + } + + 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 ; + }else if(wordIsFound()){ + return true ; + }else{ + return false ; + } + } + + /** + * 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 + if(this.entriesletters[caractercode-CARACTERCODESHIFT]){ + this.remainingtry-- ; //Décrément des essais + return true ; + }else{ + boolean trouvé = false ; + for(byte i = 0 ; i < this.wordsize ; i++){ //Parcours du "secretword" + if(this.secretword[i] == letter){ + this.foundletters[i] = true ; + trouvé = true ; + } + } + if(trouvé == false){ + this.remainingtry-- ; //Décrément des essais + } + this.entriesletters[caractercode-CARACTERCODESHIFT] = true ; //Ajout au tableau des lettres jouées + return false ; + } + } + + + private char[] generateSecretWord() { + char[] word = {'D','A','M','I','E','N'}; + //À implémenter plus tard + return word ; + } + + private boolean wordIsFound() { + 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 ; + } + //Affichage public String toString() { return "" ; } + + //Tests + public static void main(String[] args){ + char[] test = {'E','O','M','I','E','D','A','Z','N'}; + byte taille = (byte) test.length ; + boolean etat ; + + Partie jeu = new Partie(); + System.out.println("Trick > " + String.valueOf(jeu.secretword) + "\n"); + for(byte i = 0 ; i < taille && !jeu.gameIsEnding() ; i++){ + System.out.println("Essais restants : " + jeu.getRemainingTry()); + etat = jeu.isAlreadyEntries(test[i]); + for(byte l = 0 ; l < jeu.wordsize ; l++){ //Parcours du "secretword" + if(jeu.foundletters[l] == true){ + System.out.print(jeu.getSecretWord()[l] + " "); + }else{ + System.out.print("_ "); + } + } + System.out.println(""); //Lisibilité + //System.out.println("Lettres : " + jeu.entriesletters); + } + } } From ffbe1e232ef3a6ff92866fd4e18230d5f69f638d Mon Sep 17 00:00:00 2001 From: amary Date: Wed, 8 Oct 2025 16:09:04 +0200 Subject: [PATCH 2/3] Retirer Console --- src/Console.java | 51 ------------------------------------------------ 1 file changed, 51 deletions(-) delete mode 100644 src/Console.java diff --git a/src/Console.java b/src/Console.java deleted file mode 100644 index 1e5a6e4..0000000 --- a/src/Console.java +++ /dev/null @@ -1,51 +0,0 @@ -import java.io.*; -/* -Auteur : Aurélien Date : 25-03-24 Version : 1.0 Liscence : Usage Personnel - -Pour se servir de cette classe, il faut créer au préalable un objet unique qui nous -servira d'intermédiaire avec la console. -Ex : Console connect = new Console() ; -*/ -public class Console { - // attribut - private BufferedReader entree ; //nécessaire à la lecture en une ligne - private BufferedWriter sortie ; //nécessaire à l'écriture en une ligne - // constructeur - public Console() { -// InputStreamReader fluxe = new InputStreamReader(System.in) ; - this.entree = new BufferedReader(new InputStreamReader(System.in)) ; -// OutputStreamWriter fluxs = new OutputStreamWriter(System.out) ; - this.sortie = new BufferedWriter(new OutputStreamWriter(System.out)) ; - } - // méthodes - public void ConsoleOut(String text) { - try{ - this.sortie.write(text) ; - this.sortie.flush() ; //affiche le texte à la console - }catch(IOException er){ - System.err.println("Console down, please relaunch program") ; - } - } - public void ConsoleOutln(String text) { - try{ - this.sortie.write(text) ; - this.sortie.newLine() ; - this.sortie.flush() ; //affiche le texte à la console - }catch(IOException er){ - System.err.println("Console down, please relaunch program") ; - } - } - public String ConsoleIn() { - String ligne = "" ; //initialisation avant le try - try{ - ligne = this.entree.readLine() ; //bloquant tant qu'il n'y à rien à lire - }catch(IOException er){ - System.err.println("Console down, please relaunch program") ; - } - return ligne ; //à placer en dehors du try - } - // affichage - public String toString() { - return "" ; - } -} \ No newline at end of file From e6e0d4cf7126d510a819f43af88756195445b931 Mon Sep 17 00:00:00 2001 From: amary Date: Wed, 8 Oct 2025 16:14:39 +0200 Subject: [PATCH 3/3] Correctif noms --- src/Partie.java | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Partie.java b/src/Partie.java index 8e9ba8f..c96cdf5 100644 --- a/src/Partie.java +++ b/src/Partie.java @@ -66,14 +66,14 @@ public class Partie { this.remainingtry-- ; //Décrément des essais return true ; }else{ - boolean trouvé = false ; + boolean isfind = false ; for(byte i = 0 ; i < this.wordsize ; i++){ //Parcours du "secretword" if(this.secretword[i] == letter){ this.foundletters[i] = true ; - trouvé = true ; + isfind = true ; } } - if(trouvé == false){ + if(isfind == false){ this.remainingtry-- ; //Décrément des essais } this.entriesletters[caractercode-CARACTERCODESHIFT] = true ; //Ajout au tableau des lettres jouées @@ -106,23 +106,23 @@ public class Partie { //Tests public static void main(String[] args){ char[] test = {'E','O','M','I','E','D','A','Z','N'}; - byte taille = (byte) test.length ; - boolean etat ; + byte size = (byte) test.length ; + boolean status ; - Partie jeu = new Partie(); - System.out.println("Trick > " + String.valueOf(jeu.secretword) + "\n"); - for(byte i = 0 ; i < taille && !jeu.gameIsEnding() ; i++){ - System.out.println("Essais restants : " + jeu.getRemainingTry()); - etat = jeu.isAlreadyEntries(test[i]); - for(byte l = 0 ; l < jeu.wordsize ; l++){ //Parcours du "secretword" - if(jeu.foundletters[l] == true){ - System.out.print(jeu.getSecretWord()[l] + " "); + 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 : " + jeu.entriesletters); + //System.out.println("Lettres : " + game.entriesletters); } } }