From 254c6c8440964fbde3dd1dfbb854aa4081d3570a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9leste=20BARBOSA?= Date: Sat, 4 May 2024 11:56:53 +0200 Subject: [PATCH 01/36] erreur supprimer dernier jeton --- Sources/CoreLibrary/Code.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/CoreLibrary/Code.cs b/Sources/CoreLibrary/Code.cs index 4c00021..c23f278 100644 --- a/Sources/CoreLibrary/Code.cs +++ b/Sources/CoreLibrary/Code.cs @@ -31,7 +31,8 @@ if(NbJetons <= 0) throw new CodeTableauLesJetonsVideException(); - lesJetons[NbJetons--] = null; + lesJetons[NbJetons-1] = null; + --NbJetons; } public Jeton RecupererJeton(int indice) From b0a2d916d43fde7e783d5c07b1d02b67f60d7efc Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Mon, 6 May 2024 17:44:27 +0200 Subject: [PATCH 02/36] =?UTF-8?q?D=C3=A9but=20de=20la=20classe=20Partie=20?= =?UTF-8?q?et=20des=20=C3=A9venments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/ConsoleApp/Program.cs | 88 ------------------- Sources/CoreLibrary/CoreLibrary.csproj | 4 + .../CodeIndiceHorsDePorteeException.cs | 2 +- .../CodeJetonNullException.cs | 0 .../CodeTableauLesJetonsCompletException.cs | 0 .../CodeTableauLesJetonsIncompletException.cs | 0 .../CodeTableauLesJetonsVideException.cs | 0 .../PlateauCodeIncompletException.cs | 0 .../PlateauTailleCodeException.cs | 0 .../PlateauTailleCodeIncompleteException.cs | 0 .../PlateauTailleGrilleException.cs | 0 .../ReglesClassiquesJoueurCourantNull.cs | 0 Sources/CoreLibrary/Partie.cs | 42 +++++++++ 13 files changed, 47 insertions(+), 89 deletions(-) rename Sources/CoreLibrary/{ => Exceptions}/CodeIndiceHorsDePorteeException.cs (90%) rename Sources/CoreLibrary/{ => Exceptions}/CodeJetonNullException.cs (100%) rename Sources/CoreLibrary/{ => Exceptions}/CodeTableauLesJetonsCompletException.cs (100%) rename Sources/CoreLibrary/{ => Exceptions}/CodeTableauLesJetonsIncompletException.cs (100%) rename Sources/CoreLibrary/{ => Exceptions}/CodeTableauLesJetonsVideException.cs (100%) rename Sources/CoreLibrary/{ => Exceptions}/PlateauCodeIncompletException.cs (100%) rename Sources/CoreLibrary/{ => Exceptions}/PlateauTailleCodeException.cs (100%) rename Sources/CoreLibrary/{ => Exceptions}/PlateauTailleCodeIncompleteException.cs (100%) rename Sources/CoreLibrary/{ => Exceptions}/PlateauTailleGrilleException.cs (100%) rename Sources/CoreLibrary/{ => Exceptions}/ReglesClassiquesJoueurCourantNull.cs (100%) create mode 100644 Sources/CoreLibrary/Partie.cs diff --git a/Sources/ConsoleApp/Program.cs b/Sources/ConsoleApp/Program.cs index 475a617..e69de29 100644 --- a/Sources/ConsoleApp/Program.cs +++ b/Sources/ConsoleApp/Program.cs @@ -1,88 +0,0 @@ -using CoreLibrary; -using ConsoleApp; - - - -Console.OutputEncoding = System.Text.Encoding.UTF8; - -ReglesClassiques partie = new ReglesClassiques(); - -Utils.AfficherTitre(); - -Utils.AfficherTitre("Joueurs"); - -string joueur1; -string joueur2; - -while (true) -{ - try - { - joueur1 = Utils.SaisirNom(); - break; - } - catch(UtilsNomJoueurNullException) - { - Console.WriteLine("Nom invalide pour le joueur ! Ressaisir le nom"); - } -} - -while (true) -{ - try - { - joueur2 = Utils.SaisirNom(); - break; - } - catch (UtilsNomJoueurNullException) - { - Console.WriteLine("Nom invalide pour le joueur 2 ! Ressaisir le nom"); - } -} - -Utils.AfficherSeparateur(); - -partie.AjouterJoueur(joueur1); -partie.AjouterJoueur(joueur2); - -partie.CommencerLaPartie(); - -while (!partie.EstTerminee()) -{ - Console.WriteLine(partie.JoueurCourant().Nom); - Console.WriteLine(); - - Utils.DessinerPlateau(partie.JoueurCourant().Plateau.Grille(), partie.JoueurCourant().Plateau.Indicateurs()); - Console.WriteLine(); - - Code code = partie.GenererCode(); - - Utils.ChoixCode(ref code); - - partie.JoueurCourant().Plateau.AjouterCode(code); - - partie.PasserLaMain(); - - Utils.AfficherSeparateur(); -} - -Console.WriteLine("La partie est maintenant terminée !"); - -Joueur[] gagnants = partie.Gagnants().ToArray(); -Joueur[] perdants = partie.Perdants().ToArray(); - - - -if (gagnants.Length > 1) -{ - Console.WriteLine("C'est une égalité !"); -} -else if (gagnants.Length == 1) -{ - Console.WriteLine($"C'est une victoire de {gagnants[0].Nom}." + - $""); -} -else -{ - Console.WriteLine("C'est une défaite..."); -} diff --git a/Sources/CoreLibrary/CoreLibrary.csproj b/Sources/CoreLibrary/CoreLibrary.csproj index fa71b7a..9ff0d50 100644 --- a/Sources/CoreLibrary/CoreLibrary.csproj +++ b/Sources/CoreLibrary/CoreLibrary.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/Sources/CoreLibrary/CodeIndiceHorsDePorteeException.cs b/Sources/CoreLibrary/Exceptions/CodeIndiceHorsDePorteeException.cs similarity index 90% rename from Sources/CoreLibrary/CodeIndiceHorsDePorteeException.cs rename to Sources/CoreLibrary/Exceptions/CodeIndiceHorsDePorteeException.cs index 36c0929..6615035 100644 --- a/Sources/CoreLibrary/CodeIndiceHorsDePorteeException.cs +++ b/Sources/CoreLibrary/Exceptions/CodeIndiceHorsDePorteeException.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace CoreLibrary +namespace CoreLibrary.Excpetion { public class CodeIndiceHorsDePorteeException : Exception { diff --git a/Sources/CoreLibrary/CodeJetonNullException.cs b/Sources/CoreLibrary/Exceptions/CodeJetonNullException.cs similarity index 100% rename from Sources/CoreLibrary/CodeJetonNullException.cs rename to Sources/CoreLibrary/Exceptions/CodeJetonNullException.cs diff --git a/Sources/CoreLibrary/CodeTableauLesJetonsCompletException.cs b/Sources/CoreLibrary/Exceptions/CodeTableauLesJetonsCompletException.cs similarity index 100% rename from Sources/CoreLibrary/CodeTableauLesJetonsCompletException.cs rename to Sources/CoreLibrary/Exceptions/CodeTableauLesJetonsCompletException.cs diff --git a/Sources/CoreLibrary/CodeTableauLesJetonsIncompletException.cs b/Sources/CoreLibrary/Exceptions/CodeTableauLesJetonsIncompletException.cs similarity index 100% rename from Sources/CoreLibrary/CodeTableauLesJetonsIncompletException.cs rename to Sources/CoreLibrary/Exceptions/CodeTableauLesJetonsIncompletException.cs diff --git a/Sources/CoreLibrary/CodeTableauLesJetonsVideException.cs b/Sources/CoreLibrary/Exceptions/CodeTableauLesJetonsVideException.cs similarity index 100% rename from Sources/CoreLibrary/CodeTableauLesJetonsVideException.cs rename to Sources/CoreLibrary/Exceptions/CodeTableauLesJetonsVideException.cs diff --git a/Sources/CoreLibrary/PlateauCodeIncompletException.cs b/Sources/CoreLibrary/Exceptions/PlateauCodeIncompletException.cs similarity index 100% rename from Sources/CoreLibrary/PlateauCodeIncompletException.cs rename to Sources/CoreLibrary/Exceptions/PlateauCodeIncompletException.cs diff --git a/Sources/CoreLibrary/PlateauTailleCodeException.cs b/Sources/CoreLibrary/Exceptions/PlateauTailleCodeException.cs similarity index 100% rename from Sources/CoreLibrary/PlateauTailleCodeException.cs rename to Sources/CoreLibrary/Exceptions/PlateauTailleCodeException.cs diff --git a/Sources/CoreLibrary/PlateauTailleCodeIncompleteException.cs b/Sources/CoreLibrary/Exceptions/PlateauTailleCodeIncompleteException.cs similarity index 100% rename from Sources/CoreLibrary/PlateauTailleCodeIncompleteException.cs rename to Sources/CoreLibrary/Exceptions/PlateauTailleCodeIncompleteException.cs diff --git a/Sources/CoreLibrary/PlateauTailleGrilleException.cs b/Sources/CoreLibrary/Exceptions/PlateauTailleGrilleException.cs similarity index 100% rename from Sources/CoreLibrary/PlateauTailleGrilleException.cs rename to Sources/CoreLibrary/Exceptions/PlateauTailleGrilleException.cs diff --git a/Sources/CoreLibrary/ReglesClassiquesJoueurCourantNull.cs b/Sources/CoreLibrary/Exceptions/ReglesClassiquesJoueurCourantNull.cs similarity index 100% rename from Sources/CoreLibrary/ReglesClassiquesJoueurCourantNull.cs rename to Sources/CoreLibrary/Exceptions/ReglesClassiquesJoueurCourantNull.cs diff --git a/Sources/CoreLibrary/Partie.cs b/Sources/CoreLibrary/Partie.cs new file mode 100644 index 0000000..ecb4b1c --- /dev/null +++ b/Sources/CoreLibrary/Partie.cs @@ -0,0 +1,42 @@ +namespace CoreLibrary +{ + public class Partie + { + private IRegles regles; + + public Partie(IRegles regles) + { + this.regles = regles; + } + + public void Jouer() + { + DefinirJoueurs(); + + regles.CommencerLaPartie(); + + while (!regles.EstTerminee()) + { + // ?? + } + + PartieTerminee(); + + } + + private void DefinirJoueurs() + { + while(regles.NbJoueurs != regles.NbJoueursMaximum) + { + // + } + } + + private void PartieTerminee() + { + + } + + + } +} From 33c2b4ff03bba073989fb096035c00fe91407ba5 Mon Sep 17 00:00:00 2001 From: "pauline.prady" Date: Mon, 6 May 2024 18:31:45 +0200 Subject: [PATCH 03/36] Classe Partie --- Sources/ConsoleApp/Program.cs | 4 ++++ Sources/CoreLibrary/Code.cs | 2 -- Sources/CoreLibrary/Partie.cs | 25 ++++++++++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Sources/ConsoleApp/Program.cs b/Sources/ConsoleApp/Program.cs index e69de29..3c85a5e 100644 --- a/Sources/ConsoleApp/Program.cs +++ b/Sources/ConsoleApp/Program.cs @@ -0,0 +1,4 @@ +using CoreLibrary; + +Partie maPartie = new Partie(new ReglesClassiques()); +maPartie.Jouer(); diff --git a/Sources/CoreLibrary/Code.cs b/Sources/CoreLibrary/Code.cs index c23f278..27bf7d4 100644 --- a/Sources/CoreLibrary/Code.cs +++ b/Sources/CoreLibrary/Code.cs @@ -37,8 +37,6 @@ public Jeton RecupererJeton(int indice) { - if(indice < 0 || indice > TailleMaximale()) - throw new CodeIndiceHorsDePorteeException(); Jeton? jeton = lesJetons[indice]; diff --git a/Sources/CoreLibrary/Partie.cs b/Sources/CoreLibrary/Partie.cs index ecb4b1c..fb61c2c 100644 --- a/Sources/CoreLibrary/Partie.cs +++ b/Sources/CoreLibrary/Partie.cs @@ -17,24 +17,43 @@ while (!regles.EstTerminee()) { - // ?? + Joueur joueurCourant = regles.JoueurCourant(); + Plateau plateauCourant = joueurCourant.Plateau; + + Code code = regles.GenererCode(); + + while (!code.EstComplet()) + { + AjouterJeton(code); + } + plateauCourant.AjouterCode(code); + + regles.PasserLaMain(); } PartieTerminee(); } + private void AjouterJeton(Code code) + { + Jeton jeton = new Jeton(Couleur.ROUGE); + code.AjouterJeton(jeton); + } + private void DefinirJoueurs() { while(regles.NbJoueurs != regles.NbJoueursMaximum) { - // + string nom = "pauline"; + regles.AjouterJoueur(nom); } } private void PartieTerminee() { - + regles.Gagnants(); + regles.Perdants(); } From 7a430538b9706d0d4495de66524b5a3f5a049eb7 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Mon, 6 May 2024 18:49:42 +0200 Subject: [PATCH 04/36] nouvelles exceptions --- Sources/CoreLibrary/Code.cs | 55 +++++++++++++------ .../CodeIndiceHorsDePorteeException.cs | 14 ----- Sources/CoreLibrary/CodeJetonNullException.cs | 14 ----- .../CodeTableauLesJetonsCompletException.cs | 15 ----- .../CodeTableauLesJetonsIncompletException.cs | 14 ----- .../CodeTableauLesJetonsVideException.cs | 14 ----- .../Exceptions/CodeCompletException.cs | 9 +++ .../Exceptions/CodeIncompletException.cs | 9 +++ .../Exceptions/CodeInvalideException.cs | 9 +++ .../Exceptions/CodeVideException.cs | 9 +++ .../Exceptions/GrilleCompleteException.cs | 9 +++ .../Exceptions/IndiceCodeException.cs | 9 +++ .../Exceptions/PartieNonCommenceeException.cs | 9 +++ .../Exceptions/TailleCodeException.cs | 9 +++ .../Exceptions/TailleGrilleException.cs | 9 +++ Sources/CoreLibrary/Plateau.cs | 22 ++++++-- .../PlateauCodeIncompletException.cs | 8 --- .../CoreLibrary/PlateauTailleCodeException.cs | 7 --- .../PlateauTailleCodeIncompleteException.cs | 7 --- .../PlateauTailleGrilleException.cs | 8 --- Sources/CoreLibrary/ReglesClassiques.cs | 8 ++- .../ReglesClassiquesJoueurCourantNull.cs | 8 --- 22 files changed, 141 insertions(+), 134 deletions(-) delete mode 100644 Sources/CoreLibrary/CodeIndiceHorsDePorteeException.cs delete mode 100644 Sources/CoreLibrary/CodeJetonNullException.cs delete mode 100644 Sources/CoreLibrary/CodeTableauLesJetonsCompletException.cs delete mode 100644 Sources/CoreLibrary/CodeTableauLesJetonsIncompletException.cs delete mode 100644 Sources/CoreLibrary/CodeTableauLesJetonsVideException.cs create mode 100644 Sources/CoreLibrary/Exceptions/CodeCompletException.cs create mode 100644 Sources/CoreLibrary/Exceptions/CodeIncompletException.cs create mode 100644 Sources/CoreLibrary/Exceptions/CodeInvalideException.cs create mode 100644 Sources/CoreLibrary/Exceptions/CodeVideException.cs create mode 100644 Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs create mode 100644 Sources/CoreLibrary/Exceptions/IndiceCodeException.cs create mode 100644 Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs create mode 100644 Sources/CoreLibrary/Exceptions/TailleCodeException.cs create mode 100644 Sources/CoreLibrary/Exceptions/TailleGrilleException.cs delete mode 100644 Sources/CoreLibrary/PlateauCodeIncompletException.cs delete mode 100644 Sources/CoreLibrary/PlateauTailleCodeException.cs delete mode 100644 Sources/CoreLibrary/PlateauTailleCodeIncompleteException.cs delete mode 100644 Sources/CoreLibrary/PlateauTailleGrilleException.cs delete mode 100644 Sources/CoreLibrary/ReglesClassiquesJoueurCourantNull.cs diff --git a/Sources/CoreLibrary/Code.cs b/Sources/CoreLibrary/Code.cs index 79e10b3..6081402 100644 --- a/Sources/CoreLibrary/Code.cs +++ b/Sources/CoreLibrary/Code.cs @@ -1,4 +1,6 @@ -namespace CoreLibrary +using CoreLibrary.Exceptions; + +namespace CoreLibrary { public class Code { @@ -7,41 +9,59 @@ public int NbJetons { get; private set; } = 0; public Code(int tailleCode) - { + { + if(tailleCode <= 0) + { + throw new TailleCodeException(tailleCode); + } + lesJetons = new Jeton?[tailleCode]; } - public Code(IEnumerable jetons) + public Code(IEnumerable jetons) { - lesJetons = jetons.ToArray(); + if (jetons.Count() == 0) + { + throw new TailleCodeException(jetons.Count()); + } + + lesJetons = new Jeton?[jetons.Count()]; + foreach(Jeton jeton in jetons) + { + AjouterJeton(jeton); + } } public void AjouterJeton(Jeton jeton) - { - if (EstComplet()) - throw new CodeTableauLesJetonsCompletException(); - + { + if (NbJetons == TailleMaximale()) + { + throw new CodeCompletException(); + } + lesJetons[NbJetons++] = jeton; } public void SupprimerDernierJeton() { - if(NbJetons <= 0) - throw new CodeTableauLesJetonsVideException(); - - lesJetons[NbJetons--] = null; + if(NbJetons == 0) + { + throw new CodeVideException(); + } + + lesJetons[--NbJetons] = null; } public Jeton RecupererJeton(int indice) { if(indice < 0 || indice > TailleMaximale()) - throw new CodeIndiceHorsDePorteeException(); + throw new IndiceCodeException(indice, NbJetons-1); Jeton? jeton = lesJetons[indice]; if (!jeton.HasValue) - throw new CodeJetonNullException(); - + throw new IndiceCodeException(indice, NbJetons-1); + return jeton.Value; } @@ -63,11 +83,12 @@ public IEnumerable Comparer(Code autreCode) { // Mon code est le code correct, l'autre code est celui qui teste - if (!autreCode.EstComplet()) - throw new CodeTableauLesJetonsIncompletException(); Indicateur[] indicateurs = []; + if (EstComplet() || !autreCode.EstComplet()) + return indicateurs; + Jeton?[] mesJetons = Jetons().ToArray(); Jeton?[] sesJetons = autreCode.Jetons().ToArray(); diff --git a/Sources/CoreLibrary/CodeIndiceHorsDePorteeException.cs b/Sources/CoreLibrary/CodeIndiceHorsDePorteeException.cs deleted file mode 100644 index 36c0929..0000000 --- a/Sources/CoreLibrary/CodeIndiceHorsDePorteeException.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CoreLibrary -{ - public class CodeIndiceHorsDePorteeException : Exception - { - public CodeIndiceHorsDePorteeException() : base("L'indice pointe en dehors du tableau") - { } - } -} diff --git a/Sources/CoreLibrary/CodeJetonNullException.cs b/Sources/CoreLibrary/CodeJetonNullException.cs deleted file mode 100644 index 9fcc9f3..0000000 --- a/Sources/CoreLibrary/CodeJetonNullException.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CoreLibrary -{ - internal class CodeJetonNullException : Exception - { - public CodeJetonNullException() : base("le jeton est null") - { } - } -} diff --git a/Sources/CoreLibrary/CodeTableauLesJetonsCompletException.cs b/Sources/CoreLibrary/CodeTableauLesJetonsCompletException.cs deleted file mode 100644 index dfc3d44..0000000 --- a/Sources/CoreLibrary/CodeTableauLesJetonsCompletException.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CoreLibrary -{ - public class CodeTableauLesJetonsCompletException : Exception - { - public CodeTableauLesJetonsCompletException() : base("Le tableau des jetons est plein") - { } - - } -} diff --git a/Sources/CoreLibrary/CodeTableauLesJetonsIncompletException.cs b/Sources/CoreLibrary/CodeTableauLesJetonsIncompletException.cs deleted file mode 100644 index 2205f9c..0000000 --- a/Sources/CoreLibrary/CodeTableauLesJetonsIncompletException.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CoreLibrary -{ - public class CodeTableauLesJetonsIncompletException : Exception - { - public CodeTableauLesJetonsIncompletException() : base("Le tableau des jetons est incomplet") - { } - } -} diff --git a/Sources/CoreLibrary/CodeTableauLesJetonsVideException.cs b/Sources/CoreLibrary/CodeTableauLesJetonsVideException.cs deleted file mode 100644 index d9300f8..0000000 --- a/Sources/CoreLibrary/CodeTableauLesJetonsVideException.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CoreLibrary -{ - public class CodeTableauLesJetonsVideException : Exception - { - public CodeTableauLesJetonsVideException() : base("Le tableau des jetons est vide") - { } - } -} diff --git a/Sources/CoreLibrary/Exceptions/CodeCompletException.cs b/Sources/CoreLibrary/Exceptions/CodeCompletException.cs new file mode 100644 index 0000000..3a560c0 --- /dev/null +++ b/Sources/CoreLibrary/Exceptions/CodeCompletException.cs @@ -0,0 +1,9 @@ +namespace CoreLibrary.Exceptions +{ + public class CodeCompletException : Exception + { + public CodeCompletException() : + base("Le code dans lequel vous essayez d'ajouter un jeton est dĂ©jĂ  complet.") + { } + } +} diff --git a/Sources/CoreLibrary/Exceptions/CodeIncompletException.cs b/Sources/CoreLibrary/Exceptions/CodeIncompletException.cs new file mode 100644 index 0000000..5e29af8 --- /dev/null +++ b/Sources/CoreLibrary/Exceptions/CodeIncompletException.cs @@ -0,0 +1,9 @@ +namespace CoreLibrary.Exceptions +{ + public class CodeIncompletException : Exception + { + public CodeIncompletException() : + base("Le code que vous essayez d'ajouter dans la grille n'est pas complet.") + { } + } +} diff --git a/Sources/CoreLibrary/Exceptions/CodeInvalideException.cs b/Sources/CoreLibrary/Exceptions/CodeInvalideException.cs new file mode 100644 index 0000000..fe616e9 --- /dev/null +++ b/Sources/CoreLibrary/Exceptions/CodeInvalideException.cs @@ -0,0 +1,9 @@ +namespace CoreLibrary.Exceptions +{ + public class CodeInvalideException : Exception + { + public CodeInvalideException(int tailleCodeAjoute, int tailleCodePlateau) : + base($"Le code que vous essayez d'ajouter est un code de taille {tailleCodeAjoute}, or le plateau attend un code de {tailleCodePlateau}.") + { } + } +} diff --git a/Sources/CoreLibrary/Exceptions/CodeVideException.cs b/Sources/CoreLibrary/Exceptions/CodeVideException.cs new file mode 100644 index 0000000..bc6c9d4 --- /dev/null +++ b/Sources/CoreLibrary/Exceptions/CodeVideException.cs @@ -0,0 +1,9 @@ +namespace CoreLibrary.Exceptions +{ + public class CodeVideException : Exception + { + public CodeVideException() : + base("Le code dans lequel vous essayez de supprimer un jeton est dĂ©jĂ  vide.") + { } + } +} diff --git a/Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs b/Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs new file mode 100644 index 0000000..b7f8434 --- /dev/null +++ b/Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs @@ -0,0 +1,9 @@ +namespace CoreLibrary.Exceptions +{ + public class GrilleCompleteException : Exception + { + public GrilleCompleteException() : + base("La grille dans laquelle vous essayez d'ajouter un code est dĂ©jĂ  complète.") + { } + } +} diff --git a/Sources/CoreLibrary/Exceptions/IndiceCodeException.cs b/Sources/CoreLibrary/Exceptions/IndiceCodeException.cs new file mode 100644 index 0000000..8b3c0e5 --- /dev/null +++ b/Sources/CoreLibrary/Exceptions/IndiceCodeException.cs @@ -0,0 +1,9 @@ +namespace CoreLibrary.Exceptions +{ + public class IndiceCodeException : Exception + { + public IndiceCodeException(int indice, int indiceMax) : + base($"Vous avez essayĂ© de rĂ©cupĂ©rer le jeton Ă  la place {indice}, mais son indice doit ĂŞtre compris entre 0 et {indiceMax}.") + { } + } +} diff --git a/Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs b/Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs new file mode 100644 index 0000000..052bacc --- /dev/null +++ b/Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs @@ -0,0 +1,9 @@ +namespace CoreLibrary.Exceptions +{ + public class PartieNonCommenceeException : Exception + { + public PartieNonCommenceeException() : + base("La partie n'a pas encore commencĂ©e.") + { } + } +} diff --git a/Sources/CoreLibrary/Exceptions/TailleCodeException.cs b/Sources/CoreLibrary/Exceptions/TailleCodeException.cs new file mode 100644 index 0000000..ebf67c9 --- /dev/null +++ b/Sources/CoreLibrary/Exceptions/TailleCodeException.cs @@ -0,0 +1,9 @@ +namespace CoreLibrary.Exceptions +{ + public class TailleCodeException : Exception + { + public TailleCodeException(int taille) : + base($"Un code doit avoir une taille positive non nulle, or il a reçu {taille}.") + { } + } +} diff --git a/Sources/CoreLibrary/Exceptions/TailleGrilleException.cs b/Sources/CoreLibrary/Exceptions/TailleGrilleException.cs new file mode 100644 index 0000000..494e1ee --- /dev/null +++ b/Sources/CoreLibrary/Exceptions/TailleGrilleException.cs @@ -0,0 +1,9 @@ +namespace CoreLibrary.Exceptions +{ + public class TailleGrilleException : Exception + { + public TailleGrilleException(int taille) : + base($"Une grille doit avoir une taille positive non nulle, or elle a reçu {taille}.") + { } + } +} diff --git a/Sources/CoreLibrary/Plateau.cs b/Sources/CoreLibrary/Plateau.cs index d8b0c16..dd3bbff 100644 --- a/Sources/CoreLibrary/Plateau.cs +++ b/Sources/CoreLibrary/Plateau.cs @@ -1,4 +1,6 @@ -namespace CoreLibrary +using CoreLibrary.Exceptions; + +namespace CoreLibrary { public class Plateau { @@ -17,12 +19,12 @@ { if(tailleCode <= 0) { - throw new PlateauTailleCodeException(); + throw new TailleCodeException(tailleCode); } if (tailleGrille <= 0) { - throw new PlateauTailleGrilleException(); + throw new TailleGrilleException(tailleGrille); } codeSecret = new Code(tailleCode); @@ -53,12 +55,12 @@ { if (code.TailleMaximale() != tailleCode) { - throw new PlateauTailleCodeException(); + throw new CodeInvalideException(code.TailleMaximale(), tailleCode); } if (!code.EstComplet()) { - throw new PlateauCodeIncompletException(); + throw new CodeIncompletException(); } indicateurs[Tour - 1] = codeSecret.Comparer(code); @@ -73,6 +75,16 @@ public bool EstBonCode(Code code) { + if (code.TailleMaximale() != tailleCode) + { + throw new CodeInvalideException(code.TailleMaximale(), tailleCode); + } + + if (!code.EstComplet()) + { + throw new CodeIncompletException(); + } + IEnumerable indicateurs = codeSecret.Comparer(code); if (indicateurs.Count() != tailleCode) diff --git a/Sources/CoreLibrary/PlateauCodeIncompletException.cs b/Sources/CoreLibrary/PlateauCodeIncompletException.cs deleted file mode 100644 index d522cb4..0000000 --- a/Sources/CoreLibrary/PlateauCodeIncompletException.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace CoreLibrary -{ - public class PlateauCodeIncompletException : Exception - { - public PlateauCodeIncompletException() : base("Le code est incomplet") - { } - } -} diff --git a/Sources/CoreLibrary/PlateauTailleCodeException.cs b/Sources/CoreLibrary/PlateauTailleCodeException.cs deleted file mode 100644 index a73ed73..0000000 --- a/Sources/CoreLibrary/PlateauTailleCodeException.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace CoreLibrary -{ - public class PlateauTailleCodeException : Exception - { - public PlateauTailleCodeException() : base("La taille du code doit ĂŞtre positive non nulle.") { } - } -} diff --git a/Sources/CoreLibrary/PlateauTailleCodeIncompleteException.cs b/Sources/CoreLibrary/PlateauTailleCodeIncompleteException.cs deleted file mode 100644 index 38133c7..0000000 --- a/Sources/CoreLibrary/PlateauTailleCodeIncompleteException.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace CoreLibrary -{ - public class PlateauTailleCodeIncompleteException : Exception - { - public PlateauTailleCodeIncompleteException() : base("Le code n'est pas remplit au maximum") { } - } -} diff --git a/Sources/CoreLibrary/PlateauTailleGrilleException.cs b/Sources/CoreLibrary/PlateauTailleGrilleException.cs deleted file mode 100644 index 1305e65..0000000 --- a/Sources/CoreLibrary/PlateauTailleGrilleException.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace CoreLibrary -{ - public class PlateauTailleGrilleException : Exception - { - public PlateauTailleGrilleException() : base("La taille de la grille doit ĂŞtre Ă©gale positive non nulle.") - { } - } -} diff --git a/Sources/CoreLibrary/ReglesClassiques.cs b/Sources/CoreLibrary/ReglesClassiques.cs index a7ac01e..3776b16 100644 --- a/Sources/CoreLibrary/ReglesClassiques.cs +++ b/Sources/CoreLibrary/ReglesClassiques.cs @@ -1,4 +1,6 @@ -namespace CoreLibrary +using CoreLibrary.Exceptions; + +namespace CoreLibrary { public class ReglesClassiques : IRegles { @@ -28,7 +30,7 @@ public Joueur JoueurCourant() { if (!joueurCourant.HasValue) - throw new ReglesClassiquesJoueurCourantNull(); + throw new PartieNonCommenceeException(); return joueurs[joueurCourant.Value]; } @@ -37,7 +39,7 @@ { if (!joueurCourant.HasValue) { - throw new ReglesClassiquesJoueurCourantNull(); + throw new PartieNonCommenceeException(); } joueurCourant++; diff --git a/Sources/CoreLibrary/ReglesClassiquesJoueurCourantNull.cs b/Sources/CoreLibrary/ReglesClassiquesJoueurCourantNull.cs deleted file mode 100644 index 89e6df5..0000000 --- a/Sources/CoreLibrary/ReglesClassiquesJoueurCourantNull.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace CoreLibrary -{ - public class ReglesClassiquesJoueurCourantNull : Exception - { - public ReglesClassiquesJoueurCourantNull() : base("Le joueur courant est null") - { } - } -} From 568da5718ba3cc50a72275538dd8daade29081e6 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Mon, 6 May 2024 18:50:30 +0200 Subject: [PATCH 05/36] Correction de AJouterJoueur interface --- Sources/CoreLibrary/IRegles.cs | 2 +- Sources/CoreLibrary/ReglesClassiques.cs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/CoreLibrary/IRegles.cs b/Sources/CoreLibrary/IRegles.cs index dfe558b..7c5c389 100644 --- a/Sources/CoreLibrary/IRegles.cs +++ b/Sources/CoreLibrary/IRegles.cs @@ -10,7 +10,7 @@ int NbJoueurs { get; } int NbJoueursMaximum { get; } - void AjouterJoueur(string nom); + Joueur AjouterJoueur(string nom); Joueur JoueurCourant(); void PasserLaMain(); diff --git a/Sources/CoreLibrary/ReglesClassiques.cs b/Sources/CoreLibrary/ReglesClassiques.cs index 3776b16..53c3ef8 100644 --- a/Sources/CoreLibrary/ReglesClassiques.cs +++ b/Sources/CoreLibrary/ReglesClassiques.cs @@ -22,9 +22,11 @@ namespace CoreLibrary } - public void AjouterJoueur(string nom) + public Joueur AjouterJoueur(string nom) { - joueurs[nbJoueurs++] = new Joueur(nom, new Plateau(TailleCodeMaximum, TourMaximum)); + Joueur joueur = new Joueur(nom, new Plateau(TailleCodeMaximum, TourMaximum)) + joueurs[nbJoueurs++] = joueur; + return joueur; } public Joueur JoueurCourant() From 6645c50a8eeed222038ceb854a3f58e395b9f7b9 Mon Sep 17 00:00:00 2001 From: "pauline.prady" Date: Mon, 6 May 2024 19:31:03 +0200 Subject: [PATCH 06/36] =?UTF-8?q?ajout=20des=20=C3=A9v=C3=A9nements=20dans?= =?UTF-8?q?=20partie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/ConsoleApp/Program.cs | 9 +++++ Sources/CoreLibrary/CoreLibrary.csproj | 4 -- .../Events/AjouterCodeEventArgs.cs | 12 ++++++ .../Events/AjouterJetonEventArgs.cs | 13 +++++++ .../Events/AjouterJoueursEventArgs.cs | 12 ++++++ .../Events/DebutPartieEventArgs.cs | 10 +++++ .../Events/NouveauTourEventArgs.cs | 14 +++++++ .../Events/PartieTermineeEventArgs.cs | 20 ++++++++++ .../CoreLibrary/Events/PasserMainEventArgs.cs | 13 +++++++ Sources/CoreLibrary/Partie.cs | 37 ++++++++++++++++--- 10 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 Sources/CoreLibrary/Events/AjouterCodeEventArgs.cs create mode 100644 Sources/CoreLibrary/Events/AjouterJetonEventArgs.cs create mode 100644 Sources/CoreLibrary/Events/AjouterJoueursEventArgs.cs create mode 100644 Sources/CoreLibrary/Events/DebutPartieEventArgs.cs create mode 100644 Sources/CoreLibrary/Events/NouveauTourEventArgs.cs create mode 100644 Sources/CoreLibrary/Events/PartieTermineeEventArgs.cs create mode 100644 Sources/CoreLibrary/Events/PasserMainEventArgs.cs diff --git a/Sources/ConsoleApp/Program.cs b/Sources/ConsoleApp/Program.cs index 3c85a5e..a43a2ae 100644 --- a/Sources/ConsoleApp/Program.cs +++ b/Sources/ConsoleApp/Program.cs @@ -1,4 +1,13 @@ using CoreLibrary; +using CoreLibrary.Events; + +void LaPartieDemarre(object sender, DebutPartieEventArgs evenement) +{ + Console.WriteLine("La partie commence"); +} + Partie maPartie = new Partie(new ReglesClassiques()); +maPartie.debutPartie += LaPartieDemarre; + maPartie.Jouer(); diff --git a/Sources/CoreLibrary/CoreLibrary.csproj b/Sources/CoreLibrary/CoreLibrary.csproj index 9ff0d50..fa71b7a 100644 --- a/Sources/CoreLibrary/CoreLibrary.csproj +++ b/Sources/CoreLibrary/CoreLibrary.csproj @@ -6,8 +6,4 @@ enable - - - - diff --git a/Sources/CoreLibrary/Events/AjouterCodeEventArgs.cs b/Sources/CoreLibrary/Events/AjouterCodeEventArgs.cs new file mode 100644 index 0000000..3cd1c56 --- /dev/null +++ b/Sources/CoreLibrary/Events/AjouterCodeEventArgs.cs @@ -0,0 +1,12 @@ + +namespace CoreLibrary.Events +{ + public class AjouterCodeEventArgs : EventArgs + { + public Code Code { get; private set; } + public AjouterCodeEventArgs(Code code) + { + Code = code; + } + } +} diff --git a/Sources/CoreLibrary/Events/AjouterJetonEventArgs.cs b/Sources/CoreLibrary/Events/AjouterJetonEventArgs.cs new file mode 100644 index 0000000..50b35ab --- /dev/null +++ b/Sources/CoreLibrary/Events/AjouterJetonEventArgs.cs @@ -0,0 +1,13 @@ + + +namespace CoreLibrary.Events +{ + public class AjouterJetonEventArgs : EventArgs + { + public Jeton Jeton { get; private set; } + public AjouterJetonEventArgs(Jeton jeton) + { + Jeton = jeton; + } + } +} diff --git a/Sources/CoreLibrary/Events/AjouterJoueursEventArgs.cs b/Sources/CoreLibrary/Events/AjouterJoueursEventArgs.cs new file mode 100644 index 0000000..4fb2ddb --- /dev/null +++ b/Sources/CoreLibrary/Events/AjouterJoueursEventArgs.cs @@ -0,0 +1,12 @@ +namespace CoreLibrary.Events +{ + public class AjouterJoueursEventArgs : EventArgs + { + public Joueur Joueur { get; private set; } + + public AjouterJoueursEventArgs(Joueur joueur) + { + Joueur = joueur; + } + } +} diff --git a/Sources/CoreLibrary/Events/DebutPartieEventArgs.cs b/Sources/CoreLibrary/Events/DebutPartieEventArgs.cs new file mode 100644 index 0000000..93745af --- /dev/null +++ b/Sources/CoreLibrary/Events/DebutPartieEventArgs.cs @@ -0,0 +1,10 @@ +namespace CoreLibrary.Events +{ + public class DebutPartieEventArgs : EventArgs + { + + public DebutPartieEventArgs() + { + } + } +} diff --git a/Sources/CoreLibrary/Events/NouveauTourEventArgs.cs b/Sources/CoreLibrary/Events/NouveauTourEventArgs.cs new file mode 100644 index 0000000..a6e297f --- /dev/null +++ b/Sources/CoreLibrary/Events/NouveauTourEventArgs.cs @@ -0,0 +1,14 @@ +namespace CoreLibrary.Events +{ + public class NouveauTourEventArgs : EventArgs + { + public Joueur Joueur { get; private set; } + public int Tour { get; private set; } + + public NouveauTourEventArgs(Joueur joueur, int tour) + { + Joueur = joueur; + Tour = tour; + } + } +} \ No newline at end of file diff --git a/Sources/CoreLibrary/Events/PartieTermineeEventArgs.cs b/Sources/CoreLibrary/Events/PartieTermineeEventArgs.cs new file mode 100644 index 0000000..094073c --- /dev/null +++ b/Sources/CoreLibrary/Events/PartieTermineeEventArgs.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CoreLibrary.Events +{ + public class PartieTermineeEventArgs : EventArgs + { + public IEnumerable Gagnants { get; private set; } + public IEnumerable Perdants { get; private set; } + + public PartieTermineeEventArgs(IEnumerable gagnants, IEnumerable perdants) + { + Gagnants = gagnants; + Perdants = perdants; + } + } +} diff --git a/Sources/CoreLibrary/Events/PasserMainEventArgs.cs b/Sources/CoreLibrary/Events/PasserMainEventArgs.cs new file mode 100644 index 0000000..30999ad --- /dev/null +++ b/Sources/CoreLibrary/Events/PasserMainEventArgs.cs @@ -0,0 +1,13 @@ + +using System.Security.Cryptography.X509Certificates; + +namespace CoreLibrary.Events +{ + public class PasserMainEventArgs : EventArgs + { + public PasserMainEventArgs() + { + + } + } +} diff --git a/Sources/CoreLibrary/Partie.cs b/Sources/CoreLibrary/Partie.cs index fb61c2c..41a2bd9 100644 --- a/Sources/CoreLibrary/Partie.cs +++ b/Sources/CoreLibrary/Partie.cs @@ -1,9 +1,28 @@ -namespace CoreLibrary +using CoreLibrary.Events; + +namespace CoreLibrary { public class Partie { private IRegles regles; + public event EventHandler ajouterJoueur; + public event EventHandler debutPartie; + public event EventHandler nouveauTour; + public event EventHandler ajouterJeton; + public event EventHandler ajouterCode; + public event EventHandler passerMain; + public event EventHandler partieTerminee; + + private void QuandAjouterJoueur(Joueur joueur) => ajouterJoueur?.Invoke(this, new AjouterJoueursEventArgs(joueur)); + private void QuandDebutPartie() => debutPartie?.Invoke(this, new DebutPartieEventArgs()); + private void QuandNouveauTour(Joueur joueur, int tour) => nouveauTour?.Invoke(this, new NouveauTourEventArgs(joueur, tour)); + private void QuandNouveauJeton(Jeton jeton) => ajouterJeton?.Invoke(this, new AjouterJetonEventArgs(jeton)); + private void QuandNouveauCode(Code code) => ajouterCode?.Invoke(this, new AjouterCodeEventArgs(code)); + private void QuandPasserMain() => passerMain?.Invoke(this, new PasserMainEventArgs()); + private void QuandPartieTerminee(IEnumerable gagnants, IEnumerable perdants) => partieTerminee?.Invoke(this, new PartieTermineeEventArgs(gagnants, perdants)); + + public Partie(IRegles regles) { this.regles = regles; @@ -11,34 +30,41 @@ public void Jouer() { - DefinirJoueurs(); + DefinirJoueurs(); regles.CommencerLaPartie(); + QuandDebutPartie(); while (!regles.EstTerminee()) { Joueur joueurCourant = regles.JoueurCourant(); - Plateau plateauCourant = joueurCourant.Plateau; + Plateau plateauCourant = joueurCourant.Plateau; + + QuandNouveauTour(joueurCourant, plateauCourant.Tour); Code code = regles.GenererCode(); while (!code.EstComplet()) { - AjouterJeton(code); + AjouterJeton(code); + } plateauCourant.AjouterCode(code); + QuandNouveauCode(code); regles.PasserLaMain(); + QuandPasserMain(); } PartieTerminee(); - + QuandPartieTerminee(regles.Gagnants(), regles.Perdants()); } private void AjouterJeton(Code code) { Jeton jeton = new Jeton(Couleur.ROUGE); code.AjouterJeton(jeton); + QuandNouveauJeton(jeton); } private void DefinirJoueurs() @@ -47,6 +73,7 @@ { string nom = "pauline"; regles.AjouterJoueur(nom); + //QuandAjouterJoueur() } } From 9d0deda4af01fcd7df091958878d2782bc839147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9leste=20BARBOSA?= Date: Fri, 10 May 2024 11:26:48 +0200 Subject: [PATCH 07/36] oublie point virgule --- Sources/CoreLibrary/ReglesClassiques.cs | 228 ++++++++++++------------ 1 file changed, 114 insertions(+), 114 deletions(-) diff --git a/Sources/CoreLibrary/ReglesClassiques.cs b/Sources/CoreLibrary/ReglesClassiques.cs index 53c3ef8..6aab766 100644 --- a/Sources/CoreLibrary/ReglesClassiques.cs +++ b/Sources/CoreLibrary/ReglesClassiques.cs @@ -1,114 +1,114 @@ -using CoreLibrary.Exceptions; - -namespace CoreLibrary -{ - public class ReglesClassiques : IRegles - { - private int nbJoueurs = 0; - private int? joueurCourant; - private readonly Joueur[] joueurs; - - public string Nom { get => "Règles classiques"; } - - public int TourMaximum { get => 12; } - public int TailleCodeMaximum { get => 4; } - public int NbJoueurs { get => nbJoueurs; } - public int NbJoueursMaximum { get => 2; } - - - public ReglesClassiques() - { - joueurs = new Joueur[NbJoueursMaximum]; - } - - - public Joueur AjouterJoueur(string nom) - { - Joueur joueur = new Joueur(nom, new Plateau(TailleCodeMaximum, TourMaximum)) - joueurs[nbJoueurs++] = joueur; - return joueur; - } - - public Joueur JoueurCourant() - { - if (!joueurCourant.HasValue) - throw new PartieNonCommenceeException(); - - return joueurs[joueurCourant.Value]; - } - - public void PasserLaMain() - { - if (!joueurCourant.HasValue) - { - throw new PartieNonCommenceeException(); - } - - joueurCourant++; - if (joueurCourant >= joueurs.Length) - { - joueurCourant = 0; - } - - } - - - public Code GenererCode() - { - return new Code(TailleCodeMaximum); - } - - - public void CommencerLaPartie() - { - joueurCourant = 0; - } - - - public bool EstTerminee() - { - if (!joueurCourant.HasValue || joueurCourant != 0) - return false; - - if (JoueurCourant().Plateau.Tour > TourMaximum) - return true; - - for (int i = 0; i < joueurs.Length; ++i) - { - if (joueurs[i].Plateau.Victoire) - return true; - } - - return false; - } - - - public IEnumerable Gagnants() - { - Joueur[] gagnants = []; - for (int i = 0; i < joueurs.Length; ++i) - { - if (joueurs[i].Plateau.Victoire) - { - gagnants = gagnants.Append(joueurs[i]).ToArray(); - } - } - - return gagnants; - } - - public IEnumerable Perdants() - { - Joueur[] perdants = []; - for (int i = 0; i < joueurs.Length; ++i) - { - if (!joueurs[i].Plateau.Victoire) - { - perdants = perdants.Append(joueurs[i]).ToArray(); - } - } - - return perdants; - } - } -} +using CoreLibrary.Exceptions; + +namespace CoreLibrary +{ + public class ReglesClassiques : IRegles + { + private int nbJoueurs = 0; + private int? joueurCourant; + private readonly Joueur[] joueurs; + + public string Nom { get => "Règles classiques"; } + + public int TourMaximum { get => 12; } + public int TailleCodeMaximum { get => 4; } + public int NbJoueurs { get => nbJoueurs; } + public int NbJoueursMaximum { get => 2; } + + + public ReglesClassiques() + { + joueurs = new Joueur[NbJoueursMaximum]; + } + + + public Joueur AjouterJoueur(string nom) + { + Joueur joueur = new Joueur(nom, new Plateau(TailleCodeMaximum, TourMaximum)); + joueurs[nbJoueurs++] = joueur; + return joueur; + } + + public Joueur JoueurCourant() + { + if (!joueurCourant.HasValue) + throw new PartieNonCommenceeException(); + + return joueurs[joueurCourant.Value]; + } + + public void PasserLaMain() + { + if (!joueurCourant.HasValue) + { + throw new PartieNonCommenceeException(); + } + + joueurCourant++; + if (joueurCourant >= joueurs.Length) + { + joueurCourant = 0; + } + + } + + + public Code GenererCode() + { + return new Code(TailleCodeMaximum); + } + + + public void CommencerLaPartie() + { + joueurCourant = 0; + } + + + public bool EstTerminee() + { + if (!joueurCourant.HasValue || joueurCourant != 0) + return false; + + if (JoueurCourant().Plateau.Tour > TourMaximum) + return true; + + for (int i = 0; i < joueurs.Length; ++i) + { + if (joueurs[i].Plateau.Victoire) + return true; + } + + return false; + } + + + public IEnumerable Gagnants() + { + Joueur[] gagnants = []; + for (int i = 0; i < joueurs.Length; ++i) + { + if (joueurs[i].Plateau.Victoire) + { + gagnants = gagnants.Append(joueurs[i]).ToArray(); + } + } + + return gagnants; + } + + public IEnumerable Perdants() + { + Joueur[] perdants = []; + for (int i = 0; i < joueurs.Length; ++i) + { + if (!joueurs[i].Plateau.Victoire) + { + perdants = perdants.Append(joueurs[i]).ToArray(); + } + } + + return perdants; + } + } +} From 0377774eb6c9b6183c3a203d3bb0a921f89f3c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9leste=20BARBOSA?= Date: Fri, 10 May 2024 11:27:48 +0200 Subject: [PATCH 08/36] Erreur compilation, oublie de suppresion --- Sources/ConsoleApp/Utils.cs | 239 ------------------------------------ 1 file changed, 239 deletions(-) delete mode 100644 Sources/ConsoleApp/Utils.cs diff --git a/Sources/ConsoleApp/Utils.cs b/Sources/ConsoleApp/Utils.cs deleted file mode 100644 index 76b1885..0000000 --- a/Sources/ConsoleApp/Utils.cs +++ /dev/null @@ -1,239 +0,0 @@ -using CoreLibrary; - -namespace ConsoleApp -{ - internal class Utils - { - private static int nombreJoueurs = 0; - - private readonly static int longueurTitre = 55; - - private readonly static Dictionary convertirCouleurs = new Dictionary() - { - {Couleur.NOIR, ConsoleColor.Black }, - {Couleur.BLANC, ConsoleColor.White }, - {Couleur.ROUGE, ConsoleColor.Red }, - {Couleur.VERT, ConsoleColor.Green }, - {Couleur.BLEU, ConsoleColor.Blue }, - {Couleur.JAUNE, ConsoleColor.Yellow } - }; - private readonly static Dictionary convertirIndicateurs = new Dictionary() - { - {Indicateur.BONNEPLACE, ConsoleColor.Black }, - {Indicateur.BONNECOULEUR, ConsoleColor.White } - }; - - public static void AfficherTitre() - { - - Console.WriteLine(""" - __ __ _ _ _ - | \/ | __ _ ___| |_ ___ _ _ _ __ (_) _ _ __| | - | |\/| |/ _` |(_-<| _|/ -_)| '_|| ' \ | || ' \ / _` | - |_| |_|\__,_|/__/ \__|\___||_| |_|_|_||_||_||_|\__,_| - """); - - AfficherSeparateur(); - } - - public static void AfficherTitre(string titre) - { - int taille = longueurTitre - titre.Length; - int gauche = taille > 0 ? taille / 2 : 0; - - Console.Write(titre.PadLeft(titre.Length + gauche)); - AfficherSeparateur(); - } - - public static void AfficherSeparateur() - { - Console.WriteLine(""" - - _______________________________________________________ - - - """); - } - - public static string SaisirNom() - { - string nom = $"Joueur {++nombreJoueurs}"; - - Console.WriteLine(nom); - Console.Write(">>> "); - nom = Console.ReadLine() ?? nom; - if (nom == "") - { - --nombreJoueurs; - throw new UtilsNomJoueurNullException(); - } - Console.WriteLine(); - - return nom; - } - - public static void DessinerJeton(Jeton jeton) - { - Console.Write(" "); - - Console.ForegroundColor = convertirCouleurs.GetValueOrDefault(jeton.Couleur); - Console.BackgroundColor = Console.ForegroundColor.Equals(ConsoleColor.Black) ? ConsoleColor.White : ConsoleColor.Black; - - Console.Write("⬤"); - - Console.ResetColor(); - - Console.Write(" "); - } - - public static void DessinerIndicateur(Indicateur indicateur) - { - Console.Write(" "); - - Console.ForegroundColor = convertirIndicateurs.GetValueOrDefault(indicateur); - Console.BackgroundColor = Console.ForegroundColor.Equals(ConsoleColor.Black) ? ConsoleColor.White : ConsoleColor.Black; - - Console.Write("⬤"); - - Console.ResetColor(); - - Console.Write(" "); - } - - public static void DessinerCode(IEnumerable jetons) - { - foreach (Jeton? jeton in jetons) - { - if (jeton.HasValue) - { - DessinerJeton(jeton.Value); - } - else - { - Console.Write(" "); - } - } - } - - - public static void DessinerIndicateurs(IEnumerable indicateurs) - { - if (indicateurs == null) - { - indicateurs = []; - } - - foreach (Indicateur indicateur in indicateurs) - { - DessinerIndicateur(indicateur); - } - - if (indicateurs.Count() < 4) - Console.Write("".PadLeft((4 - indicateurs.Count()) * 3)); - } - - public static void DessinerPlateau(IEnumerable> grille, IEnumerable> indicateurs) - { - IEnumerable[] grilleT = grille.ToArray(); - IEnumerable[] indicateursT = indicateurs.ToArray(); - - - Console.WriteLine(" Codes Indicateurs "); - Console.WriteLine("──────────────── ────────────────"); - Console.WriteLine("│ │ │ │"); - - for (int i = 0; i < grilleT.Length; ++i) - { - Console.Write("│ "); - DessinerCode(grilleT[i]); - Console.Write(" │"); - - Console.Write(" "); - - Console.Write("│ "); - DessinerIndicateurs(indicateursT[i]); - Console.WriteLine(" │"); - } - - Console.WriteLine("│ │ │ │"); - Console.WriteLine("──────────────── ────────────────"); - } - - - public static Jeton? ChoixJeton() - { - Console.TreatControlCAsInput = true; - - bool aChoisi = false; - int indice = 0; - Couleur[] couleurs = (Couleur[])Enum.GetValues(typeof(Couleur)); - Couleur couleur = couleurs[indice]; - - while (!aChoisi) - { - DessinerJeton(new Jeton(couleur)); - Console.Write("\b\b\b"); - - ConsoleKey touche = Console.ReadKey(true).Key; - - switch (touche) - { - case ConsoleKey.Enter: - aChoisi = true; - break; - - case ConsoleKey.LeftArrow: - --indice; - break; - - case ConsoleKey.RightArrow: - ++indice; - break; - - case ConsoleKey.Escape: - return null; - - default: - break; - } - - if (indice < 0) - indice = couleurs.Length - 1; - else if (indice >= couleurs.Length) - indice = 0; - - couleur = couleurs[indice]; - } - - Console.TreatControlCAsInput = false; - return new Jeton(couleur); - } - - public static void ChoixCode(ref Code code) - { - while (!code.EstComplet()) - { - Jeton? jeton = ChoixJeton(); - - if (jeton.HasValue) - { - DessinerJeton(jeton.Value); - code.AjouterJeton(jeton.Value); - } - else - { - Console.Write("\b\b\b \b\b\b\b\b\b\b\b\b\b\b\b"); - try - { - code.SupprimerDernierJeton(); - } - catch(CodeTableauLesJetonsVideException) - { - Console.WriteLine("Il n'y a pas de jetons! Impossible de supprimer"); - } - - } - } - } - } -} From 383845ff532ea35ea5e1d0bd6aae14ed71a1b906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9leste=20BARBOSA?= Date: Fri, 10 May 2024 11:28:03 +0200 Subject: [PATCH 09/36] N'a pas a exister, exception inutile --- Sources/ConsoleApp/UtilsNomJoueurNullException.cs | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 Sources/ConsoleApp/UtilsNomJoueurNullException.cs diff --git a/Sources/ConsoleApp/UtilsNomJoueurNullException.cs b/Sources/ConsoleApp/UtilsNomJoueurNullException.cs deleted file mode 100644 index 20187e7..0000000 --- a/Sources/ConsoleApp/UtilsNomJoueurNullException.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ConsoleApp -{ - public class UtilsNomJoueurNullException : Exception - { - public UtilsNomJoueurNullException() : base("Le nom du joueur est null") - { } - } -} From d6cbb5bac6c58d83291087b5ec38603e68d83ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9leste=20BARBOSA?= Date: Fri, 10 May 2024 11:29:00 +0200 Subject: [PATCH 10/36] A refaire, deja en cours --- Sources/ConsoleApp/Program.cs | 88 ----------------------------------- 1 file changed, 88 deletions(-) delete mode 100644 Sources/ConsoleApp/Program.cs diff --git a/Sources/ConsoleApp/Program.cs b/Sources/ConsoleApp/Program.cs deleted file mode 100644 index 475a617..0000000 --- a/Sources/ConsoleApp/Program.cs +++ /dev/null @@ -1,88 +0,0 @@ -using CoreLibrary; -using ConsoleApp; - - - -Console.OutputEncoding = System.Text.Encoding.UTF8; - -ReglesClassiques partie = new ReglesClassiques(); - -Utils.AfficherTitre(); - -Utils.AfficherTitre("Joueurs"); - -string joueur1; -string joueur2; - -while (true) -{ - try - { - joueur1 = Utils.SaisirNom(); - break; - } - catch(UtilsNomJoueurNullException) - { - Console.WriteLine("Nom invalide pour le joueur ! Ressaisir le nom"); - } -} - -while (true) -{ - try - { - joueur2 = Utils.SaisirNom(); - break; - } - catch (UtilsNomJoueurNullException) - { - Console.WriteLine("Nom invalide pour le joueur 2 ! Ressaisir le nom"); - } -} - -Utils.AfficherSeparateur(); - -partie.AjouterJoueur(joueur1); -partie.AjouterJoueur(joueur2); - -partie.CommencerLaPartie(); - -while (!partie.EstTerminee()) -{ - Console.WriteLine(partie.JoueurCourant().Nom); - Console.WriteLine(); - - Utils.DessinerPlateau(partie.JoueurCourant().Plateau.Grille(), partie.JoueurCourant().Plateau.Indicateurs()); - Console.WriteLine(); - - Code code = partie.GenererCode(); - - Utils.ChoixCode(ref code); - - partie.JoueurCourant().Plateau.AjouterCode(code); - - partie.PasserLaMain(); - - Utils.AfficherSeparateur(); -} - -Console.WriteLine("La partie est maintenant terminée !"); - -Joueur[] gagnants = partie.Gagnants().ToArray(); -Joueur[] perdants = partie.Perdants().ToArray(); - - - -if (gagnants.Length > 1) -{ - Console.WriteLine("C'est une égalité !"); -} -else if (gagnants.Length == 1) -{ - Console.WriteLine($"C'est une victoire de {gagnants[0].Nom}." + - $""); -} -else -{ - Console.WriteLine("C'est une défaite..."); -} From a755d8055bc3f56fb7ff8ed3c713bf722e71c57d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9leste=20BARBOSA?= Date: Fri, 10 May 2024 11:31:15 +0200 Subject: [PATCH 11/36] =?UTF-8?q?Ajout=20d'un=20console=20app=20vide=20pou?= =?UTF-8?q?r=20=C3=A9viter=20les=20erreurs=20de=20compilation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/ConsoleApp/Program.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Sources/ConsoleApp/Program.cs diff --git a/Sources/ConsoleApp/Program.cs b/Sources/ConsoleApp/Program.cs new file mode 100644 index 0000000..e69de29 From bae481b5e4b589722b75126d2e05aa700a990c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9leste=20BARBOSA?= Date: Fri, 10 May 2024 11:32:37 +0200 Subject: [PATCH 12/36] Hello ConsoleApp --- Sources/ConsoleApp/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/ConsoleApp/Program.cs b/Sources/ConsoleApp/Program.cs index e69de29..21751ed 100644 --- a/Sources/ConsoleApp/Program.cs +++ b/Sources/ConsoleApp/Program.cs @@ -0,0 +1 @@ +Console.WriteLine("Hello"); \ No newline at end of file From 0aa0621de481fc07f59aa77ff155cc6e9b3da4c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9leste=20BARBOSA?= Date: Fri, 10 May 2024 13:48:46 +0200 Subject: [PATCH 13/36] correction erreur comparer --- Sources/CoreLibrary/Code.cs | 272 ++++++++++++++++++------------------ 1 file changed, 136 insertions(+), 136 deletions(-) diff --git a/Sources/CoreLibrary/Code.cs b/Sources/CoreLibrary/Code.cs index 6081402..54dbcd0 100644 --- a/Sources/CoreLibrary/Code.cs +++ b/Sources/CoreLibrary/Code.cs @@ -1,136 +1,136 @@ -using CoreLibrary.Exceptions; - -namespace CoreLibrary -{ - public class Code - { - private readonly Jeton?[] lesJetons; - - public int NbJetons { get; private set; } = 0; - - public Code(int tailleCode) - { - if(tailleCode <= 0) - { - throw new TailleCodeException(tailleCode); - } - - lesJetons = new Jeton?[tailleCode]; - } - - public Code(IEnumerable jetons) - { - if (jetons.Count() == 0) - { - throw new TailleCodeException(jetons.Count()); - } - - lesJetons = new Jeton?[jetons.Count()]; - foreach(Jeton jeton in jetons) - { - AjouterJeton(jeton); - } - } - - public void AjouterJeton(Jeton jeton) - { - if (NbJetons == TailleMaximale()) - { - throw new CodeCompletException(); - } - - lesJetons[NbJetons++] = jeton; - } - - public void SupprimerDernierJeton() - { - if(NbJetons == 0) - { - throw new CodeVideException(); - } - - lesJetons[--NbJetons] = null; - } - - public Jeton RecupererJeton(int indice) - { - if(indice < 0 || indice > TailleMaximale()) - throw new IndiceCodeException(indice, NbJetons-1); - - Jeton? jeton = lesJetons[indice]; - - if (!jeton.HasValue) - throw new IndiceCodeException(indice, NbJetons-1); - - return jeton.Value; - } - - public IEnumerable Jetons() - { - return lesJetons; - } - - public bool EstComplet() - { - return NbJetons == lesJetons.Length; - } - - public int TailleMaximale() - { - return lesJetons.Length; - } - - public IEnumerable Comparer(Code autreCode) - { - // Mon code est le code correct, l'autre code est celui qui teste - - Indicateur[] indicateurs = []; - - if (EstComplet() || !autreCode.EstComplet()) - return indicateurs; - - Jeton?[] mesJetons = Jetons().ToArray(); - Jeton?[] sesJetons = autreCode.Jetons().ToArray(); - - for (int i = 0; i < mesJetons.Length; ++i) - { - Jeton? monJeton = mesJetons[i]; - Jeton? sonJeton = sesJetons[i]; - - if (monJeton.HasValue && sonJeton.HasValue && monJeton.Value.Couleur.Equals(sonJeton.Value.Couleur)) - { - indicateurs = indicateurs.Append(Indicateur.BONNEPLACE).ToArray(); - mesJetons[i] = null; - sesJetons[i] = null; - } - } - - - for (int i = 0; i < sesJetons.Length; ++i) - { - Jeton? sonJeton = sesJetons[i]; - - if (sonJeton.HasValue) - { - for (int j = 0; j < mesJetons.Length; ++j) - { - Jeton? monJeton = mesJetons[j]; - - if (monJeton.HasValue && sonJeton.Value.Couleur.Equals(monJeton.Value.Couleur)) - { - indicateurs = indicateurs.Append(Indicateur.BONNECOULEUR).ToArray(); - mesJetons[j] = null; - sesJetons[i] = null; - break; - } - - } - } - } - - return indicateurs; - } - } -} - - +using CoreLibrary.Exceptions; + +namespace CoreLibrary +{ + public class Code + { + private readonly Jeton?[] lesJetons; + + public int NbJetons { get; private set; } = 0; + + public Code(int tailleCode) + { + if(tailleCode <= 0) + { + throw new TailleCodeException(tailleCode); + } + + lesJetons = new Jeton?[tailleCode]; + } + + public Code(IEnumerable jetons) + { + if (jetons.Count() == 0) + { + throw new TailleCodeException(jetons.Count()); + } + + lesJetons = new Jeton?[jetons.Count()]; + foreach(Jeton jeton in jetons) + { + AjouterJeton(jeton); + } + } + + public void AjouterJeton(Jeton jeton) + { + if (NbJetons == TailleMaximale()) + { + throw new CodeCompletException(); + } + + lesJetons[NbJetons++] = jeton; + } + + public void SupprimerDernierJeton() + { + if(NbJetons == 0) + { + throw new CodeVideException(); + } + + lesJetons[--NbJetons] = null; + } + + public Jeton RecupererJeton(int indice) + { + if(indice < 0 || indice > TailleMaximale()) + throw new IndiceCodeException(indice, NbJetons-1); + + Jeton? jeton = lesJetons[indice]; + + if (!jeton.HasValue) + throw new IndiceCodeException(indice, NbJetons-1); + + return jeton.Value; + } + + public IEnumerable Jetons() + { + return lesJetons; + } + + public bool EstComplet() + { + return NbJetons == lesJetons.Length; + } + + public int TailleMaximale() + { + return lesJetons.Length; + } + + public IEnumerable Comparer(Code autreCode) + { + // Mon code est le code correct, l'autre code est celui qui teste + + Indicateur[] indicateurs = []; + + if (!EstComplet() || !autreCode.EstComplet()) + return indicateurs; + + Jeton?[] mesJetons = Jetons().ToArray(); + Jeton?[] sesJetons = autreCode.Jetons().ToArray(); + + for (int i = 0; i < mesJetons.Length; ++i) + { + Jeton? monJeton = mesJetons[i]; + Jeton? sonJeton = sesJetons[i]; + + if (monJeton.HasValue && sonJeton.HasValue && monJeton.Value.Couleur.Equals(sonJeton.Value.Couleur)) + { + indicateurs = indicateurs.Append(Indicateur.BONNEPLACE).ToArray(); + mesJetons[i] = null; + sesJetons[i] = null; + } + } + + + for (int i = 0; i < sesJetons.Length; ++i) + { + Jeton? sonJeton = sesJetons[i]; + + if (sonJeton.HasValue) + { + for (int j = 0; j < mesJetons.Length; ++j) + { + Jeton? monJeton = mesJetons[j]; + + if (monJeton.HasValue && sonJeton.Value.Couleur.Equals(monJeton.Value.Couleur)) + { + indicateurs = indicateurs.Append(Indicateur.BONNECOULEUR).ToArray(); + mesJetons[j] = null; + sesJetons[i] = null; + break; + } + + } + } + } + + return indicateurs; + } + } +} + + From 78c938384e5b40a5c19c631ffdc3753a32f3b3d1 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Fri, 10 May 2024 14:00:43 +0200 Subject: [PATCH 14/36] Partie consoleapp --- Sources/ConsoleApp/Program.cs | 22 +- Sources/ConsoleApp/Utils.cs | 233 +++++++++--------- .../ConsoleApp/UtilsNomJoueurNullException.cs | 14 -- .../Events/DebutPartieEventArgs.cs | 4 - .../Events/DemanderJetonEventArgs.cs | 7 + .../Events/DemanderJoueurEventArgs.cs | 12 + .../Events/NouveauTourEventArgs.cs | 10 +- .../CoreLibrary/Events/PasserMainEventArgs.cs | 9 +- Sources/CoreLibrary/Partie.cs | 80 +++--- 9 files changed, 194 insertions(+), 197 deletions(-) delete mode 100644 Sources/ConsoleApp/UtilsNomJoueurNullException.cs create mode 100644 Sources/CoreLibrary/Events/DemanderJetonEventArgs.cs create mode 100644 Sources/CoreLibrary/Events/DemanderJoueurEventArgs.cs diff --git a/Sources/ConsoleApp/Program.cs b/Sources/ConsoleApp/Program.cs index a43a2ae..c7dc2de 100644 --- a/Sources/ConsoleApp/Program.cs +++ b/Sources/ConsoleApp/Program.cs @@ -1,13 +1,21 @@ +using ConsoleApp; using CoreLibrary; -using CoreLibrary.Events; -void LaPartieDemarre(object sender, DebutPartieEventArgs evenement) -{ - Console.WriteLine("La partie commence"); -} +Console.OutputEncoding = System.Text.Encoding.UTF8; + +Utils.DessinerTitre(); Partie maPartie = new Partie(new ReglesClassiques()); -maPartie.debutPartie += LaPartieDemarre; -maPartie.Jouer(); +maPartie.DemanderJoueur += Utils.DemanderJoueur; + +maPartie.DebutPartie += Utils.CommencerLaPartie; +maPartie.NouveauTour += Utils.NouveauTour; +maPartie.DemanderJeton += Utils.DemanderJeton; +maPartie.AjouterJeton += Utils.AjouterJeton; +maPartie.AjouterCode += Utils.AjouterCode; +maPartie.PartieTerminee += Utils.PartieTerminee; + + +maPartie.Jouer(); \ No newline at end of file diff --git a/Sources/ConsoleApp/Utils.cs b/Sources/ConsoleApp/Utils.cs index 76b1885..d6157ee 100644 --- a/Sources/ConsoleApp/Utils.cs +++ b/Sources/ConsoleApp/Utils.cs @@ -1,31 +1,30 @@ using CoreLibrary; +using CoreLibrary.Events; +using System.Collections.Generic; +using System.Reflection; namespace ConsoleApp { - internal class Utils + public class Utils { - private static int nombreJoueurs = 0; - - private readonly static int longueurTitre = 55; - - private readonly static Dictionary convertirCouleurs = new Dictionary() + private readonly static Dictionary couleursTerminal = new Dictionary() { {Couleur.NOIR, ConsoleColor.Black }, {Couleur.BLANC, ConsoleColor.White }, {Couleur.ROUGE, ConsoleColor.Red }, {Couleur.VERT, ConsoleColor.Green }, {Couleur.BLEU, ConsoleColor.Blue }, - {Couleur.JAUNE, ConsoleColor.Yellow } + {Couleur.JAUNE, ConsoleColor.DarkYellow } }; - private readonly static Dictionary convertirIndicateurs = new Dictionary() + + private readonly static Dictionary indicateursTerminal = new Dictionary() { {Indicateur.BONNEPLACE, ConsoleColor.Black }, {Indicateur.BONNECOULEUR, ConsoleColor.White } }; - public static void AfficherTitre() + public static void DessinerTitre() { - Console.WriteLine(""" __ __ _ _ _ | \/ | __ _ ___| |_ ___ _ _ _ __ (_) _ _ __| | @@ -33,50 +32,28 @@ namespace ConsoleApp |_| |_|\__,_|/__/ \__|\___||_| |_|_|_||_||_||_|\__,_| """); - AfficherSeparateur(); + DessinerSeparateur(); } + - public static void AfficherTitre(string titre) - { - int taille = longueurTitre - titre.Length; - int gauche = taille > 0 ? taille / 2 : 0; - - Console.Write(titre.PadLeft(titre.Length + gauche)); - AfficherSeparateur(); - } - - public static void AfficherSeparateur() + public static void DessinerSeparateur() { Console.WriteLine(""" - _______________________________________________________ + ─────────────────────────────────────────────────────── """); } - public static string SaisirNom() - { - string nom = $"Joueur {++nombreJoueurs}"; - - Console.WriteLine(nom); - Console.Write(">>> "); - nom = Console.ReadLine() ?? nom; - if (nom == "") - { - --nombreJoueurs; - throw new UtilsNomJoueurNullException(); - } - Console.WriteLine(); - - return nom; - } - - public static void DessinerJeton(Jeton jeton) + public static void DessinerPion(Enum pion) { Console.Write(" "); - Console.ForegroundColor = convertirCouleurs.GetValueOrDefault(jeton.Couleur); + Console.ForegroundColor = pion.GetType().Equals(typeof(Couleur)) ? + couleursTerminal.GetValueOrDefault((Couleur) pion) : + indicateursTerminal.GetValueOrDefault((Indicateur) pion); + Console.BackgroundColor = Console.ForegroundColor.Equals(ConsoleColor.Black) ? ConsoleColor.White : ConsoleColor.Black; Console.Write("⬤"); @@ -86,97 +63,113 @@ namespace ConsoleApp Console.Write(" "); } - public static void DessinerIndicateur(Indicateur indicateur) + public static void DessinerPlateau(IEnumerable> grille, IEnumerable> indicateurs) { - Console.Write(" "); + IEnumerable[] grilleTableau = (IEnumerable[]) grille.ToArray(); + IEnumerable[] indicateursTableau = (IEnumerable[]) indicateurs.ToArray(); - Console.ForegroundColor = convertirIndicateurs.GetValueOrDefault(indicateur); - Console.BackgroundColor = Console.ForegroundColor.Equals(ConsoleColor.Black) ? ConsoleColor.White : ConsoleColor.Black; + Console.WriteLine(" Codes Indicateurs "); + Console.WriteLine("──────────────── ────────────────"); + Console.WriteLine("│ │ │ │"); - Console.Write("⬤"); + for (int i = 0; i < grille.Count(); ++i) + { + Console.Write("│ "); - Console.ResetColor(); + Jeton?[] ligneGrille = grilleTableau[i].ToArray(); - Console.Write(" "); - } + for (int j = 0; j < ligneGrille.Length; ++j) + { + Jeton? jeton = ligneGrille[j]; - public static void DessinerCode(IEnumerable jetons) - { - foreach (Jeton? jeton in jetons) - { - if (jeton.HasValue) + if(jeton.HasValue) + { + DessinerPion(jeton.Value.Couleur); + } + else + { + Console.Write(" "); + } + + } + + Console.Write(" │ │ "); + + if(indicateursTableau[i] != null) { - DessinerJeton(jeton.Value); + Indicateur[] ligneIndicateurs = indicateursTableau[i].ToArray(); + + for (int j = 0; j < ligneIndicateurs.Length; ++j) + { + DessinerPion(ligneIndicateurs[j]); + } + + if (ligneIndicateurs.Length < 4) + { + Console.Write("".PadLeft((4 - ligneIndicateurs.Length) * 3)); + } } else { - Console.Write(" "); + Console.Write(" "); } + + Console.WriteLine(" │"); } + + + Console.WriteLine("│ │ │ │"); + Console.WriteLine("──────────────── ────────────────"); } - public static void DessinerIndicateurs(IEnumerable indicateurs) + public static string? DemanderJoueur(Object? sender, DemanderJoueurEventArgs e) { - if (indicateurs == null) - { - indicateurs = []; - } + Console.WriteLine($"Joueur {e.Numero}"); + Console.Write(">>> "); - foreach (Indicateur indicateur in indicateurs) - { - DessinerIndicateur(indicateur); - } + string? nom = Console.ReadLine(); - if (indicateurs.Count() < 4) - Console.Write("".PadLeft((4 - indicateurs.Count()) * 3)); + Console.WriteLine(); + + return nom; } - public static void DessinerPlateau(IEnumerable> grille, IEnumerable> indicateurs) + + public static void CommencerLaPartie(Object? sender, DebutPartieEventArgs e) { - IEnumerable[] grilleT = grille.ToArray(); - IEnumerable[] indicateursT = indicateurs.ToArray(); + DessinerSeparateur(); + Console.WriteLine("La partie commence, bonne chance Ă  tous !\n"); + } - Console.WriteLine(" Codes Indicateurs "); - Console.WriteLine("──────────────── ────────────────"); - Console.WriteLine("│ │ │ │"); + + public static void NouveauTour(Object? sender, NouveauTourEventArgs e) + { + DessinerSeparateur(); - for (int i = 0; i < grilleT.Length; ++i) - { - Console.Write("│ "); - DessinerCode(grilleT[i]); - Console.Write(" │"); + Console.WriteLine($"Tour {e.Tour} - {e.Joueur.Nom}\n"); - Console.Write(" "); + DessinerPlateau(e.Grille, e.Indicateurs); - Console.Write("│ "); - DessinerIndicateurs(indicateursT[i]); - Console.WriteLine(" │"); - } + Console.WriteLine(); - Console.WriteLine("│ │ │ │"); - Console.WriteLine("──────────────── ────────────────"); } - - public static Jeton? ChoixJeton() + public static Jeton DemanderJeton(Object? sender, DemanderJetonEventArgs e) { Console.TreatControlCAsInput = true; bool aChoisi = false; int indice = 0; Couleur[] couleurs = (Couleur[])Enum.GetValues(typeof(Couleur)); - Couleur couleur = couleurs[indice]; while (!aChoisi) { - DessinerJeton(new Jeton(couleur)); + DessinerPion(couleurs[indice]); Console.Write("\b\b\b"); - ConsoleKey touche = Console.ReadKey(true).Key; - - switch (touche) + switch (Console.ReadKey(true).Key) { case ConsoleKey.Enter: aChoisi = true; @@ -190,8 +183,8 @@ namespace ConsoleApp ++indice; break; - case ConsoleKey.Escape: - return null; + /*case ConsoleKey.Escape: + return null;*/ default: break; @@ -201,38 +194,40 @@ namespace ConsoleApp indice = couleurs.Length - 1; else if (indice >= couleurs.Length) indice = 0; - - couleur = couleurs[indice]; } Console.TreatControlCAsInput = false; - return new Jeton(couleur); + + return new Jeton(couleurs[indice]); } - public static void ChoixCode(ref Code code) + public static void AjouterJeton(Object? sender, AjouterJetonEventArgs e) { - while (!code.EstComplet()) - { - Jeton? jeton = ChoixJeton(); + DessinerPion(e.Jeton.Couleur); + } - if (jeton.HasValue) - { - DessinerJeton(jeton.Value); - code.AjouterJeton(jeton.Value); - } - else - { - Console.Write("\b\b\b \b\b\b\b\b\b\b\b\b\b\b\b"); - try - { - code.SupprimerDernierJeton(); - } - catch(CodeTableauLesJetonsVideException) - { - Console.WriteLine("Il n'y a pas de jetons! Impossible de supprimer"); - } - - } + public static void AjouterCode(Object? sender, AjouterCodeEventArgs e) + { + Console.WriteLine(); + + DessinerSeparateur(); + } + + public static void PartieTerminee(Object? sender, PartieTermineeEventArgs e) + { + Joueur[] gagnants = e.Gagnants.ToArray(); + + if (gagnants.Length > 1) + { + Console.WriteLine("C'est une Ă©galitĂ© !"); + } + else if (gagnants.Length == 1) + { + Console.WriteLine($"C'est une victoire de {gagnants[0].Nom}."); + } + else + { + Console.WriteLine("C'est une dĂ©faite des deux joueurs..."); } } } diff --git a/Sources/ConsoleApp/UtilsNomJoueurNullException.cs b/Sources/ConsoleApp/UtilsNomJoueurNullException.cs deleted file mode 100644 index 20187e7..0000000 --- a/Sources/ConsoleApp/UtilsNomJoueurNullException.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ConsoleApp -{ - public class UtilsNomJoueurNullException : Exception - { - public UtilsNomJoueurNullException() : base("Le nom du joueur est null") - { } - } -} diff --git a/Sources/CoreLibrary/Events/DebutPartieEventArgs.cs b/Sources/CoreLibrary/Events/DebutPartieEventArgs.cs index 93745af..5b830a7 100644 --- a/Sources/CoreLibrary/Events/DebutPartieEventArgs.cs +++ b/Sources/CoreLibrary/Events/DebutPartieEventArgs.cs @@ -2,9 +2,5 @@ { public class DebutPartieEventArgs : EventArgs { - - public DebutPartieEventArgs() - { - } } } diff --git a/Sources/CoreLibrary/Events/DemanderJetonEventArgs.cs b/Sources/CoreLibrary/Events/DemanderJetonEventArgs.cs new file mode 100644 index 0000000..e2a982b --- /dev/null +++ b/Sources/CoreLibrary/Events/DemanderJetonEventArgs.cs @@ -0,0 +1,7 @@ + +namespace CoreLibrary.Events +{ + public class DemanderJetonEventArgs : EventArgs + { + } +} diff --git a/Sources/CoreLibrary/Events/DemanderJoueurEventArgs.cs b/Sources/CoreLibrary/Events/DemanderJoueurEventArgs.cs new file mode 100644 index 0000000..9b38733 --- /dev/null +++ b/Sources/CoreLibrary/Events/DemanderJoueurEventArgs.cs @@ -0,0 +1,12 @@ +namespace CoreLibrary.Events +{ + public class DemanderJoueurEventArgs : EventArgs + { + public int Numero { get; private set; } + + public DemanderJoueurEventArgs(int numero) + { + Numero = numero; + } + } +} diff --git a/Sources/CoreLibrary/Events/NouveauTourEventArgs.cs b/Sources/CoreLibrary/Events/NouveauTourEventArgs.cs index a6e297f..1a15771 100644 --- a/Sources/CoreLibrary/Events/NouveauTourEventArgs.cs +++ b/Sources/CoreLibrary/Events/NouveauTourEventArgs.cs @@ -1,14 +1,20 @@ -namespace CoreLibrary.Events +using CoreLibrary.Exceptions; + +namespace CoreLibrary.Events { public class NouveauTourEventArgs : EventArgs { public Joueur Joueur { get; private set; } public int Tour { get; private set; } + public IEnumerable> Grille { get; private set; } + public IEnumerable> Indicateurs { get; private set; } - public NouveauTourEventArgs(Joueur joueur, int tour) + public NouveauTourEventArgs(Joueur joueur, int tour, IEnumerable> grille, IEnumerable> indicateurs) { Joueur = joueur; Tour = tour; + Grille = grille; + Indicateurs = indicateurs; } } } \ No newline at end of file diff --git a/Sources/CoreLibrary/Events/PasserMainEventArgs.cs b/Sources/CoreLibrary/Events/PasserMainEventArgs.cs index 30999ad..fcff1f4 100644 --- a/Sources/CoreLibrary/Events/PasserMainEventArgs.cs +++ b/Sources/CoreLibrary/Events/PasserMainEventArgs.cs @@ -1,13 +1,6 @@ - -using System.Security.Cryptography.X509Certificates; - -namespace CoreLibrary.Events +namespace CoreLibrary.Events { public class PasserMainEventArgs : EventArgs { - public PasserMainEventArgs() - { - - } } } diff --git a/Sources/CoreLibrary/Partie.cs b/Sources/CoreLibrary/Partie.cs index 41a2bd9..c41b587 100644 --- a/Sources/CoreLibrary/Partie.cs +++ b/Sources/CoreLibrary/Partie.cs @@ -4,23 +4,33 @@ namespace CoreLibrary { public class Partie { - private IRegles regles; + private readonly IRegles regles; - public event EventHandler ajouterJoueur; - public event EventHandler debutPartie; - public event EventHandler nouveauTour; - public event EventHandler ajouterJeton; - public event EventHandler ajouterCode; - public event EventHandler passerMain; - public event EventHandler partieTerminee; + public delegate string? StringEventHandler(Object? sender, TEventArgs e); + public delegate Jeton JetonEventHandler(Object? sender, TEventArgs e); - private void QuandAjouterJoueur(Joueur joueur) => ajouterJoueur?.Invoke(this, new AjouterJoueursEventArgs(joueur)); - private void QuandDebutPartie() => debutPartie?.Invoke(this, new DebutPartieEventArgs()); - private void QuandNouveauTour(Joueur joueur, int tour) => nouveauTour?.Invoke(this, new NouveauTourEventArgs(joueur, tour)); - private void QuandNouveauJeton(Jeton jeton) => ajouterJeton?.Invoke(this, new AjouterJetonEventArgs(jeton)); - private void QuandNouveauCode(Code code) => ajouterCode?.Invoke(this, new AjouterCodeEventArgs(code)); - private void QuandPasserMain() => passerMain?.Invoke(this, new PasserMainEventArgs()); - private void QuandPartieTerminee(IEnumerable gagnants, IEnumerable perdants) => partieTerminee?.Invoke(this, new PartieTermineeEventArgs(gagnants, perdants)); + public event StringEventHandler? DemanderJoueur; + public event JetonEventHandler? DemanderJeton; + + public event EventHandler? AjouterJoueur; + public event EventHandler? DebutPartie; + public event EventHandler? NouveauTour; + public event EventHandler? AjouterJeton; + public event EventHandler? AjouterCode; + public event EventHandler? PasserMain; + public event EventHandler? PartieTerminee; + + private string? QuandDemanderJoueur(int numero) => DemanderJoueur?.Invoke(this, new DemanderJoueurEventArgs(numero)); + private Jeton? QuandDemanderJeton() => DemanderJeton?.Invoke(this, new DemanderJetonEventArgs()); + + + private void QuandAjouterJoueur(Joueur joueur) => AjouterJoueur?.Invoke(this, new AjouterJoueursEventArgs(joueur)); + private void QuandDebutPartie() => DebutPartie?.Invoke(this, new DebutPartieEventArgs()); + private void QuandNouveauTour(Joueur joueur, int tour, IEnumerable> grille, IEnumerable> indicateurs) => NouveauTour?.Invoke(this, new NouveauTourEventArgs(joueur, tour, grille, indicateurs)); + private void QuandNouveauJeton(Jeton jeton) => AjouterJeton?.Invoke(this, new AjouterJetonEventArgs(jeton)); + private void QuandNouveauCode(Code code) => AjouterCode?.Invoke(this, new AjouterCodeEventArgs(code)); + private void QuandPasserMain() => PasserMain?.Invoke(this, new PasserMainEventArgs()); + private void QuandPartieTerminee(IEnumerable gagnants, IEnumerable perdants) => PartieTerminee?.Invoke(this, new PartieTermineeEventArgs(gagnants, perdants)); public Partie(IRegles regles) @@ -30,7 +40,12 @@ namespace CoreLibrary public void Jouer() { - DefinirJoueurs(); + while (regles.NbJoueurs != regles.NbJoueursMaximum) + { + string nom = QuandDemanderJoueur(regles.NbJoueurs + 1) ?? $"Joueur {regles.NbJoueurs+1}"; + Joueur joueur = regles.AjouterJoueur(nom); + QuandAjouterJoueur(joueur); + } regles.CommencerLaPartie(); QuandDebutPartie(); @@ -40,14 +55,15 @@ namespace CoreLibrary Joueur joueurCourant = regles.JoueurCourant(); Plateau plateauCourant = joueurCourant.Plateau; - QuandNouveauTour(joueurCourant, plateauCourant.Tour); + QuandNouveauTour(joueurCourant, plateauCourant.Tour, plateauCourant.Grille(), plateauCourant.Indicateurs()); Code code = regles.GenererCode(); while (!code.EstComplet()) { - AjouterJeton(code); - + Jeton jeton = QuandDemanderJeton() ?? new Jeton(); + code.AjouterJeton(jeton); + QuandNouveauJeton(jeton); } plateauCourant.AjouterCode(code); QuandNouveauCode(code); @@ -56,33 +72,11 @@ namespace CoreLibrary QuandPasserMain(); } - PartieTerminee(); - QuandPartieTerminee(regles.Gagnants(), regles.Perdants()); - } - - private void AjouterJeton(Code code) - { - Jeton jeton = new Jeton(Couleur.ROUGE); - code.AjouterJeton(jeton); - QuandNouveauJeton(jeton); - } - - private void DefinirJoueurs() - { - while(regles.NbJoueurs != regles.NbJoueursMaximum) - { - string nom = "pauline"; - regles.AjouterJoueur(nom); - //QuandAjouterJoueur() - } - } - private void PartieTerminee() - { regles.Gagnants(); regles.Perdants(); - } - + QuandPartieTerminee(regles.Gagnants(), regles.Perdants()); + } } } From 43a0c68f723983174800c2c26864e5e9fd112690 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Fri, 10 May 2024 14:01:41 +0200 Subject: [PATCH 15/36] oublie indexation --- Sources/CoreLibrary/Code.cs | 3 ++- Sources/CoreLibrary/ReglesClassiques.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/CoreLibrary/Code.cs b/Sources/CoreLibrary/Code.cs index 4651bcb..0e1756e 100644 --- a/Sources/CoreLibrary/Code.cs +++ b/Sources/CoreLibrary/Code.cs @@ -84,9 +84,10 @@ namespace CoreLibrary { // Mon code est le code correct, l'autre code est celui qui teste + Indicateur[] indicateurs = []; - if (EstComplet() || !autreCode.EstComplet()) + if (!EstComplet() || !autreCode.EstComplet()) return indicateurs; Jeton?[] mesJetons = Jetons().ToArray(); diff --git a/Sources/CoreLibrary/ReglesClassiques.cs b/Sources/CoreLibrary/ReglesClassiques.cs index 53c3ef8..ef16576 100644 --- a/Sources/CoreLibrary/ReglesClassiques.cs +++ b/Sources/CoreLibrary/ReglesClassiques.cs @@ -24,7 +24,7 @@ namespace CoreLibrary public Joueur AjouterJoueur(string nom) { - Joueur joueur = new Joueur(nom, new Plateau(TailleCodeMaximum, TourMaximum)) + Joueur joueur = new Joueur(nom, new Plateau(TailleCodeMaximum, TourMaximum)); joueurs[nbJoueurs++] = joueur; return joueur; } From a91756c7e08d6f889e149dcd9821aad49c3172fc Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Fri, 10 May 2024 17:11:45 +0200 Subject: [PATCH 16/36] Ajout de la doc pour la class code --- Sources/CoreLibrary/Code.cs | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/Sources/CoreLibrary/Code.cs b/Sources/CoreLibrary/Code.cs index 54dbcd0..c6b61fd 100644 --- a/Sources/CoreLibrary/Code.cs +++ b/Sources/CoreLibrary/Code.cs @@ -1,13 +1,28 @@ using CoreLibrary.Exceptions; + + + + namespace CoreLibrary { + /// + /// ReprĂ©sente un code composĂ© de jetons. + /// public class Code { private readonly Jeton?[] lesJetons; + /// + /// Obtenir le nombre de jetons dans le code. + /// public int NbJetons { get; private set; } = 0; + /// + /// Initialise une nouvelle instance de la classe avec la longueur de code spĂ©cifiĂ©e. + /// + /// La longueur du code. + /// LevĂ©e lorsque la longueur du code spĂ©cifiĂ©e est infĂ©rieure ou Ă©gale Ă  zĂ©ro. public Code(int tailleCode) { if(tailleCode <= 0) @@ -18,6 +33,11 @@ namespace CoreLibrary lesJetons = new Jeton?[tailleCode]; } + /// + /// Initialise une nouvelle instance de la class avec les jetons spĂ©cifiĂ©s. + /// + /// Les jetons pour initaliser le code. + /// LevĂ©e lorsque la collection de jetons spĂ©cifiĂ©e est vide. public Code(IEnumerable jetons) { if (jetons.Count() == 0) @@ -32,6 +52,11 @@ namespace CoreLibrary } } + /// + /// Ajoute un jeton au code. + /// + /// Le jeton Ă  ajouter + /// LevĂ©e lorsque le code est plein. public void AjouterJeton(Jeton jeton) { if (NbJetons == TailleMaximale()) @@ -42,6 +67,10 @@ namespace CoreLibrary lesJetons[NbJetons++] = jeton; } + /// + /// Supprime le dernier jeton ajoutĂ© au code. + /// + /// LevĂ©e lorsque le code est vide. public void SupprimerDernierJeton() { if(NbJetons == 0) @@ -52,6 +81,12 @@ namespace CoreLibrary lesJetons[--NbJetons] = null; } + /// + /// RĂ©cupère le jeton Ă  l'indice spĂ©cifiĂ© dans le code. + /// + /// L'indice du jeton a rĂ©cupĂ©rĂ©. + /// Le jeton situĂ© Ă  l'indice spĂ©cifiĂ©. + /// LevĂ©e lorsque l'indice est supĂ©rieur Ă  la taille maximale du code, infĂ©rieur Ă  0 ou qu'il n'y a pas de jeton Ă  l'indice spĂ©cifiĂ© public Jeton RecupererJeton(int indice) { if(indice < 0 || indice > TailleMaximale()) @@ -65,33 +100,57 @@ namespace CoreLibrary return jeton.Value; } + /// + /// RĂ©cupère une Ă©numĂ©ration des jetons dans le code. + /// + /// EnumĂ©ration des jetons du code public IEnumerable Jetons() { return lesJetons; } + + + /// + /// VĂ©rifie si le code est complet. + /// + /// True si le code est complet, sinon False. public bool EstComplet() { return NbJetons == lesJetons.Length; } + /// + /// Recupère la taille maximal du code. + /// + /// Taille maximal du code. public int TailleMaximale() { return lesJetons.Length; } + + /// + /// Compare le code avec un autre code et gĂ©nère des indcateurs de correspondance. + /// + /// Le code Ă  comparer avec le code actuel + /// EnumĂ©ration d'indicateurs de correspondance entre les deux codes. public IEnumerable Comparer(Code autreCode) { // Mon code est le code correct, l'autre code est celui qui teste Indicateur[] indicateurs = []; + /// VĂ©rifie si les deux codes sont complets if (!EstComplet() || !autreCode.EstComplet()) return indicateurs; + /// Convertie les jetons des codes en tableaux. Jeton?[] mesJetons = Jetons().ToArray(); Jeton?[] sesJetons = autreCode.Jetons().ToArray(); + /// Compare les jetons pour dĂ©tecter les ceux Ă  la bonnes places + /// S'ils sont Ă  la bonne place alors ils sont enlever du tableau et un indicateur BONNEPLACE est ajouter au tableau des indicateurs. for (int i = 0; i < mesJetons.Length; ++i) { Jeton? monJeton = mesJetons[i]; @@ -106,6 +165,8 @@ namespace CoreLibrary } + /// Compare les jetons pour dĂ©tecter ceux qui ont la bonne couleur. + /// S'ils ont la bonne couleur alors ils sont enlever du tableau et un indicateur BONNECOULEUR est ajouter au tableau des indicateurs. for (int i = 0; i < sesJetons.Length; ++i) { Jeton? sonJeton = sesJetons[i]; From 61f4a5e918b293b3953685f2a0f97e43b88d166d Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Fri, 10 May 2024 17:35:37 +0200 Subject: [PATCH 17/36] Ajout de la doc pour la Couleurs, Indicateur, IRegles, Jeton, Joueur --- Sources/CoreLibrary/Couleur.cs | 3 ++ Sources/CoreLibrary/IRegles.cs | 55 +++++++++++++++++++++++++++++++ Sources/CoreLibrary/Indicateur.cs | 3 ++ Sources/CoreLibrary/Jeton.cs | 10 ++++++ Sources/CoreLibrary/Joueur.cs | 14 ++++++++ 5 files changed, 85 insertions(+) diff --git a/Sources/CoreLibrary/Couleur.cs b/Sources/CoreLibrary/Couleur.cs index 214cd87..ce25820 100644 --- a/Sources/CoreLibrary/Couleur.cs +++ b/Sources/CoreLibrary/Couleur.cs @@ -1,5 +1,8 @@ namespace CoreLibrary { + /// + /// ReprĂ©sente les couleurs disponible pour les jetons. + /// public enum Couleur { ROUGE, diff --git a/Sources/CoreLibrary/IRegles.cs b/Sources/CoreLibrary/IRegles.cs index 7c5c389..8f20344 100644 --- a/Sources/CoreLibrary/IRegles.cs +++ b/Sources/CoreLibrary/IRegles.cs @@ -1,25 +1,80 @@ namespace CoreLibrary { + /// + /// Interface dĂ©finissant les règles du jeu. + /// public interface IRegles { + /// + /// Obtient le nom des règles du jeu. + /// string Nom { get; } + /// + /// Obtient le nombre de maximum de tours. + /// int TourMaximum { get; } + + /// + /// Obtient la taille maximal du code. + /// int TailleCodeMaximum { get; } + /// + /// Obtient le nombre de joueurs actuels. + /// int NbJoueurs { get; } + + /// + /// Obtient le nombre de maximum de joueurs. + /// int NbJoueursMaximum { get; } + /// + /// Ajoute un joueur avec le nom spĂ©cifiĂ©. + /// + /// Nom du joueur Ă  ajouter + /// Le joueur ajoutĂ©. Joueur AjouterJoueur(string nom); + + /// + /// RĂ©cupère le joueur courant. + /// + /// Le joueur courant. Joueur JoueurCourant(); + + /// + /// Passe la main au joueur suivant. + /// void PasserLaMain(); + /// + /// GĂ©nère un code selon les règles du jeu. + /// + /// Le code gĂ©nĂ©rĂ©. Code GenererCode(); + /// + /// Initialise le premier joueur Ă  jouer. + /// void CommencerLaPartie(); + + /// + /// VĂ©rifie si la partie est terminĂ©e. + /// + /// True si la partie est terminĂ©e, sinon False. bool EstTerminee(); + /// + /// RĂ©cupère les joueurs gagnants. + /// + /// EnumĂ©ration des joueurs gagnants. IEnumerable Gagnants(); + + /// + /// RĂ©cupère les joueurs perdants. + /// + /// EnumĂ©ration des joueurs perdants. IEnumerable Perdants(); } } diff --git a/Sources/CoreLibrary/Indicateur.cs b/Sources/CoreLibrary/Indicateur.cs index 05e3689..d26b5da 100644 --- a/Sources/CoreLibrary/Indicateur.cs +++ b/Sources/CoreLibrary/Indicateur.cs @@ -1,5 +1,8 @@ namespace CoreLibrary { + /// + /// ReprĂ©sente les couleurs disponibles pour les indicateurs. + /// public enum Indicateur { BONNEPLACE, diff --git a/Sources/CoreLibrary/Jeton.cs b/Sources/CoreLibrary/Jeton.cs index b115aa2..9940127 100644 --- a/Sources/CoreLibrary/Jeton.cs +++ b/Sources/CoreLibrary/Jeton.cs @@ -1,9 +1,19 @@ namespace CoreLibrary { + /// + /// ReprĂ©sente un jetons de couleur. + /// public struct Jeton { + /// + /// Obtient la couleur du jeton. + /// public readonly Couleur Couleur { get; private init; } + /// + /// Initialise une nouvelle instance de la structure Jeton avec la couleur spĂ©cifiĂ©e. + /// + /// La couleur du jeton. public Jeton(Couleur couleur) { Couleur = couleur; diff --git a/Sources/CoreLibrary/Joueur.cs b/Sources/CoreLibrary/Joueur.cs index 48a1bbb..e8463bd 100644 --- a/Sources/CoreLibrary/Joueur.cs +++ b/Sources/CoreLibrary/Joueur.cs @@ -1,10 +1,24 @@ namespace CoreLibrary { + /// + /// ReprĂ©sente un joueur. + /// public class Joueur { + /// + /// Obtient le nom du joueur. + /// public string Nom { get; private init; } + /// + /// Obtient le plateau du joueur. + /// public Plateau Plateau { get; private init; } + /// + /// CrĂ©e une nouvelle instance de joueur avec un nom et un plateau spĂ©cifiĂ©. + /// + /// Le nom du joueur + /// Le plateau du joueur public Joueur(string nom, Plateau plateau) { Nom = nom; From 20031d21cfb51eed656525262cc1786239212834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9leste=20BARBOSA?= Date: Fri, 10 May 2024 17:54:35 +0200 Subject: [PATCH 18/36] nouvel UML ajout de la partie Partie et quelques corrections --- .../conception/diagramme_de_classes.md | 92 ++++++++++++++----- 1 file changed, 67 insertions(+), 25 deletions(-) diff --git a/Documentation/conception/diagramme_de_classes.md b/Documentation/conception/diagramme_de_classes.md index 5781895..1baeefd 100644 --- a/Documentation/conception/diagramme_de_classes.md +++ b/Documentation/conception/diagramme_de_classes.md @@ -1,5 +1,6 @@ ```plantuml + @startuml enum Couleur { @@ -16,24 +17,27 @@ enum Indicateur { BONNECOULEUR } -class Jeton { +struct Jeton { + --- + --- +Jeton(couleur: Couleur) } Jeton *--> Couleur: +Couleur: Couleur class Code { + --- + +NbJetons: int = 0 + --- +Code(tailleCode: int) - +Code(jetons: Jeton?[]) + +Code(jetons: Jeton[]) +AjouterJeton(jeton: Jeton): void +SupprimerDernierJeton(): void - +RecupererJeton(indice: int): void + +RecupererJeton(indice: int): Jeton +Jetons(): Jeton?[] +EstComplet(): bool +TailleMaximale(): int +Comparer(autreCode: Code): Indicateur[] - - +NbJetons: int = 0 } Code o--> Jeton: -lesJeton: Jeton?[] @@ -41,7 +45,10 @@ Code o--> Jeton: -lesJeton: Jeton?[] class Plateau { -random: Random -tailleCode: int - + --- + +Victoire: bool = false + +Tour: int = 1 + --- +Plateau(tailleCode: int, tailleGrille: int) +GenererCodeAleatoire(): void +EstComplet(): bool @@ -49,9 +56,6 @@ class Plateau { +EstBonCode(code: Code): bool +Grille(): Jeton?[][] +Indicateurs(): Indicateur[][] - - +Victoire: bool = false - +Tour: int = 1 } Plateau *--> Code: -codeSecret: Code @@ -60,16 +64,24 @@ Plateau *--> Indicateur: -indicateurs: Indicateur[][] class Joueur { - +Joueur(nom: string, plateau: Plateau) - + --- +Nom: string + --- + +Joueur(nom: string, plateau: Plateau) } Joueur *--> Plateau: +Plateau: Plateau interface IRegles { - +AjouterJoueur(joueur: string): void + --- + +Nom: string + +TourMaximum: int + +TailleCodeMaximum: int + +NbJoueurs: int + +NbJoueursMaximum: int + --- + +AjouterJoueur(joueur: string): Joueur +JoueurCourant(): Joueur +PasserLaMain(): void +GenererCode(): Code @@ -77,30 +89,60 @@ interface IRegles { +EstTerminee(): bool +Gagnants(): Joueur[] +Perdants(): Joueur[] - - +Nom: string - +TourMaximum: int - +TailleCodeMaximum: int - +NbJoueurs: int - +NbJoueursMaximum: int } class ReglesClassiques { - +nbJoueurs: int = 0 - +joueurCourant: int? - +joueurs: Joueur[] - - +ReglesClassiques() - + -nbJoueurs: int = 0 + -joueurCourant: int? + --- +Nom: string = "Règles classiques" +TourMaximum: int = 12 +TailleCodeMaximum: int = 4 +NbJoueurs: int +NbJoueursMaximum: int = 2 + --- + +ReglesClassiques() +} + +IRegles <|.. ReglesClassiques + +ReglesClassiques *--> Joueur: -joueurs: Joueur[] + + + +class Partie { + --- + +StringEventHandler(sender: Object?, e: TEventArgs): string? + +JetonEventHandler(sender: Object?, e: TEventArgs): Jeton + --- + +DemanderJoueur: StringEventHandler? + +DemanderJeton: JetonEventHandler? + +AjouterJoueur: EventHandler? + +DebutPartie: EventHandler? + +NouveauTour: EventHandler? + +NouveauJeton: EventHandler? + +NouveauCode: EventHandler? + +PasserMain: EventHandler? + +PartieTerminee: EventHandler? + --- + -QuandDemanderJoueur(int numero): string? + -QuandDemanderJeton(): Jeton? + -QuandAjouterJoueur(Joueur joueur): void + -QuandDebutPartie(): void + -QuandNouveauTour(Joueur joueur, int tour, Jeton?[][] grille, Indicateur[][] indicateurs): void + -QuandNouveauJeton(Jeton jeton): void + -QuandNouveauCode(Code: code): void + -QuandPasserMain(): void + -QuandPartieTerminee(Joueur[] gagnants, Joueur[] perdants): void + +Partie(IRegles regles) + +Jouer(): void } -ReglesClassiques ..|> IRegles + +Partie *--> IRegles: -regles: IRegles + + @enduml From 386ab06a84965667e2564519c530b695fcb65048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9leste=20BARBOSA?= Date: Fri, 10 May 2024 18:17:03 +0200 Subject: [PATCH 19/36] ajout du diagramme de paquetage --- .../conception/diagramme_de_paquetage.md | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Documentation/conception/diagramme_de_paquetage.md diff --git a/Documentation/conception/diagramme_de_paquetage.md b/Documentation/conception/diagramme_de_paquetage.md new file mode 100644 index 0000000..6c8f459 --- /dev/null +++ b/Documentation/conception/diagramme_de_paquetage.md @@ -0,0 +1,64 @@ +```plantuml + +@startuml + +package CoreLibrary <> { + package Core <> { + class Code + class Plateau + struct Jeton + enum Couleur + enum Indicateur + } + + package Joueurs <> { + class Joueur + } + + + package Regles <> { + interface IRegles + class ReglesClassiques + } + + package Evenements <> { + class AjouterCodeEventArgs + class AjouterJetonEventArgs + class AjouterJoueurEventArgs + class DebutPartieEventArgs + class DemanderJetonEventArgs + class DemanderJoueurEventArgs + class NouveauTourEventArgs + class PartieTermineeEventArgs + class PasserMainEventArgs + } + + package Exceptions <> { + class CodeCompletException + class CodeIncompletException + class CodeInvalideException + class CodeVideException + class GrilleCompleteException + class IndiceCodeException + class PartieNonCommenceeException + class TailleCodeException + class TailleGrilleException + } + + class Partie +} + +package ConsoleApp <> { + class Program + class Utils +} + +package System <> { + class Exception + class EventArgs + class Random +} + +@enduml + +``` \ No newline at end of file From feba0b85638fd24c0e9d4a4afaba730c46f396d6 Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Sat, 11 May 2024 13:47:39 +0200 Subject: [PATCH 20/36] Ajout de la doc pour Plateau, RegleClassique, Exception --- .../Exceptions/CodeCompletException.cs | 6 ++ .../Exceptions/CodeIncompletException.cs | 6 ++ .../Exceptions/CodeInvalideException.cs | 8 +++ .../Exceptions/CodeVideException.cs | 6 ++ .../Exceptions/GrilleCompleteException.cs | 6 ++ .../Exceptions/IndiceCodeException.cs | 8 +++ .../Exceptions/PartieNonCommenceeException.cs | 6 ++ .../Exceptions/TailleCodeException.cs | 7 +++ .../Exceptions/TailleGrilleException.cs | 7 +++ Sources/CoreLibrary/Plateau.cs | 45 ++++++++++++++ Sources/CoreLibrary/ReglesClassiques.cs | 62 +++++++++++++++++-- 11 files changed, 162 insertions(+), 5 deletions(-) diff --git a/Sources/CoreLibrary/Exceptions/CodeCompletException.cs b/Sources/CoreLibrary/Exceptions/CodeCompletException.cs index 3a560c0..a9fe1b5 100644 --- a/Sources/CoreLibrary/Exceptions/CodeCompletException.cs +++ b/Sources/CoreLibrary/Exceptions/CodeCompletException.cs @@ -1,7 +1,13 @@ namespace CoreLibrary.Exceptions { + /// + /// Exception levĂ©e lorsqu'un jeton est ajoutĂ© Ă  un code dĂ©jĂ  complet. + /// public class CodeCompletException : Exception { + /// + /// Initialise une nouvelle instance de la classe . + /// public CodeCompletException() : base("Le code dans lequel vous essayez d'ajouter un jeton est dĂ©jĂ  complet.") { } diff --git a/Sources/CoreLibrary/Exceptions/CodeIncompletException.cs b/Sources/CoreLibrary/Exceptions/CodeIncompletException.cs index 5e29af8..3d7642c 100644 --- a/Sources/CoreLibrary/Exceptions/CodeIncompletException.cs +++ b/Sources/CoreLibrary/Exceptions/CodeIncompletException.cs @@ -1,7 +1,13 @@ namespace CoreLibrary.Exceptions { + /// + /// Exception levĂ©e lorsqu'un code incomplet est ajoutĂ© Ă  la grille. + /// public class CodeIncompletException : Exception { + /// + /// Initialise une nouvelle instance de la classe . + /// public CodeIncompletException() : base("Le code que vous essayez d'ajouter dans la grille n'est pas complet.") { } diff --git a/Sources/CoreLibrary/Exceptions/CodeInvalideException.cs b/Sources/CoreLibrary/Exceptions/CodeInvalideException.cs index fe616e9..73c629d 100644 --- a/Sources/CoreLibrary/Exceptions/CodeInvalideException.cs +++ b/Sources/CoreLibrary/Exceptions/CodeInvalideException.cs @@ -1,7 +1,15 @@ namespace CoreLibrary.Exceptions { + /// + /// Exception levĂ©e lorsqu'un code avec une taille invalide est ajoutĂ© Ă  la grille. + /// public class CodeInvalideException : Exception { + /// + /// Initialise une nouvelle instance de la classe . + /// + /// La taille du code que vous essayez d'ajouter. + /// La taille du code que le plateau attend. public CodeInvalideException(int tailleCodeAjoute, int tailleCodePlateau) : base($"Le code que vous essayez d'ajouter est un code de taille {tailleCodeAjoute}, or le plateau attend un code de {tailleCodePlateau}.") { } diff --git a/Sources/CoreLibrary/Exceptions/CodeVideException.cs b/Sources/CoreLibrary/Exceptions/CodeVideException.cs index bc6c9d4..b05da88 100644 --- a/Sources/CoreLibrary/Exceptions/CodeVideException.cs +++ b/Sources/CoreLibrary/Exceptions/CodeVideException.cs @@ -1,7 +1,13 @@ namespace CoreLibrary.Exceptions { + /// + /// Exception levĂ©e lorsqu'un jeton est supprimĂ© d'un code qui est dĂ©jĂ  vide. + /// public class CodeVideException : Exception { + /// + /// Initialise une nouvelle instance de la classe . + /// public CodeVideException() : base("Le code dans lequel vous essayez de supprimer un jeton est dĂ©jĂ  vide.") { } diff --git a/Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs b/Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs index b7f8434..b02a9c0 100644 --- a/Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs +++ b/Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs @@ -1,7 +1,13 @@ namespace CoreLibrary.Exceptions { + /// + /// Exception levĂ©e lorsqu'un code est ajoutĂ© Ă  une grille qui est dĂ©jĂ  complète. + /// public class GrilleCompleteException : Exception { + /// + /// Initialise une nouvelle instance de la classe . + /// public GrilleCompleteException() : base("La grille dans laquelle vous essayez d'ajouter un code est dĂ©jĂ  complète.") { } diff --git a/Sources/CoreLibrary/Exceptions/IndiceCodeException.cs b/Sources/CoreLibrary/Exceptions/IndiceCodeException.cs index 8b3c0e5..f1b246a 100644 --- a/Sources/CoreLibrary/Exceptions/IndiceCodeException.cs +++ b/Sources/CoreLibrary/Exceptions/IndiceCodeException.cs @@ -1,7 +1,15 @@ namespace CoreLibrary.Exceptions { + /// + /// Exception levĂ©e lorsqu'un indice de jeton est invalide. + /// public class IndiceCodeException : Exception { + /// + /// Initialise une nouvelle instance de la classe . + /// + /// L'indice incorrect qui a Ă©tĂ© spĂ©cifiĂ©. + /// L'indice maximum permis. public IndiceCodeException(int indice, int indiceMax) : base($"Vous avez essayĂ© de rĂ©cupĂ©rer le jeton Ă  la place {indice}, mais son indice doit ĂŞtre compris entre 0 et {indiceMax}.") { } diff --git a/Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs b/Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs index 052bacc..b4768f7 100644 --- a/Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs +++ b/Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs @@ -1,7 +1,13 @@ namespace CoreLibrary.Exceptions { + /// + /// Exception levĂ©e lorsqu'une opĂ©ration est tentĂ©e alors que la partie n'a pas encore commencĂ©. + /// public class PartieNonCommenceeException : Exception { + /// + /// Initialise une nouvelle instance de la classe . + /// public PartieNonCommenceeException() : base("La partie n'a pas encore commencĂ©e.") { } diff --git a/Sources/CoreLibrary/Exceptions/TailleCodeException.cs b/Sources/CoreLibrary/Exceptions/TailleCodeException.cs index ebf67c9..5563cdd 100644 --- a/Sources/CoreLibrary/Exceptions/TailleCodeException.cs +++ b/Sources/CoreLibrary/Exceptions/TailleCodeException.cs @@ -1,7 +1,14 @@ namespace CoreLibrary.Exceptions { + /// + /// Exception levĂ©e lorsqu'une taille de code invalide est spĂ©cifiĂ©e. + /// public class TailleCodeException : Exception { + /// + /// Initialise une nouvelle instance de la classe . + /// + /// La taille du code spĂ©cifiĂ©e. public TailleCodeException(int taille) : base($"Un code doit avoir une taille positive non nulle, or il a reçu {taille}.") { } diff --git a/Sources/CoreLibrary/Exceptions/TailleGrilleException.cs b/Sources/CoreLibrary/Exceptions/TailleGrilleException.cs index 494e1ee..332b319 100644 --- a/Sources/CoreLibrary/Exceptions/TailleGrilleException.cs +++ b/Sources/CoreLibrary/Exceptions/TailleGrilleException.cs @@ -1,7 +1,14 @@ namespace CoreLibrary.Exceptions { + /// + /// Exception levĂ©e lorsqu'une taille de grille invalide est spĂ©cifiĂ©e. + /// public class TailleGrilleException : Exception { + /// + /// Initialise une nouvelle instance de la classe . + /// + /// La taille de grille spĂ©cifiĂ©e. public TailleGrilleException(int taille) : base($"Une grille doit avoir une taille positive non nulle, or elle a reçu {taille}.") { } diff --git a/Sources/CoreLibrary/Plateau.cs b/Sources/CoreLibrary/Plateau.cs index dd3bbff..5e421d3 100644 --- a/Sources/CoreLibrary/Plateau.cs +++ b/Sources/CoreLibrary/Plateau.cs @@ -2,6 +2,9 @@ namespace CoreLibrary { + /// + /// ReprĂ©sente un plateau de jeu composer de code + /// public class Plateau { private static Random random = new Random(); @@ -12,9 +15,23 @@ namespace CoreLibrary private readonly int tailleCode; + /// + /// Obtient le numĂ©ro de tour actuel. + /// public int Tour { get; private set; } = 1; + + /// + /// Obtient True si le joueur a gagnĂ© sinon False + /// public bool Victoire { get; private set; } = false; + /// + /// Initialise une nouvelle instance de la classe . + /// + /// Taille des codes du plateau + /// Taille du plateau de jeu + /// LevĂ©e lorsque la tailleCode est infĂ©rieur ou Ă©gal Ă  0. + /// LevĂ©e lorsque la tailleGrille est infĂ©rieur ou Ă©gal Ă  0. public Plateau(int tailleCode, int tailleGrille) { if(tailleCode <= 0) @@ -36,6 +53,9 @@ namespace CoreLibrary GenererCodeAleatoire(); } + /// + /// GĂ©nère un code secret alĂ©atoire en utilisant des jetons de couleurs alĂ©atoire. + /// private void GenererCodeAleatoire() { Couleur[] couleurs = (Couleur[])Enum.GetValues(typeof(Couleur)); @@ -46,11 +66,21 @@ namespace CoreLibrary } } + /// + /// VĂ©rifie si le plateau de jeu est plein. + /// + /// True si la tableau est plein, sinon False. public bool EstComplet() { return Tour - 1 == grille.Length; } + /// + /// Ajoute le code fourni au plateau de jeu. + /// + /// Le code Ă  ajouter au plateau de jeu. + /// LevĂ©e lorsque le code fourni Ă  une taille invalide. + /// LevĂ©e lorsque le code fourni est incomplet. public void AjouterCode(Code code) { if (code.TailleMaximale() != tailleCode) @@ -73,6 +103,13 @@ namespace CoreLibrary } } + /// + /// VĂ©rifie si le code fourni correspond au code secret. + /// + /// Le code Ă  vĂ©rifier. + /// True si le code fourni correspond au code secret, sinon False + /// LevĂ©e lorsque le code fourni Ă  une taille invalide. + /// LevĂ©e lorsque le code fourni est incomplet. public bool EstBonCode(Code code) { if (code.TailleMaximale() != tailleCode) @@ -103,6 +140,10 @@ namespace CoreLibrary return true; } + /// + /// RĂ©cupère le plateau de jeu. + /// + /// Le plateau de jeu reprĂ©sentĂ© sous forme d'une collections de jetons. public IEnumerable> Grille() { IEnumerable[] grilleJetons = new IEnumerable[grille.Length]; @@ -115,6 +156,10 @@ namespace CoreLibrary return grilleJetons; } + /// + /// RĂ©cupère les indicateurs pour chaque tour. + /// + /// Les indicateurs pour chaque tour reprĂ©sentĂ©s sous forme d'une collections d'indicateurs. public IEnumerable> Indicateurs() { return indicateurs; diff --git a/Sources/CoreLibrary/ReglesClassiques.cs b/Sources/CoreLibrary/ReglesClassiques.cs index 6aab766..e724f4c 100644 --- a/Sources/CoreLibrary/ReglesClassiques.cs +++ b/Sources/CoreLibrary/ReglesClassiques.cs @@ -2,26 +2,53 @@ namespace CoreLibrary { + /// + /// ImplĂ©mente les règles classiques du jeu. + /// public class ReglesClassiques : IRegles { private int nbJoueurs = 0; private int? joueurCourant; private readonly Joueur[] joueurs; + /// + /// Obtient le nom des règles. + /// public string Nom { get => "Règles classiques"; } + /// + /// Obtient le nombre maximum de tours. + /// public int TourMaximum { get => 12; } + + /// + /// Obtient la taille maximale d'un code. + /// public int TailleCodeMaximum { get => 4; } + + /// + /// Obtient le nombre de joueurs actuels dans le jeu. + /// public int NbJoueurs { get => nbJoueurs; } - public int NbJoueursMaximum { get => 2; } + /// + /// Obtient le nombre maximum de joueurs possible pour le jeu. + /// + public int NbJoueursMaximum { get => 2; } + /// + /// Initialise une nouvelle instance de la classe en initialisant un tableau de joueurs avec la taille maximale de joueurs autorisĂ©e. + /// public ReglesClassiques() { joueurs = new Joueur[NbJoueursMaximum]; } - + /// + /// Ajoute un joueur avec le nom spĂ©cifiĂ©. + /// + /// Le nom du joueur Ă  ajouter. + /// Le joueur ajoutĂ©. public Joueur AjouterJoueur(string nom) { Joueur joueur = new Joueur(nom, new Plateau(TailleCodeMaximum, TourMaximum)); @@ -29,6 +56,11 @@ namespace CoreLibrary return joueur; } + /// + /// Obtient le joueur dont c'est actuellement le tour. + /// + /// Le joueur actuel. + /// LevĂ©e lorsqu'il n'y a pas de joueur courant. public Joueur JoueurCourant() { if (!joueurCourant.HasValue) @@ -37,6 +69,10 @@ namespace CoreLibrary return joueurs[joueurCourant.Value]; } + /// + /// Passe la main au joueur suivant. + /// + /// LevĂ©e lorsqu'il n'y a pas de joueur courant. public void PasserLaMain() { if (!joueurCourant.HasValue) @@ -52,19 +88,27 @@ namespace CoreLibrary } - + /// + /// GĂ©nère un nouveau code. + /// + /// Le code gĂ©nĂ©rĂ© public Code GenererCode() { return new Code(TailleCodeMaximum); } - + /// + /// Initialise le premier joueur Ă  jouer. + /// public void CommencerLaPartie() { joueurCourant = 0; } - + /// + /// VĂ©rifie si la partie est terminĂ©e. + /// + /// True si la partie est terminĂ©e, sinon False. public bool EstTerminee() { if (!joueurCourant.HasValue || joueurCourant != 0) @@ -83,6 +127,10 @@ namespace CoreLibrary } + /// + /// Obtient les joueurs gagnants de la partie. + /// + /// La liste des joueurs gagnants. public IEnumerable Gagnants() { Joueur[] gagnants = []; @@ -97,6 +145,10 @@ namespace CoreLibrary return gagnants; } + /// + /// Obtient les joueurs perdants de la partie. + /// + /// La liste des joueurs perdants. public IEnumerable Perdants() { Joueur[] perdants = []; From dd8ed3c45f9046407dae32cc326ee84323542323 Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Sat, 11 May 2024 13:49:51 +0200 Subject: [PATCH 21/36] Ajout de la doc pour Plateau, RegleClassique, Exception --- Sources/CoreLibrary/ReglesClassiques.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/CoreLibrary/ReglesClassiques.cs b/Sources/CoreLibrary/ReglesClassiques.cs index e724f4c..7e9b090 100644 --- a/Sources/CoreLibrary/ReglesClassiques.cs +++ b/Sources/CoreLibrary/ReglesClassiques.cs @@ -3,7 +3,7 @@ namespace CoreLibrary { /// - /// ImplĂ©mente les règles classiques du jeu. + /// ImplĂ©mente les règles du jeu. /// public class ReglesClassiques : IRegles { From 84d05806d36e91f60b62cfbe5f2147aa448de1e8 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Sun, 12 May 2024 17:20:55 +0200 Subject: [PATCH 22/36] =?UTF-8?q?Ajout=20de=20la=20possibilit=C3=A9=20de?= =?UTF-8?q?=20supprimer=20le=20dernier=20jeton=20en=20faisant=20echap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/ConsoleApp/Evenements.cs | 121 ++++++++++++++++ Sources/ConsoleApp/Program.cs | 21 ++- Sources/ConsoleApp/Utils.cs | 132 ++---------------- .../Events/SupprimerDernierJetonEventArgs.cs | 6 + Sources/CoreLibrary/Partie.cs | 34 ++++- 5 files changed, 177 insertions(+), 137 deletions(-) create mode 100644 Sources/ConsoleApp/Evenements.cs create mode 100644 Sources/CoreLibrary/Events/SupprimerDernierJetonEventArgs.cs diff --git a/Sources/ConsoleApp/Evenements.cs b/Sources/ConsoleApp/Evenements.cs new file mode 100644 index 0000000..662f9ce --- /dev/null +++ b/Sources/ConsoleApp/Evenements.cs @@ -0,0 +1,121 @@ +using CoreLibrary.Events; +using CoreLibrary; + +namespace ConsoleApp +{ + public class Evenements + { + public static string? DemanderJoueur(Object? sender, DemanderJoueurEventArgs e) + { + Console.WriteLine($"Joueur {e.Numero}"); + Console.Write(">>> "); + + string? nom = Console.ReadLine(); + + Console.WriteLine(); + + return nom; + } + + + public static void CommencerLaPartie(Object? sender, DebutPartieEventArgs e) + { + Utils.DessinerSeparateur(); + + Console.WriteLine("La partie commence, bonne chance Ă  tous !\n"); + } + + + public static void NouveauTour(Object? sender, NouveauTourEventArgs e) + { + Utils.DessinerSeparateur(); + + Console.WriteLine($"Tour {e.Tour} - {e.Joueur.Nom}\n"); + + Utils.DessinerPlateau(e.Grille, e.Indicateurs); + + Console.WriteLine(); + + } + + public static Jeton? DemanderJeton(Object? sender, DemanderJetonEventArgs e) + { + Console.TreatControlCAsInput = true; + + bool aChoisi = false; + int indice = 0; + Couleur[] couleurs = (Couleur[])Enum.GetValues(typeof(Couleur)); + + while (!aChoisi) + { + Utils.DessinerPion(couleurs[indice]); + Console.Write("\b\b\b"); + + switch (Console.ReadKey(true).Key) + { + case ConsoleKey.Enter: + aChoisi = true; + break; + + case ConsoleKey.LeftArrow: + --indice; + break; + + case ConsoleKey.RightArrow: + ++indice; + break; + + case ConsoleKey.Escape: + return null; + + default: + break; + } + + if (indice < 0) + indice = couleurs.Length - 1; + else if (indice >= couleurs.Length) + indice = 0; + } + + Console.TreatControlCAsInput = false; + + return new Jeton(couleurs[indice]); + } + + public static void AjouterJeton(Object? sender, AjouterJetonEventArgs e) + { + Utils.DessinerPion(e.Jeton.Couleur); + } + + public static void SupprimerDernierJeton(Object? sender, SupprimerDernierJetonEventArgs e) + { + Console.Write("\b\b\b \b\b\b\b\b\b"); + } + + public static void AjouterCode(Object? sender, AjouterCodeEventArgs e) + { + Console.WriteLine(); + + Utils.DessinerSeparateur(); + } + + public static void PartieTerminee(Object? sender, PartieTermineeEventArgs e) + { + Joueur[] gagnants = e.Gagnants.ToArray(); + + if (gagnants.Length > 1) + { + Console.WriteLine("C'est une Ă©galitĂ© !"); + } + else if (gagnants.Length == 1) + { + Console.WriteLine($"C'est une victoire de {gagnants[0].Nom}."); + } + else + { + Console.WriteLine("C'est une dĂ©faite des deux joueurs..."); + } + } + } +} diff --git a/Sources/ConsoleApp/Program.cs b/Sources/ConsoleApp/Program.cs index c7dc2de..cb384c3 100644 --- a/Sources/ConsoleApp/Program.cs +++ b/Sources/ConsoleApp/Program.cs @@ -8,14 +8,13 @@ Utils.DessinerTitre(); Partie maPartie = new Partie(new ReglesClassiques()); -maPartie.DemanderJoueur += Utils.DemanderJoueur; - -maPartie.DebutPartie += Utils.CommencerLaPartie; -maPartie.NouveauTour += Utils.NouveauTour; -maPartie.DemanderJeton += Utils.DemanderJeton; -maPartie.AjouterJeton += Utils.AjouterJeton; -maPartie.AjouterCode += Utils.AjouterCode; -maPartie.PartieTerminee += Utils.PartieTerminee; - - -maPartie.Jouer(); \ No newline at end of file +maPartie.DemanderJoueur += Evenements.DemanderJoueur; +maPartie.DebutPartie += Evenements.CommencerLaPartie; +maPartie.NouveauTour += Evenements.NouveauTour; +maPartie.DemanderJeton += Evenements.DemanderJeton; +maPartie.AjouterJeton += Evenements.AjouterJeton; +maPartie.SupprimerDernierJeton += Evenements.SupprimerDernierJeton; +maPartie.AjouterCode += Evenements.AjouterCode; +maPartie.PartieTerminee += Evenements.PartieTerminee; + +maPartie.Jouer(); diff --git a/Sources/ConsoleApp/Utils.cs b/Sources/ConsoleApp/Utils.cs index d6157ee..442fac5 100644 --- a/Sources/ConsoleApp/Utils.cs +++ b/Sources/ConsoleApp/Utils.cs @@ -1,7 +1,4 @@ using CoreLibrary; -using CoreLibrary.Events; -using System.Collections.Generic; -using System.Reflection; namespace ConsoleApp { @@ -34,7 +31,7 @@ namespace ConsoleApp DessinerSeparateur(); } - + public static void DessinerSeparateur() { @@ -50,9 +47,9 @@ namespace ConsoleApp { Console.Write(" "); - Console.ForegroundColor = pion.GetType().Equals(typeof(Couleur)) ? - couleursTerminal.GetValueOrDefault((Couleur) pion) : - indicateursTerminal.GetValueOrDefault((Indicateur) pion); + Console.ForegroundColor = pion.GetType().Equals(typeof(Couleur)) ? + couleursTerminal.GetValueOrDefault((Couleur)pion) : + indicateursTerminal.GetValueOrDefault((Indicateur)pion); Console.BackgroundColor = Console.ForegroundColor.Equals(ConsoleColor.Black) ? ConsoleColor.White : ConsoleColor.Black; @@ -65,8 +62,8 @@ namespace ConsoleApp public static void DessinerPlateau(IEnumerable> grille, IEnumerable> indicateurs) { - IEnumerable[] grilleTableau = (IEnumerable[]) grille.ToArray(); - IEnumerable[] indicateursTableau = (IEnumerable[]) indicateurs.ToArray(); + IEnumerable[] grilleTableau = (IEnumerable[])grille.ToArray(); + IEnumerable[] indicateursTableau = (IEnumerable[])indicateurs.ToArray(); Console.WriteLine(" Codes Indicateurs "); Console.WriteLine("──────────────── ────────────────"); @@ -82,7 +79,7 @@ namespace ConsoleApp { Jeton? jeton = ligneGrille[j]; - if(jeton.HasValue) + if (jeton.HasValue) { DessinerPion(jeton.Value.Couleur); } @@ -90,12 +87,12 @@ namespace ConsoleApp { Console.Write(" "); } - + } Console.Write(" │ │ "); - - if(indicateursTableau[i] != null) + + if (indicateursTableau[i] != null) { Indicateur[] ligneIndicateurs = indicateursTableau[i].ToArray(); @@ -121,114 +118,5 @@ namespace ConsoleApp Console.WriteLine("│ │ │ │"); Console.WriteLine("──────────────── ────────────────"); } - - - public static string? DemanderJoueur(Object? sender, DemanderJoueurEventArgs e) - { - Console.WriteLine($"Joueur {e.Numero}"); - Console.Write(">>> "); - - string? nom = Console.ReadLine(); - - Console.WriteLine(); - - return nom; - } - - - public static void CommencerLaPartie(Object? sender, DebutPartieEventArgs e) - { - DessinerSeparateur(); - - Console.WriteLine("La partie commence, bonne chance Ă  tous !\n"); - } - - - public static void NouveauTour(Object? sender, NouveauTourEventArgs e) - { - DessinerSeparateur(); - - Console.WriteLine($"Tour {e.Tour} - {e.Joueur.Nom}\n"); - - DessinerPlateau(e.Grille, e.Indicateurs); - - Console.WriteLine(); - - } - - public static Jeton DemanderJeton(Object? sender, DemanderJetonEventArgs e) - { - Console.TreatControlCAsInput = true; - - bool aChoisi = false; - int indice = 0; - Couleur[] couleurs = (Couleur[])Enum.GetValues(typeof(Couleur)); - - while (!aChoisi) - { - DessinerPion(couleurs[indice]); - Console.Write("\b\b\b"); - - switch (Console.ReadKey(true).Key) - { - case ConsoleKey.Enter: - aChoisi = true; - break; - - case ConsoleKey.LeftArrow: - --indice; - break; - - case ConsoleKey.RightArrow: - ++indice; - break; - - /*case ConsoleKey.Escape: - return null;*/ - - default: - break; - } - - if (indice < 0) - indice = couleurs.Length - 1; - else if (indice >= couleurs.Length) - indice = 0; - } - - Console.TreatControlCAsInput = false; - - return new Jeton(couleurs[indice]); - } - - public static void AjouterJeton(Object? sender, AjouterJetonEventArgs e) - { - DessinerPion(e.Jeton.Couleur); - } - - public static void AjouterCode(Object? sender, AjouterCodeEventArgs e) - { - Console.WriteLine(); - - DessinerSeparateur(); - } - - public static void PartieTerminee(Object? sender, PartieTermineeEventArgs e) - { - Joueur[] gagnants = e.Gagnants.ToArray(); - - if (gagnants.Length > 1) - { - Console.WriteLine("C'est une Ă©galitĂ© !"); - } - else if (gagnants.Length == 1) - { - Console.WriteLine($"C'est une victoire de {gagnants[0].Nom}."); - } - else - { - Console.WriteLine("C'est une dĂ©faite des deux joueurs..."); - } - } } } diff --git a/Sources/CoreLibrary/Events/SupprimerDernierJetonEventArgs.cs b/Sources/CoreLibrary/Events/SupprimerDernierJetonEventArgs.cs new file mode 100644 index 0000000..4796efd --- /dev/null +++ b/Sources/CoreLibrary/Events/SupprimerDernierJetonEventArgs.cs @@ -0,0 +1,6 @@ +namespace CoreLibrary.Events +{ + public class SupprimerDernierJetonEventArgs : EventArgs + { + } +} diff --git a/Sources/CoreLibrary/Partie.cs b/Sources/CoreLibrary/Partie.cs index c41b587..d59ba5e 100644 --- a/Sources/CoreLibrary/Partie.cs +++ b/Sources/CoreLibrary/Partie.cs @@ -1,4 +1,5 @@ using CoreLibrary.Events; +using CoreLibrary.Exceptions; namespace CoreLibrary { @@ -7,7 +8,7 @@ namespace CoreLibrary private readonly IRegles regles; public delegate string? StringEventHandler(Object? sender, TEventArgs e); - public delegate Jeton JetonEventHandler(Object? sender, TEventArgs e); + public delegate Jeton? JetonEventHandler(Object? sender, TEventArgs e); public event StringEventHandler? DemanderJoueur; public event JetonEventHandler? DemanderJeton; @@ -16,6 +17,7 @@ namespace CoreLibrary public event EventHandler? DebutPartie; public event EventHandler? NouveauTour; public event EventHandler? AjouterJeton; + public event EventHandler? SupprimerDernierJeton; public event EventHandler? AjouterCode; public event EventHandler? PasserMain; public event EventHandler? PartieTerminee; @@ -28,6 +30,7 @@ namespace CoreLibrary private void QuandDebutPartie() => DebutPartie?.Invoke(this, new DebutPartieEventArgs()); private void QuandNouveauTour(Joueur joueur, int tour, IEnumerable> grille, IEnumerable> indicateurs) => NouveauTour?.Invoke(this, new NouveauTourEventArgs(joueur, tour, grille, indicateurs)); private void QuandNouveauJeton(Jeton jeton) => AjouterJeton?.Invoke(this, new AjouterJetonEventArgs(jeton)); + private void QuandSupprimerDernierJeton() => SupprimerDernierJeton?.Invoke(this, new SupprimerDernierJetonEventArgs()); private void QuandNouveauCode(Code code) => AjouterCode?.Invoke(this, new AjouterCodeEventArgs(code)); private void QuandPasserMain() => PasserMain?.Invoke(this, new PasserMainEventArgs()); private void QuandPartieTerminee(IEnumerable gagnants, IEnumerable perdants) => PartieTerminee?.Invoke(this, new PartieTermineeEventArgs(gagnants, perdants)); @@ -61,9 +64,32 @@ namespace CoreLibrary while (!code.EstComplet()) { - Jeton jeton = QuandDemanderJeton() ?? new Jeton(); - code.AjouterJeton(jeton); - QuandNouveauJeton(jeton); + Jeton? jeton = QuandDemanderJeton(); + + if(jeton == null) + { + if(DemanderJeton != null) + { + // Si quelqu'un Ă©coute l'Ă©vĂ©nement mais ne renvoie rien, alors on supprime le dernier jeton + try + { + code.SupprimerDernierJeton(); + QuandSupprimerDernierJeton(); + } + catch(CodeVideException){} + } + else + { + // Si personne n'Ă©coute l'Ă©venment, on met un jeton alĂ©atoire + jeton = new Jeton(); + } + } + + if(jeton != null) + { + code.AjouterJeton(jeton.Value); + QuandNouveauJeton(jeton.Value); + } } plateauCourant.AjouterCode(code); QuandNouveauCode(code); From 597275c96a473d34e7d091b337a90287385af522 Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Sun, 12 May 2024 21:37:14 +0200 Subject: [PATCH 23/36] =?UTF-8?q?Ajout=20de=20la=20doc=20pour=20les=20Ev?= =?UTF-8?q?=C3=A8nements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/ConsoleApp/Evenements.cs | 28 ++++++++- .../Events/AjouterCodeEventArgs.cs | 13 +++- .../Events/AjouterJetonEventArgs.cs | 11 ++++ .../Events/AjouterJoueursEventArgs.cs | 10 ++++ .../Events/DebutPartieEventArgs.cs | 3 + .../Events/DemanderJetonEventArgs.cs | 3 + .../Events/DemanderJoueurEventArgs.cs | 11 ++++ .../Events/NouveauTourEventArgs.cs | 25 ++++++++ .../Events/PartieTermineeEventArgs.cs | 15 +++++ .../CoreLibrary/Events/PasserMainEventArgs.cs | 3 + .../Events/SupprimerDernierJetonEventArgs.cs | 3 + Sources/CoreLibrary/ReglesClassiques.cs | 59 ++++++++++++++++++- 12 files changed, 180 insertions(+), 4 deletions(-) diff --git a/Sources/ConsoleApp/Evenements.cs b/Sources/ConsoleApp/Evenements.cs index 662f9ce..14068e9 100644 --- a/Sources/ConsoleApp/Evenements.cs +++ b/Sources/ConsoleApp/Evenements.cs @@ -3,8 +3,14 @@ using CoreLibrary; namespace ConsoleApp { + /// + /// Fournit des gestionnaires d'Ă©vĂ©nements les Ă©vĂ©nements liĂ©s au dĂ©roulement de la partie. + /// public class Evenements { + /// + /// Gestionnaire d'Ă©vĂ©nement pour l'ajout d'un joueur. + /// public static string? DemanderJoueur(Object? sender, DemanderJoueurEventArgs e) { Console.WriteLine($"Joueur {e.Numero}"); @@ -18,6 +24,9 @@ namespace ConsoleApp } + /// + /// Gestionnaire d'Ă©vĂ©nement pour le dĂ©but de la partie. + /// public static void CommencerLaPartie(Object? sender, DebutPartieEventArgs e) { Utils.DessinerSeparateur(); @@ -25,7 +34,9 @@ namespace ConsoleApp Console.WriteLine("La partie commence, bonne chance Ă  tous !\n"); } - + /// + /// Gestionnaire d'Ă©vĂ©nement pour le dĂ©but d'un nouveau tour. + /// public static void NouveauTour(Object? sender, NouveauTourEventArgs e) { Utils.DessinerSeparateur(); @@ -38,6 +49,9 @@ namespace ConsoleApp } + /// + /// Gestionnaire d'Ă©vĂ©nement pour la demande d'ajout d'un jeton. + /// public static Jeton? DemanderJeton(Object? sender, DemanderJetonEventArgs e) { Console.TreatControlCAsInput = true; @@ -83,16 +97,25 @@ namespace ConsoleApp return new Jeton(couleurs[indice]); } + /// + /// Gestionnaire d'Ă©vĂ©nement pour l'ajout d'un jeton. + /// public static void AjouterJeton(Object? sender, AjouterJetonEventArgs e) { Utils.DessinerPion(e.Jeton.Couleur); } + /// + /// Gestionnaire d'Ă©vĂ©nement pour la suppression du dernier jeton ajoutĂ©. + /// public static void SupprimerDernierJeton(Object? sender, SupprimerDernierJetonEventArgs e) { Console.Write("\b\b\b \b\b\b\b\b\b"); } + /// + /// Gestionnaire d'Ă©vĂ©nement pour l'ajout d'un code. + /// public static void AjouterCode(Object? sender, AjouterCodeEventArgs e) { Console.WriteLine(); @@ -100,6 +123,9 @@ namespace ConsoleApp Utils.DessinerSeparateur(); } + /// + /// Gestionnaire d'Ă©vĂ©nement pour la fin de la partie. + /// public static void PartieTerminee(Object? sender, PartieTermineeEventArgs e) { Joueur[] gagnants = e.Gagnants.ToArray(); diff --git a/Sources/CoreLibrary/Events/AjouterCodeEventArgs.cs b/Sources/CoreLibrary/Events/AjouterCodeEventArgs.cs index 3cd1c56..489fded 100644 --- a/Sources/CoreLibrary/Events/AjouterCodeEventArgs.cs +++ b/Sources/CoreLibrary/Events/AjouterCodeEventArgs.cs @@ -1,9 +1,20 @@  namespace CoreLibrary.Events { + /// + /// ReprĂ©sente les arguments d'Ă©vĂ©nement pour l'Ă©vĂ©nement de l'ajout d'un code. + /// public class AjouterCodeEventArgs : EventArgs { - public Code Code { get; private set; } + /// + /// Obtient le code ajoutĂ©. + /// + public Code Code { get; private set; } + + /// + /// Initialise une nouvelle instance de la classe avec le code spĂ©cifiĂ©. + /// + /// Le code Ă  ajouter. public AjouterCodeEventArgs(Code code) { Code = code; diff --git a/Sources/CoreLibrary/Events/AjouterJetonEventArgs.cs b/Sources/CoreLibrary/Events/AjouterJetonEventArgs.cs index 50b35ab..a19fcbf 100644 --- a/Sources/CoreLibrary/Events/AjouterJetonEventArgs.cs +++ b/Sources/CoreLibrary/Events/AjouterJetonEventArgs.cs @@ -2,9 +2,20 @@ namespace CoreLibrary.Events { + /// + /// ReprĂ©sente les arguments d'Ă©vĂ©nement pour l'Ă©vĂ©nement d'ajout d'un jeton. + /// public class AjouterJetonEventArgs : EventArgs { + /// + /// Obtient le jeton ajoutĂ©. + /// public Jeton Jeton { get; private set; } + + /// + /// Initialise une nouvelle instance de la classe avec le jeton spĂ©cifiĂ©. + /// + /// Le jeton Ă  ajouter. public AjouterJetonEventArgs(Jeton jeton) { Jeton = jeton; diff --git a/Sources/CoreLibrary/Events/AjouterJoueursEventArgs.cs b/Sources/CoreLibrary/Events/AjouterJoueursEventArgs.cs index 4fb2ddb..0e04345 100644 --- a/Sources/CoreLibrary/Events/AjouterJoueursEventArgs.cs +++ b/Sources/CoreLibrary/Events/AjouterJoueursEventArgs.cs @@ -1,9 +1,19 @@ namespace CoreLibrary.Events { + /// + /// ReprĂ©sente les arguments d'Ă©vĂ©nement pour l'Ă©vĂ©nement d'ajout d'un joueur. + /// public class AjouterJoueursEventArgs : EventArgs { + /// + /// Obtient le joueur ajoutĂ©. + /// public Joueur Joueur { get; private set; } + /// + /// Initialise une nouvelle instance de la classe avec le joueur spĂ©cifiĂ©. + /// + /// Le joueur Ă  ajouter. public AjouterJoueursEventArgs(Joueur joueur) { Joueur = joueur; diff --git a/Sources/CoreLibrary/Events/DebutPartieEventArgs.cs b/Sources/CoreLibrary/Events/DebutPartieEventArgs.cs index 5b830a7..631c7ca 100644 --- a/Sources/CoreLibrary/Events/DebutPartieEventArgs.cs +++ b/Sources/CoreLibrary/Events/DebutPartieEventArgs.cs @@ -1,5 +1,8 @@ namespace CoreLibrary.Events { + /// + /// ReprĂ©sente les arguments d'Ă©vĂ©nement pour le dĂ©but d'une partie. + /// public class DebutPartieEventArgs : EventArgs { } diff --git a/Sources/CoreLibrary/Events/DemanderJetonEventArgs.cs b/Sources/CoreLibrary/Events/DemanderJetonEventArgs.cs index e2a982b..41c2059 100644 --- a/Sources/CoreLibrary/Events/DemanderJetonEventArgs.cs +++ b/Sources/CoreLibrary/Events/DemanderJetonEventArgs.cs @@ -1,6 +1,9 @@  namespace CoreLibrary.Events { + /// + /// ReprĂ©sente les arguments d'Ă©vĂ©nement pour la demande d'ajout d'un jeton. + /// public class DemanderJetonEventArgs : EventArgs { } diff --git a/Sources/CoreLibrary/Events/DemanderJoueurEventArgs.cs b/Sources/CoreLibrary/Events/DemanderJoueurEventArgs.cs index 9b38733..42ed8c2 100644 --- a/Sources/CoreLibrary/Events/DemanderJoueurEventArgs.cs +++ b/Sources/CoreLibrary/Events/DemanderJoueurEventArgs.cs @@ -1,9 +1,20 @@ namespace CoreLibrary.Events { + /// + /// ReprĂ©sente les arguments d'Ă©vĂ©nement pour la demande d'ajout d'un joueur. + /// public class DemanderJoueurEventArgs : EventArgs { + /// + /// Obtient le numĂ©ro du joueur Ă  ajouter. + /// public int Numero { get; private set; } + + /// + /// Initialise une nouvelle instance de la classe avec le numĂ©ro du joueur spĂ©cifiĂ©. + /// + /// Le numĂ©ro du joueur Ă  ajouter. public DemanderJoueurEventArgs(int numero) { Numero = numero; diff --git a/Sources/CoreLibrary/Events/NouveauTourEventArgs.cs b/Sources/CoreLibrary/Events/NouveauTourEventArgs.cs index 1a15771..cc577b1 100644 --- a/Sources/CoreLibrary/Events/NouveauTourEventArgs.cs +++ b/Sources/CoreLibrary/Events/NouveauTourEventArgs.cs @@ -2,13 +2,38 @@ namespace CoreLibrary.Events { + /// + /// ReprĂ©sente les arguments d'Ă©vĂ©nement pour le dĂ©but d'un nouveau tour. + /// public class NouveauTourEventArgs : EventArgs { + /// + /// Obtient le joueur dont c'est le tour. + /// public Joueur Joueur { get; private set; } + + /// + /// Obtient le numĂ©ro du tour. + /// public int Tour { get; private set; } + + /// + /// Obtient la grille du joueur actuelle. + /// public IEnumerable> Grille { get; private set; } + + /// + /// Obtient les indicateurs de la grille de jeu. + /// public IEnumerable> Indicateurs { get; private set; } + /// + /// Initialise une nouvelle instance de la classe avec les informations spĂ©cifiĂ©es. + /// + /// Le joueur dont c'est le tour. + /// Le numĂ©ro du tour. + /// La grille du joueur actuelle. + /// Les indicateurs de la grille de jeu. public NouveauTourEventArgs(Joueur joueur, int tour, IEnumerable> grille, IEnumerable> indicateurs) { Joueur = joueur; diff --git a/Sources/CoreLibrary/Events/PartieTermineeEventArgs.cs b/Sources/CoreLibrary/Events/PartieTermineeEventArgs.cs index 094073c..955fc4e 100644 --- a/Sources/CoreLibrary/Events/PartieTermineeEventArgs.cs +++ b/Sources/CoreLibrary/Events/PartieTermineeEventArgs.cs @@ -6,11 +6,26 @@ using System.Threading.Tasks; namespace CoreLibrary.Events { + /// + /// ReprĂ©sente les arguments d'Ă©vĂ©nement pour la fin d'une partie. + /// public class PartieTermineeEventArgs : EventArgs { + /// + /// Obtient les joueurs gagnants de la partie. + /// public IEnumerable Gagnants { get; private set; } + + /// + /// Obtient les joueurs perdants de la partie. + /// public IEnumerable Perdants { get; private set; } + /// + /// Initialise une nouvelle instance de la classe avec les gagnants et les perdants spĂ©cifiĂ©s. + /// + /// Les joueurs gagnants de la partie. + /// Les joueurs perdants de la partie. public PartieTermineeEventArgs(IEnumerable gagnants, IEnumerable perdants) { Gagnants = gagnants; diff --git a/Sources/CoreLibrary/Events/PasserMainEventArgs.cs b/Sources/CoreLibrary/Events/PasserMainEventArgs.cs index fcff1f4..91df021 100644 --- a/Sources/CoreLibrary/Events/PasserMainEventArgs.cs +++ b/Sources/CoreLibrary/Events/PasserMainEventArgs.cs @@ -1,5 +1,8 @@ namespace CoreLibrary.Events { + /// + /// ReprĂ©sente les arguments d'Ă©vĂ©nement pour le passage de la main au joueur suivant. + /// public class PasserMainEventArgs : EventArgs { } diff --git a/Sources/CoreLibrary/Events/SupprimerDernierJetonEventArgs.cs b/Sources/CoreLibrary/Events/SupprimerDernierJetonEventArgs.cs index 4796efd..8ba6ae9 100644 --- a/Sources/CoreLibrary/Events/SupprimerDernierJetonEventArgs.cs +++ b/Sources/CoreLibrary/Events/SupprimerDernierJetonEventArgs.cs @@ -1,5 +1,8 @@ namespace CoreLibrary.Events { + /// + /// ReprĂ©sente les arguments d'Ă©vĂ©nement pour la suppression du dernier jeton ajoutĂ©. + /// public class SupprimerDernierJetonEventArgs : EventArgs { } diff --git a/Sources/CoreLibrary/ReglesClassiques.cs b/Sources/CoreLibrary/ReglesClassiques.cs index 6aab766..44950b5 100644 --- a/Sources/CoreLibrary/ReglesClassiques.cs +++ b/Sources/CoreLibrary/ReglesClassiques.cs @@ -2,26 +2,54 @@ namespace CoreLibrary { + /// + /// ImplĂ©mente les règles du jeu. + /// public class ReglesClassiques : IRegles { private int nbJoueurs = 0; private int? joueurCourant; private readonly Joueur[] joueurs; + /// + /// Obtient le nom des règles. + /// public string Nom { get => "Règles classiques"; } + /// + /// Obtient le nombre maximum de tours. + /// public int TourMaximum { get => 12; } + + /// + /// Obtient la taille maximale d'un code. + /// public int TailleCodeMaximum { get => 4; } + /// + /// Obtient le nombre de joueurs actuels dans le jeu. + /// public int NbJoueurs { get => nbJoueurs; } + /// + /// Obtient le nombre maximum de joueurs possible pour le jeu. + /// public int NbJoueursMaximum { get => 2; } + /// + /// Initialise une nouvelle instance de la classe en initialisant un tableau de joueurs avec la taille maximale de joueurs autorisĂ©e. + /// public ReglesClassiques() { joueurs = new Joueur[NbJoueursMaximum]; } + + /// + /// Ajoute un joueur avec le nom spĂ©cifiĂ©. + /// + /// Le nom du joueur Ă  ajouter. + /// Le joueur ajoutĂ©. public Joueur AjouterJoueur(string nom) { Joueur joueur = new Joueur(nom, new Plateau(TailleCodeMaximum, TourMaximum)); @@ -29,6 +57,12 @@ namespace CoreLibrary return joueur; } + /// + /// Obtient le joueur dont c'est actuellement le tour. + /// + /// Le joueur actuel. + /// LevĂ©e lorsqu'il n'y a pas de joueur courant. + public Joueur JoueurCourant() { if (!joueurCourant.HasValue) @@ -37,6 +71,10 @@ namespace CoreLibrary return joueurs[joueurCourant.Value]; } + /// + /// Passe la main au joueur suivant. + /// + /// LevĂ©e lorsqu'il n'y a pas de joueur courant. public void PasserLaMain() { if (!joueurCourant.HasValue) @@ -52,19 +90,29 @@ namespace CoreLibrary } + /// + /// GĂ©nère un nouveau code. + /// + /// Le code gĂ©nĂ©rĂ© public Code GenererCode() { return new Code(TailleCodeMaximum); } - + /// + /// Initialise le premier joueur Ă  jouer. + /// public void CommencerLaPartie() { joueurCourant = 0; } + /// + /// VĂ©rifie si la partie est terminĂ©e. + /// + /// True si la partie est terminĂ©e, sinon False. public bool EstTerminee() { if (!joueurCourant.HasValue || joueurCourant != 0) @@ -82,7 +130,10 @@ namespace CoreLibrary return false; } - + /// + /// Obtient les joueurs gagnants de la partie. + /// + /// La liste des joueurs gagnants. public IEnumerable Gagnants() { Joueur[] gagnants = []; @@ -97,6 +148,10 @@ namespace CoreLibrary return gagnants; } + /// + /// Obtient les joueurs perdants de la partie. + /// + /// La liste des joueurs perdants. public IEnumerable Perdants() { Joueur[] perdants = []; From 3212ea31a4004c4f5fa343da2824d8e1af10033d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9leste=20BARBOSA?= Date: Sun, 12 May 2024 22:07:09 +0200 Subject: [PATCH 24/36] ajout du status sonar et drone dans readme --- README.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 24b55f2..ea5f521 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ -# mastermind - -SAE2.01 - DĂ©veloppement d'une application -R2.02 - DĂ©veloppement d'applications avec IHM -R2.03 - QualitĂ© de dĂ©veloppement - -Mastermind en C#, MAUI, et .net - -BARBOSA CĂ©leste -PRADY Pauline -TURPIN-ETIENNE Camille +[![Build Status](https://codefirst.iut.uca.fr/api/badges/nicolas.barbosa/mastermind/status.svg)](https://codefirst.iut.uca.fr/nicolas.barbosa/mastermind) +[![Bugs](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=bugs&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![Code Smells](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=code_smells&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![Coverage](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=coverage&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![Duplicated Lines (%)](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=duplicated_lines_density&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![Lines of Code](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=ncloc&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![Maintainability Rating](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=sqale_rating&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![Quality Gate Status](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=alert_status&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![Reliability Rating](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=reliability_rating&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![Security Hotspots](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=security_hotspots&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![Security Rating](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=security_rating&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![Technical Debt](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=sqale_index&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![Vulnerabilities](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=vulnerabilities&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) \ No newline at end of file From bc8c1e7b019c237172b809aabeaac7cbd81f9054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9leste=20BARBOSA?= Date: Sun, 12 May 2024 22:19:41 +0200 Subject: [PATCH 25/36] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'README.md'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ea5f521..7b5e05f 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,25 @@ -[![Build Status](https://codefirst.iut.uca.fr/api/badges/nicolas.barbosa/mastermind/status.svg)](https://codefirst.iut.uca.fr/nicolas.barbosa/mastermind) +[![Drone](https://codefirst.iut.uca.fr/api/badges/nicolas.barbosa/mastermind/status.svg)](https://codefirst.iut.uca.fr/nicolas.barbosa/mastermind) + +[![Sonar](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=alert_status&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) + [![Bugs](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=bugs&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) -[![Code Smells](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=code_smells&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) -[![Coverage](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=coverage&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) -[![Duplicated Lines (%)](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=duplicated_lines_density&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![FiabilitĂ©](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=reliability_rating&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) + +[![VulnĂ©rabilitĂ©s](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=vulnerabilities&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) + +[![Risques](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=security_hotspots&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![SecuritĂ©](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=security_rating&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) + + + [![Lines of Code](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=ncloc&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) -[![Maintainability Rating](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=sqale_rating&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) -[![Quality Gate Status](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=alert_status&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) -[![Reliability Rating](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=reliability_rating&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) -[![Security Hotspots](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=security_hotspots&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) -[![Security Rating](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=security_rating&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) -[![Technical Debt](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=sqale_index&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) -[![Vulnerabilities](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=vulnerabilities&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) \ No newline at end of file + + + +[![Dette technique](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=sqale_index&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![Code Smells](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=code_smells&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![MaintenabilitĂ©](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=sqale_rating&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) + +[![Lignes dupliquĂ©es (%)](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=duplicated_lines_density&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![Tests](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=coverage&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) + From c9c5cee4662c2b30f857a8f5566125cabbe3d95f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9leste=20BARBOSA?= Date: Sun, 12 May 2024 22:32:52 +0200 Subject: [PATCH 26/36] =?UTF-8?q?d=C3=A9but=20du=20readme=20propre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7b5e05f..a953b79 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,26 @@ [![FiabilitĂ©](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=reliability_rating&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) [![VulnĂ©rabilitĂ©s](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=vulnerabilities&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) - -[![Risques](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=security_hotspots&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) [![SecuritĂ©](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=security_rating&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) - - -[![Lines of Code](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=ncloc&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) - - +[![Risques](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=security_hotspots&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) [![Dette technique](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=sqale_index&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) [![Code Smells](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=code_smells&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) [![MaintenabilitĂ©](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=sqale_rating&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) -[![Lignes dupliquĂ©es (%)](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=duplicated_lines_density&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) [![Tests](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=coverage&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![Lignes dupliquĂ©es (%)](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=duplicated_lines_density&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) +[![Nombre de lignes](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=celestebarbosa-mastermind&metric=ncloc&token=849a6b4d77bc19046c81e8fc8f6be8ec0b8c5f3a)](https://codefirst.iut.uca.fr/sonar/dashboard?id=celestebarbosa-mastermind) + +--- + +# Mastermind - Projet IHM + +**CĂ©leste BARBOSA**\ +**Pauline PRADY**\ +**Camille TURPIN-ETIENNE**\ + +--- +## RĂ©alisation d'un jeu vidĂ©o en .NET, C# & MAUI From af1a1c620e19ad619f459687db06df1e7027c4d9 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Sun, 12 May 2024 22:45:12 +0200 Subject: [PATCH 27/36] Correction du random --- Sources/CoreLibrary/Plateau.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/CoreLibrary/Plateau.cs b/Sources/CoreLibrary/Plateau.cs index 5e421d3..2081cf0 100644 --- a/Sources/CoreLibrary/Plateau.cs +++ b/Sources/CoreLibrary/Plateau.cs @@ -1,4 +1,5 @@ using CoreLibrary.Exceptions; +using System.Security.Cryptography; namespace CoreLibrary { @@ -7,8 +8,6 @@ namespace CoreLibrary /// public class Plateau { - private static Random random = new Random(); - private readonly Code codeSecret; private readonly Code?[] grille; private readonly IEnumerable[] indicateurs; @@ -62,7 +61,7 @@ namespace CoreLibrary for (int i = 0; i < tailleCode; ++i) { - codeSecret.AjouterJeton(new Jeton(couleurs[random.Next(couleurs.Length)])); + codeSecret.AjouterJeton(new Jeton(couleurs[RandomNumberGenerator.GetInt32(0, couleurs.Length)])); } } From af9acb9ceda9f7a098c88d57b9b3dc977c2d97f3 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Sun, 12 May 2024 23:23:04 +0200 Subject: [PATCH 28/36] correction des code smells --- Sources/ConsoleApp/Evenements.cs | 2 +- Sources/ConsoleApp/Utils.cs | 25 +++++++++---------- Sources/CoreLibrary/Code.cs | 2 +- .../Exceptions/CodeCompletException.cs | 14 ++++++++--- .../Exceptions/CodeIncompletException.cs | 12 +++++++-- .../Exceptions/CodeInvalideException.cs | 12 +++++++++ .../Exceptions/CodeVideException.cs | 12 +++++++-- .../Exceptions/GrilleCompleteException.cs | 12 +++++++-- .../Exceptions/IndiceCodeException.cs | 12 +++++++++ .../Exceptions/PartieNonCommenceeException.cs | 12 +++++++-- .../Exceptions/TailleCodeException.cs | 14 ++++++++++- .../Exceptions/TailleGrilleException.cs | 14 ++++++++++- Sources/CoreLibrary/Partie.cs | 12 +++------ Sources/CoreLibrary/Plateau.cs | 6 ++--- 14 files changed, 122 insertions(+), 39 deletions(-) diff --git a/Sources/ConsoleApp/Evenements.cs b/Sources/ConsoleApp/Evenements.cs index 14068e9..bd611d2 100644 --- a/Sources/ConsoleApp/Evenements.cs +++ b/Sources/ConsoleApp/Evenements.cs @@ -6,7 +6,7 @@ namespace ConsoleApp /// /// Fournit des gestionnaires d'Ă©vĂ©nements les Ă©vĂ©nements liĂ©s au dĂ©roulement de la partie. /// - public class Evenements + public static class Evenements { /// /// Gestionnaire d'Ă©vĂ©nement pour l'ajout d'un joueur. diff --git a/Sources/ConsoleApp/Utils.cs b/Sources/ConsoleApp/Utils.cs index 51cbe16..47787e1 100644 --- a/Sources/ConsoleApp/Utils.cs +++ b/Sources/ConsoleApp/Utils.cs @@ -2,7 +2,7 @@ namespace ConsoleApp { - public class Utils + public static class Utils { private readonly static Dictionary couleursTerminal = new Dictionary() { @@ -22,25 +22,24 @@ namespace ConsoleApp public static void DessinerTitre() { - Console.WriteLine(""" - __ __ _ _ _ - | \/ | __ _ ___| |_ ___ _ _ _ __ (_) _ _ __| | - | |\/| |/ _` |(_-<| _|/ -_)| '_|| ' \ | || ' \ / _` | - |_| |_|\__,_|/__/ \__|\___||_| |_|_|_||_||_||_|\__,_| - """); - + Console.WriteLine(@" + __ __ _ _ _ +| \/ | __ _ ___| |_ ___ _ _ _ __ (_) _ _ __| | +| |\/| |/ _` |(_-<| _|/ -_)| '_|| ' \ | || ' \ / _` | +|_| |_|\__,_|/__/ \__|\___||_| |_|_|_||_||_||_|\__,_| +"); DessinerSeparateur(); } public static void DessinerSeparateur() { - Console.WriteLine(""" + Console.WriteLine(@" - ─────────────────────────────────────────────────────── +─────────────────────────────────────────────────────── - """); + "); } public static void DessinerPion(Enum pion) @@ -62,8 +61,8 @@ namespace ConsoleApp public static void DessinerPlateau(IEnumerable> grille, IEnumerable> indicateurs) { - IEnumerable[] grilleTableau = (IEnumerable[])grille.ToArray(); - IEnumerable[] indicateursTableau = (IEnumerable[])indicateurs.ToArray(); + IEnumerable[] grilleTableau = grille.ToArray(); + IEnumerable[] indicateursTableau = indicateurs.ToArray(); Console.WriteLine(" Codes Indicateurs "); Console.WriteLine("──────────────── ────────────────"); diff --git a/Sources/CoreLibrary/Code.cs b/Sources/CoreLibrary/Code.cs index 0e1756e..81b3b61 100644 --- a/Sources/CoreLibrary/Code.cs +++ b/Sources/CoreLibrary/Code.cs @@ -20,7 +20,7 @@ namespace CoreLibrary public Code(IEnumerable jetons) { - if (jetons.Count() == 0) + if (jetons.Any()) { throw new TailleCodeException(jetons.Count()); } diff --git a/Sources/CoreLibrary/Exceptions/CodeCompletException.cs b/Sources/CoreLibrary/Exceptions/CodeCompletException.cs index a9fe1b5..3f8abc1 100644 --- a/Sources/CoreLibrary/Exceptions/CodeCompletException.cs +++ b/Sources/CoreLibrary/Exceptions/CodeCompletException.cs @@ -3,13 +3,21 @@ /// /// Exception levĂ©e lorsqu'un jeton est ajoutĂ© Ă  un code dĂ©jĂ  complet. /// + [Serializable] public class CodeCompletException : Exception { /// /// Initialise une nouvelle instance de la classe . /// - public CodeCompletException() : - base("Le code dans lequel vous essayez d'ajouter un jeton est dĂ©jĂ  complet.") - { } + private const string messageDefaut = "Le code dans lequel vous essayez d'ajouter un jeton est dĂ©jĂ  complet."; + + public CodeCompletException() : base(messageDefaut) + {} + + public CodeCompletException(string message) : base(message) + {} + + public CodeCompletException(string message, Exception exception) : base(message, exception) + {} } } diff --git a/Sources/CoreLibrary/Exceptions/CodeIncompletException.cs b/Sources/CoreLibrary/Exceptions/CodeIncompletException.cs index 3d7642c..59a7aaf 100644 --- a/Sources/CoreLibrary/Exceptions/CodeIncompletException.cs +++ b/Sources/CoreLibrary/Exceptions/CodeIncompletException.cs @@ -3,13 +3,21 @@ /// /// Exception levĂ©e lorsqu'un code incomplet est ajoutĂ© Ă  la grille. /// + [Serializable] public class CodeIncompletException : Exception { /// /// Initialise une nouvelle instance de la classe . /// - public CodeIncompletException() : - base("Le code que vous essayez d'ajouter dans la grille n'est pas complet.") + private const string messageDefaut = "Le code que vous essayez d'ajouter dans la grille n'est pas complet."; + + public CodeIncompletException() : base(messageDefaut) + { } + + public CodeIncompletException(string message) : base(message) + { } + + public CodeIncompletException(string message, Exception exception) : base(message, exception) { } } } diff --git a/Sources/CoreLibrary/Exceptions/CodeInvalideException.cs b/Sources/CoreLibrary/Exceptions/CodeInvalideException.cs index 73c629d..e5fdfd9 100644 --- a/Sources/CoreLibrary/Exceptions/CodeInvalideException.cs +++ b/Sources/CoreLibrary/Exceptions/CodeInvalideException.cs @@ -3,6 +3,7 @@ /// /// Exception levĂ©e lorsqu'un code avec une taille invalide est ajoutĂ© Ă  la grille. /// + [Serializable] public class CodeInvalideException : Exception { /// @@ -10,8 +11,19 @@ /// /// La taille du code que vous essayez d'ajouter. /// La taille du code que le plateau attend. + private const string messageDefaut = "Le code que vous essayez d'ajouter est invalide."; + + public CodeInvalideException() : base(messageDefaut) + { } + public CodeInvalideException(int tailleCodeAjoute, int tailleCodePlateau) : base($"Le code que vous essayez d'ajouter est un code de taille {tailleCodeAjoute}, or le plateau attend un code de {tailleCodePlateau}.") { } + + public CodeInvalideException(string message) : base(message) + { } + + public CodeInvalideException(string message, Exception exception) : base(message, exception) + { } } } diff --git a/Sources/CoreLibrary/Exceptions/CodeVideException.cs b/Sources/CoreLibrary/Exceptions/CodeVideException.cs index b05da88..c8d21f9 100644 --- a/Sources/CoreLibrary/Exceptions/CodeVideException.cs +++ b/Sources/CoreLibrary/Exceptions/CodeVideException.cs @@ -3,13 +3,21 @@ /// /// Exception levĂ©e lorsqu'un jeton est supprimĂ© d'un code qui est dĂ©jĂ  vide. /// + [Serializable] public class CodeVideException : Exception { /// /// Initialise une nouvelle instance de la classe . /// - public CodeVideException() : - base("Le code dans lequel vous essayez de supprimer un jeton est dĂ©jĂ  vide.") + private const string messageDefaut = "Le code dans lequel vous essayez de supprimer un jeton est dĂ©jĂ  vide."; + + public CodeVideException() : base(messageDefaut) + { } + + public CodeVideException(string message) : base(message) + { } + + public CodeVideException(string message, Exception exception) : base(message, exception) { } } } diff --git a/Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs b/Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs index b02a9c0..f74bd4f 100644 --- a/Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs +++ b/Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs @@ -3,13 +3,21 @@ /// /// Exception levĂ©e lorsqu'un code est ajoutĂ© Ă  une grille qui est dĂ©jĂ  complète. /// + [Serializable] public class GrilleCompleteException : Exception { /// /// Initialise une nouvelle instance de la classe . /// - public GrilleCompleteException() : - base("La grille dans laquelle vous essayez d'ajouter un code est dĂ©jĂ  complète.") + private const string messageDefaut = "La grille dans laquelle vous essayez d'ajouter un code est dĂ©jĂ  complète."; + + public GrilleCompleteException() : base(messageDefaut) + { } + + public GrilleCompleteException(string message) : base(message) + { } + + public GrilleCompleteException(string message, Exception exception) : base(message, exception) { } } } diff --git a/Sources/CoreLibrary/Exceptions/IndiceCodeException.cs b/Sources/CoreLibrary/Exceptions/IndiceCodeException.cs index f1b246a..fd0e13e 100644 --- a/Sources/CoreLibrary/Exceptions/IndiceCodeException.cs +++ b/Sources/CoreLibrary/Exceptions/IndiceCodeException.cs @@ -3,6 +3,7 @@ /// /// Exception levĂ©e lorsqu'un indice de jeton est invalide. /// + [Serializable] public class IndiceCodeException : Exception { /// @@ -10,8 +11,19 @@ /// /// L'indice incorrect qui a Ă©tĂ© spĂ©cifiĂ©. /// L'indice maximum permis. + private const string messageDefaut = "L'indice du jeton que vous essayez de rĂ©cupĂ©rer est hors de la plage valide."; + + public IndiceCodeException() : base(messageDefaut) + { } + public IndiceCodeException(int indice, int indiceMax) : base($"Vous avez essayĂ© de rĂ©cupĂ©rer le jeton Ă  la place {indice}, mais son indice doit ĂŞtre compris entre 0 et {indiceMax}.") { } + + public IndiceCodeException(string message) : base(message) + { } + + public IndiceCodeException(string message, Exception exception) : base(message, exception) + { } } } diff --git a/Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs b/Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs index b4768f7..a2070ed 100644 --- a/Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs +++ b/Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs @@ -3,13 +3,21 @@ /// /// Exception levĂ©e lorsqu'une opĂ©ration est tentĂ©e alors que la partie n'a pas encore commencĂ©. /// + [Serializable] public class PartieNonCommenceeException : Exception { /// /// Initialise une nouvelle instance de la classe . /// - public PartieNonCommenceeException() : - base("La partie n'a pas encore commencĂ©e.") + private const string messageDefaut = "La partie n'a pas encore commencĂ©e."; + + public PartieNonCommenceeException() : base(messageDefaut) + { } + + public PartieNonCommenceeException(string message) : base(message) + { } + + public PartieNonCommenceeException(string message, Exception exception) : base(message, exception) { } } } diff --git a/Sources/CoreLibrary/Exceptions/TailleCodeException.cs b/Sources/CoreLibrary/Exceptions/TailleCodeException.cs index 5563cdd..9757839 100644 --- a/Sources/CoreLibrary/Exceptions/TailleCodeException.cs +++ b/Sources/CoreLibrary/Exceptions/TailleCodeException.cs @@ -3,14 +3,26 @@ /// /// Exception levĂ©e lorsqu'une taille de code invalide est spĂ©cifiĂ©e. /// + [Serializable] public class TailleCodeException : Exception { /// /// Initialise une nouvelle instance de la classe . /// /// La taille du code spĂ©cifiĂ©e. - public TailleCodeException(int taille) : + private const string messageDefaut = "Un code doit avoir une taille positive non nulle."; + + public TailleCodeException() : base(messageDefaut) + { } + + public TailleCodeException(int taille) : base($"Un code doit avoir une taille positive non nulle, or il a reçu {taille}.") { } + + public TailleCodeException(string message) : base(message) + { } + + public TailleCodeException(string message, Exception exception) : base(message, exception) + { } } } diff --git a/Sources/CoreLibrary/Exceptions/TailleGrilleException.cs b/Sources/CoreLibrary/Exceptions/TailleGrilleException.cs index 332b319..926d9d1 100644 --- a/Sources/CoreLibrary/Exceptions/TailleGrilleException.cs +++ b/Sources/CoreLibrary/Exceptions/TailleGrilleException.cs @@ -3,14 +3,26 @@ /// /// Exception levĂ©e lorsqu'une taille de grille invalide est spĂ©cifiĂ©e. /// + [Serializable] public class TailleGrilleException : Exception { /// /// Initialise une nouvelle instance de la classe . /// /// La taille de grille spĂ©cifiĂ©e. - public TailleGrilleException(int taille) : + private const string messageDefaut = "Une grille doit avoir une taille positive non nulle."; + + public TailleGrilleException() : base(messageDefaut) + { } + + public TailleGrilleException(int taille) : base($"Une grille doit avoir une taille positive non nulle, or elle a reçu {taille}.") { } + + public TailleGrilleException(string message) : base(message) + { } + + public TailleGrilleException(string message, Exception exception) : base(message, exception) + { } } } diff --git a/Sources/CoreLibrary/Partie.cs b/Sources/CoreLibrary/Partie.cs index d59ba5e..a6488a6 100644 --- a/Sources/CoreLibrary/Partie.cs +++ b/Sources/CoreLibrary/Partie.cs @@ -7,8 +7,8 @@ namespace CoreLibrary { private readonly IRegles regles; - public delegate string? StringEventHandler(Object? sender, TEventArgs e); - public delegate Jeton? JetonEventHandler(Object? sender, TEventArgs e); + public delegate string? StringEventHandler(Object? sender, TEventArgs e); + public delegate Jeton? JetonEventHandler(Object? sender, TEventArgs e); public event StringEventHandler? DemanderJoueur; public event JetonEventHandler? DemanderJeton; @@ -71,12 +71,8 @@ namespace CoreLibrary if(DemanderJeton != null) { // Si quelqu'un Ă©coute l'Ă©vĂ©nement mais ne renvoie rien, alors on supprime le dernier jeton - try - { - code.SupprimerDernierJeton(); - QuandSupprimerDernierJeton(); - } - catch(CodeVideException){} + code.SupprimerDernierJeton(); + QuandSupprimerDernierJeton(); } else { diff --git a/Sources/CoreLibrary/Plateau.cs b/Sources/CoreLibrary/Plateau.cs index 2081cf0..70ada70 100644 --- a/Sources/CoreLibrary/Plateau.cs +++ b/Sources/CoreLibrary/Plateau.cs @@ -121,14 +121,14 @@ namespace CoreLibrary throw new CodeIncompletException(); } - IEnumerable indicateurs = codeSecret.Comparer(code); + IEnumerable indicateursCode = codeSecret.Comparer(code); - if (indicateurs.Count() != tailleCode) + if (indicateursCode.Count() != tailleCode) { return false; } - foreach (Indicateur indicateur in indicateurs) + foreach (Indicateur indicateur in indicateursCode) { if (indicateur != Indicateur.BONNEPLACE) { From 14c3127ac60dcfc6d83e93a4cf1856f454a89116 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Sun, 12 May 2024 23:39:29 +0200 Subject: [PATCH 29/36] code smell correction sur les exceptions --- Sources/CoreLibrary/Exceptions/CodeCompletException.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/CoreLibrary/Exceptions/CodeCompletException.cs b/Sources/CoreLibrary/Exceptions/CodeCompletException.cs index 3f8abc1..d641329 100644 --- a/Sources/CoreLibrary/Exceptions/CodeCompletException.cs +++ b/Sources/CoreLibrary/Exceptions/CodeCompletException.cs @@ -1,4 +1,6 @@ -namespace CoreLibrary.Exceptions +using System.Runtime.Serialization; + +namespace CoreLibrary.Exceptions { /// /// Exception levĂ©e lorsqu'un jeton est ajoutĂ© Ă  un code dĂ©jĂ  complet. @@ -19,5 +21,8 @@ public CodeCompletException(string message, Exception exception) : base(message, exception) {} + + protected CodeCompletException(SerializationInfo info, StreamingContext context) : base(info, context) + {} } } From 96f16f7225f03f62b7213ac8bee4cb494656a04b Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Sun, 12 May 2024 23:42:54 +0200 Subject: [PATCH 30/36] tentative de corrections de code smell sur les exceptions --- Sources/CoreLibrary/Exceptions/CodeCompletException.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/CoreLibrary/Exceptions/CodeCompletException.cs b/Sources/CoreLibrary/Exceptions/CodeCompletException.cs index d641329..5dbb92d 100644 --- a/Sources/CoreLibrary/Exceptions/CodeCompletException.cs +++ b/Sources/CoreLibrary/Exceptions/CodeCompletException.cs @@ -22,7 +22,13 @@ namespace CoreLibrary.Exceptions public CodeCompletException(string message, Exception exception) : base(message, exception) {} - protected CodeCompletException(SerializationInfo info, StreamingContext context) : base(info, context) - {} + [Obsolete("", DiagnosticId = "SYSLIB0051")] + protected CodeCompletException(SerializationInfo info, StreamingContext contexte) : base(info, contexte) { } + + [Obsolete("", DiagnosticId = "SYSLIB0051")] + public override void GetObjectData(SerializationInfo info, StreamingContext contexte) + { + base.GetObjectData(info, contexte); + } } } From 907f9b27992565f2805d408091102414442580bb Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Sun, 12 May 2024 23:47:10 +0200 Subject: [PATCH 31/36] toujours et encore les codes smell --- Sources/CoreLibrary/Exceptions/CodeCompletException.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/CoreLibrary/Exceptions/CodeCompletException.cs b/Sources/CoreLibrary/Exceptions/CodeCompletException.cs index 5dbb92d..dc4dc7f 100644 --- a/Sources/CoreLibrary/Exceptions/CodeCompletException.cs +++ b/Sources/CoreLibrary/Exceptions/CodeCompletException.cs @@ -22,13 +22,13 @@ namespace CoreLibrary.Exceptions public CodeCompletException(string message, Exception exception) : base(message, exception) {} - [Obsolete("", DiagnosticId = "SYSLIB0051")] + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] protected CodeCompletException(SerializationInfo info, StreamingContext contexte) : base(info, contexte) { } - [Obsolete("", DiagnosticId = "SYSLIB0051")] - public override void GetObjectData(SerializationInfo info, StreamingContext contexte) + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + public override void GetObjectData(SerializationInfo info, StreamingContext context) { - base.GetObjectData(info, contexte); + base.GetObjectData(info, context); } } } From df2fab0c34c404b1c8a08b63cc25d8319536caef Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Sun, 12 May 2024 23:49:43 +0200 Subject: [PATCH 32/36] correction des code smell sur les exception v1235 --- .../Exceptions/CodeIncompletException.cs | 13 ++++++++++++- .../CoreLibrary/Exceptions/CodeInvalideException.cs | 13 ++++++++++++- Sources/CoreLibrary/Exceptions/CodeVideException.cs | 13 ++++++++++++- .../Exceptions/GrilleCompleteException.cs | 13 ++++++++++++- .../CoreLibrary/Exceptions/IndiceCodeException.cs | 13 ++++++++++++- .../Exceptions/PartieNonCommenceeException.cs | 13 ++++++++++++- .../CoreLibrary/Exceptions/TailleCodeException.cs | 13 ++++++++++++- .../CoreLibrary/Exceptions/TailleGrilleException.cs | 13 ++++++++++++- 8 files changed, 96 insertions(+), 8 deletions(-) diff --git a/Sources/CoreLibrary/Exceptions/CodeIncompletException.cs b/Sources/CoreLibrary/Exceptions/CodeIncompletException.cs index 59a7aaf..b437029 100644 --- a/Sources/CoreLibrary/Exceptions/CodeIncompletException.cs +++ b/Sources/CoreLibrary/Exceptions/CodeIncompletException.cs @@ -1,4 +1,6 @@ -namespace CoreLibrary.Exceptions +using System.Runtime.Serialization; + +namespace CoreLibrary.Exceptions { /// /// Exception levĂ©e lorsqu'un code incomplet est ajoutĂ© Ă  la grille. @@ -19,5 +21,14 @@ public CodeIncompletException(string message, Exception exception) : base(message, exception) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + protected CodeIncompletException(SerializationInfo info, StreamingContext contexte) : base(info, contexte) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + } } } diff --git a/Sources/CoreLibrary/Exceptions/CodeInvalideException.cs b/Sources/CoreLibrary/Exceptions/CodeInvalideException.cs index e5fdfd9..a786e04 100644 --- a/Sources/CoreLibrary/Exceptions/CodeInvalideException.cs +++ b/Sources/CoreLibrary/Exceptions/CodeInvalideException.cs @@ -1,4 +1,6 @@ -namespace CoreLibrary.Exceptions +using System.Runtime.Serialization; + +namespace CoreLibrary.Exceptions { /// /// Exception levĂ©e lorsqu'un code avec une taille invalide est ajoutĂ© Ă  la grille. @@ -25,5 +27,14 @@ public CodeInvalideException(string message, Exception exception) : base(message, exception) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + protected CodeInvalideException(SerializationInfo info, StreamingContext contexte) : base(info, contexte) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + } } } diff --git a/Sources/CoreLibrary/Exceptions/CodeVideException.cs b/Sources/CoreLibrary/Exceptions/CodeVideException.cs index c8d21f9..f9fc813 100644 --- a/Sources/CoreLibrary/Exceptions/CodeVideException.cs +++ b/Sources/CoreLibrary/Exceptions/CodeVideException.cs @@ -1,4 +1,6 @@ -namespace CoreLibrary.Exceptions +using System.Runtime.Serialization; + +namespace CoreLibrary.Exceptions { /// /// Exception levĂ©e lorsqu'un jeton est supprimĂ© d'un code qui est dĂ©jĂ  vide. @@ -19,5 +21,14 @@ public CodeVideException(string message, Exception exception) : base(message, exception) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + protected CodeVideException(SerializationInfo info, StreamingContext contexte) : base(info, contexte) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + } } } diff --git a/Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs b/Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs index f74bd4f..b2d9ce0 100644 --- a/Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs +++ b/Sources/CoreLibrary/Exceptions/GrilleCompleteException.cs @@ -1,4 +1,6 @@ -namespace CoreLibrary.Exceptions +using System.Runtime.Serialization; + +namespace CoreLibrary.Exceptions { /// /// Exception levĂ©e lorsqu'un code est ajoutĂ© Ă  une grille qui est dĂ©jĂ  complète. @@ -19,5 +21,14 @@ public GrilleCompleteException(string message, Exception exception) : base(message, exception) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + protected GrilleCompleteException(SerializationInfo info, StreamingContext contexte) : base(info, contexte) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + } } } diff --git a/Sources/CoreLibrary/Exceptions/IndiceCodeException.cs b/Sources/CoreLibrary/Exceptions/IndiceCodeException.cs index fd0e13e..1366665 100644 --- a/Sources/CoreLibrary/Exceptions/IndiceCodeException.cs +++ b/Sources/CoreLibrary/Exceptions/IndiceCodeException.cs @@ -1,4 +1,6 @@ -namespace CoreLibrary.Exceptions +using System.Runtime.Serialization; + +namespace CoreLibrary.Exceptions { /// /// Exception levĂ©e lorsqu'un indice de jeton est invalide. @@ -25,5 +27,14 @@ public IndiceCodeException(string message, Exception exception) : base(message, exception) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + protected IndiceCodeException(SerializationInfo info, StreamingContext contexte) : base(info, contexte) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + } } } diff --git a/Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs b/Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs index a2070ed..3c0f8c7 100644 --- a/Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs +++ b/Sources/CoreLibrary/Exceptions/PartieNonCommenceeException.cs @@ -1,4 +1,6 @@ -namespace CoreLibrary.Exceptions +using System.Runtime.Serialization; + +namespace CoreLibrary.Exceptions { /// /// Exception levĂ©e lorsqu'une opĂ©ration est tentĂ©e alors que la partie n'a pas encore commencĂ©. @@ -19,5 +21,14 @@ public PartieNonCommenceeException(string message, Exception exception) : base(message, exception) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + protected PartieNonCommenceeException(SerializationInfo info, StreamingContext contexte) : base(info, contexte) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + } } } diff --git a/Sources/CoreLibrary/Exceptions/TailleCodeException.cs b/Sources/CoreLibrary/Exceptions/TailleCodeException.cs index 9757839..bf3fae9 100644 --- a/Sources/CoreLibrary/Exceptions/TailleCodeException.cs +++ b/Sources/CoreLibrary/Exceptions/TailleCodeException.cs @@ -1,4 +1,6 @@ -namespace CoreLibrary.Exceptions +using System.Runtime.Serialization; + +namespace CoreLibrary.Exceptions { /// /// Exception levĂ©e lorsqu'une taille de code invalide est spĂ©cifiĂ©e. @@ -24,5 +26,14 @@ public TailleCodeException(string message, Exception exception) : base(message, exception) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + protected TailleCodeException(SerializationInfo info, StreamingContext contexte) : base(info, contexte) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + } } } diff --git a/Sources/CoreLibrary/Exceptions/TailleGrilleException.cs b/Sources/CoreLibrary/Exceptions/TailleGrilleException.cs index 926d9d1..e7f06ef 100644 --- a/Sources/CoreLibrary/Exceptions/TailleGrilleException.cs +++ b/Sources/CoreLibrary/Exceptions/TailleGrilleException.cs @@ -1,4 +1,6 @@ -namespace CoreLibrary.Exceptions +using System.Runtime.Serialization; + +namespace CoreLibrary.Exceptions { /// /// Exception levĂ©e lorsqu'une taille de grille invalide est spĂ©cifiĂ©e. @@ -24,5 +26,14 @@ public TailleGrilleException(string message, Exception exception) : base(message, exception) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + protected TailleGrilleException(SerializationInfo info, StreamingContext contexte) : base(info, contexte) { } + + [Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + } } } From e310163730165c468136fdcf5159567e74b3966f Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Mon, 13 May 2024 00:21:57 +0200 Subject: [PATCH 33/36] tentative de correction d'une methode trop complexe cognitivement - DessinerPlateau --- Sources/ConsoleApp/Utils.cs | 54 +++++++++++++++---------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/Sources/ConsoleApp/Utils.cs b/Sources/ConsoleApp/Utils.cs index 47787e1..5b09d8f 100644 --- a/Sources/ConsoleApp/Utils.cs +++ b/Sources/ConsoleApp/Utils.cs @@ -59,6 +59,14 @@ namespace ConsoleApp Console.Write(" "); } + private static void DessinerLigne(Enum[] ligne) + { + foreach(Enum pion in ligne) + DessinerPion(pion); + + Console.Write("".PadLeft((4 - ligne.Length) * 3)); + } + public static void DessinerPlateau(IEnumerable> grille, IEnumerable> indicateurs) { IEnumerable[] grilleTableau = grille.ToArray(); @@ -72,44 +80,26 @@ namespace ConsoleApp { Console.Write("│ "); - Jeton?[] ligneGrille = grilleTableau[i].ToArray(); - - for (int j = 0; j < ligneGrille.Length; ++j) - { - Jeton? jeton = ligneGrille[j]; - - if (jeton.HasValue) - { - DessinerPion(jeton.Value.Couleur); - } - else - { - Console.Write(" "); - } - - } + DessinerLigne( + grilleTableau[i] + .Where(jeton => jeton.HasValue) + .Select(jeton => (Enum)jeton!.Value.Couleur) + .ToArray() + ); Console.Write(" │ │ "); - if (indicateursTableau[i] != null) + if (indicateursTableau[i] == null) { - Indicateur[] ligneIndicateurs = indicateursTableau[i].ToArray(); - - for (int j = 0; j < ligneIndicateurs.Length; ++j) - { - DessinerPion(ligneIndicateurs[j]); - } - - if (ligneIndicateurs.Length < 4) - { - Console.Write("".PadLeft((4 - ligneIndicateurs.Length) * 3)); - } - } - else - { - Console.Write(" "); + indicateursTableau[i] = []; } + DessinerLigne( + indicateursTableau[i] + .Select(indicateur => (Enum)indicateur) + .ToArray() + ); + Console.WriteLine(" │"); } From 43922656a0016c62f4fe32cf5190781f614e19a1 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Mon, 13 May 2024 00:34:56 +0200 Subject: [PATCH 34/36] =?UTF-8?q?tentative=20de=20correction=20complexit?= =?UTF-8?q?=C3=A9=20cognitive=20sur=20Comparer()=20un=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/CoreLibrary/Code.cs | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/Sources/CoreLibrary/Code.cs b/Sources/CoreLibrary/Code.cs index 81b3b61..8720ed3 100644 --- a/Sources/CoreLibrary/Code.cs +++ b/Sources/CoreLibrary/Code.cs @@ -84,16 +84,15 @@ namespace CoreLibrary { // Mon code est le code correct, l'autre code est celui qui teste - Indicateur[] indicateurs = []; if (!EstComplet() || !autreCode.EstComplet()) return indicateurs; - Jeton?[] mesJetons = Jetons().ToArray(); - Jeton?[] sesJetons = autreCode.Jetons().ToArray(); + List mesJetons = new List(Jetons()); + List sesJetons = new List(autreCode.Jetons()); - for (int i = 0; i < mesJetons.Length; ++i) + for (int i = 0; i < mesJetons.Count; ++i) { Jeton? monJeton = mesJetons[i]; Jeton? sonJeton = sesJetons[i]; @@ -107,25 +106,16 @@ namespace CoreLibrary } - for (int i = 0; i < sesJetons.Length; ++i) + for (int i = 0; i < sesJetons.Count; ++i) { Jeton? sonJeton = sesJetons[i]; - - if (sonJeton.HasValue) + + if (sonJeton.HasValue && mesJetons.Contains(sonJeton.Value)) { - for (int j = 0; j < mesJetons.Length; ++j) - { - Jeton? monJeton = mesJetons[j]; - - if (monJeton.HasValue && sonJeton.Value.Couleur.Equals(monJeton.Value.Couleur)) - { - indicateurs = indicateurs.Append(Indicateur.BONNECOULEUR).ToArray(); - mesJetons[j] = null; - sesJetons[i] = null; - break; - } - - } + indicateurs = indicateurs.Append(Indicateur.BONNECOULEUR).ToArray(); + mesJetons[mesJetons.IndexOf(sonJeton.Value)] = null; + sesJetons[i] = null; + break; } } From fe68d779b1349922b2dc81831a8d56e5baaa77ea Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Mon, 13 May 2024 01:26:50 +0200 Subject: [PATCH 35/36] Ajout de la doc pour util, code, partie , Evenement --- Sources/ConsoleApp/Evenements.cs | 2 +- Sources/ConsoleApp/Utils.cs | 26 ++++++- Sources/CoreLibrary/Code.cs | 57 +++++++++++++++ Sources/CoreLibrary/Partie.cs | 115 ++++++++++++++++++++++++++++++- 4 files changed, 196 insertions(+), 4 deletions(-) diff --git a/Sources/ConsoleApp/Evenements.cs b/Sources/ConsoleApp/Evenements.cs index bd611d2..33f9151 100644 --- a/Sources/ConsoleApp/Evenements.cs +++ b/Sources/ConsoleApp/Evenements.cs @@ -4,7 +4,7 @@ using CoreLibrary; namespace ConsoleApp { /// - /// Fournit des gestionnaires d'Ă©vĂ©nements les Ă©vĂ©nements liĂ©s au dĂ©roulement de la partie. + /// Fournit des gestionnaires d'Ă©vĂ©nements pour les Ă©vĂ©nements liĂ©s au dĂ©roulement de la partie. /// public static class Evenements { diff --git a/Sources/ConsoleApp/Utils.cs b/Sources/ConsoleApp/Utils.cs index 5b09d8f..f768e8b 100644 --- a/Sources/ConsoleApp/Utils.cs +++ b/Sources/ConsoleApp/Utils.cs @@ -2,8 +2,12 @@ namespace ConsoleApp { + /// + /// Classe utilitaire contenant des mĂ©thodes pour dessiner des Ă©lĂ©ments dans la console. + /// public static class Utils { + // Dictionnaires associant les valeurs des Ă©numĂ©rations avec les couleurs de la console private readonly static Dictionary couleursTerminal = new Dictionary() { {Couleur.NOIR, ConsoleColor.Black }, @@ -20,6 +24,9 @@ namespace ConsoleApp {Indicateur.BONNECOULEUR, ConsoleColor.White } }; + /// + /// Dessine le titre du jeu dans la console. + /// public static void DessinerTitre() { Console.WriteLine(@" @@ -31,7 +38,9 @@ namespace ConsoleApp DessinerSeparateur(); } - + /// + /// Dessine un sĂ©parateur dans la console. + /// public static void DessinerSeparateur() { Console.WriteLine(@" @@ -42,14 +51,20 @@ namespace ConsoleApp "); } + /// + /// Dessine un pion dans la console. + /// + /// Le pion Ă  dessiner (une couleur ou un indicateur). public static void DessinerPion(Enum pion) { Console.Write(" "); + // SĂ©lectionne la couleur appropriĂ©e en fonction du type de pion (une couleur ou un indicateur) Console.ForegroundColor = pion.GetType().Equals(typeof(Couleur)) ? couleursTerminal.GetValueOrDefault((Couleur)pion) : indicateursTerminal.GetValueOrDefault((Indicateur)pion); + // DĂ©finit la couleur de fond en fonction de la couleur de premier plan Console.BackgroundColor = Console.ForegroundColor.Equals(ConsoleColor.Black) ? ConsoleColor.White : ConsoleColor.Black; Console.Write("⬤"); @@ -59,6 +74,10 @@ namespace ConsoleApp Console.Write(" "); } + /// + /// Dessine une ligne de pions sur la console. + /// + /// Un tableau d'Ă©numĂ©rations reprĂ©sentant les pions Ă  dessiner. private static void DessinerLigne(Enum[] ligne) { foreach(Enum pion in ligne) @@ -67,6 +86,11 @@ namespace ConsoleApp Console.Write("".PadLeft((4 - ligne.Length) * 3)); } + /// + /// Dessine un plateau de jeu dans la console, affichant les jetons et les indicateurs. + /// + /// La grille de jeu. + /// Les indicateurs associĂ©s Ă  chaque ligne. public static void DessinerPlateau(IEnumerable> grille, IEnumerable> indicateurs) { IEnumerable[] grilleTableau = grille.ToArray(); diff --git a/Sources/CoreLibrary/Code.cs b/Sources/CoreLibrary/Code.cs index 8720ed3..053303a 100644 --- a/Sources/CoreLibrary/Code.cs +++ b/Sources/CoreLibrary/Code.cs @@ -2,12 +2,23 @@ namespace CoreLibrary { + /// + /// ReprĂ©sente un code composĂ© de jetons. + /// public class Code { private readonly Jeton?[] lesJetons; + /// + /// Obtenir le nombre de jetons dans le code. + /// public int NbJetons { get; private set; } = 0; + /// + /// Initialise une nouvelle instance de la classe avec la longueur de code spĂ©cifiĂ©e. + /// + /// La longueur du code. + /// LevĂ©e lorsque la longueur du code spĂ©cifiĂ©e est infĂ©rieure ou Ă©gale Ă  zĂ©ro. public Code(int tailleCode) { if(tailleCode <= 0) @@ -18,6 +29,11 @@ namespace CoreLibrary lesJetons = new Jeton?[tailleCode]; } + /// + /// Initialise une nouvelle instance de la class avec les jetons spĂ©cifiĂ©s. + /// + /// Les jetons pour initaliser le code. + /// LevĂ©e lorsque la collection de jetons spĂ©cifiĂ©e est vide. public Code(IEnumerable jetons) { if (jetons.Any()) @@ -32,6 +48,11 @@ namespace CoreLibrary } } + /// + /// Ajoute un jeton au code. + /// + /// Le jeton Ă  ajouter + /// LevĂ©e lorsque le code est plein. public void AjouterJeton(Jeton jeton) { if (NbJetons == TailleMaximale()) @@ -42,6 +63,10 @@ namespace CoreLibrary lesJetons[NbJetons++] = jeton; } + /// + /// Supprime le dernier jeton ajoutĂ© au code. + /// + /// LevĂ©e lorsque le code est vide. public void SupprimerDernierJeton() { if(NbJetons == 0) @@ -52,6 +77,12 @@ namespace CoreLibrary lesJetons[--NbJetons] = null; } + /// + /// RĂ©cupère le jeton Ă  l'indice spĂ©cifiĂ© dans le code. + /// + /// L'indice du jeton a rĂ©cupĂ©rĂ©. + /// Le jeton situĂ© Ă  l'indice spĂ©cifiĂ©. + /// LevĂ©e lorsque l'indice est supĂ©rieur Ă  la taille maximale du code, infĂ©rieur Ă  0 ou qu'il n'y a pas de jeton Ă  l'indice spĂ©cifiĂ© public Jeton RecupererJeton(int indice) { if(indice < 0 || indice > TailleMaximale()) @@ -65,33 +96,57 @@ namespace CoreLibrary return jeton.Value; } + /// + /// RĂ©cupère une Ă©numĂ©ration des jetons dans le code. + /// + /// EnumĂ©ration des jetons du code public IEnumerable Jetons() { return lesJetons; } + + /// + /// VĂ©rifie si le code est complet. + /// + /// True si le code est complet, sinon False. public bool EstComplet() { return NbJetons == lesJetons.Length; } + /// + /// Recupère la taille maximal du code. + /// + /// Taille maximal du code. + public int TailleMaximale() { return lesJetons.Length; } + /// + /// Compare le code avec un autre code et gĂ©nère des indcateurs de correspondance. + /// + /// Le code Ă  comparer avec le code actuel + /// EnumĂ©ration d'indicateurs de correspondance entre les deux codes. public IEnumerable Comparer(Code autreCode) { // Mon code est le code correct, l'autre code est celui qui teste Indicateur[] indicateurs = []; + /// VĂ©rifie si les deux codes sont complets if (!EstComplet() || !autreCode.EstComplet()) return indicateurs; List mesJetons = new List(Jetons()); List sesJetons = new List(autreCode.Jetons()); + + /// Compare les jetons pour dĂ©tecter les ceux Ă  la bonnes places + /// S'ils sont Ă  la bonne place alors ils sont enlever du tableau et un indicateur BONNEPLACE est ajouter au tableau des indicateurs. + for (int i = 0; i < mesJetons.Count; ++i) { Jeton? monJeton = mesJetons[i]; @@ -105,6 +160,8 @@ namespace CoreLibrary } } + /// Compare les jetons pour dĂ©tecter ceux qui ont la bonne couleur. + /// S'ils ont la bonne couleur alors ils sont enlever du tableau et un indicateur BONNECOULEUR est ajouter au tableau des indicateurs. for (int i = 0; i < sesJetons.Count; ++i) { diff --git a/Sources/CoreLibrary/Partie.cs b/Sources/CoreLibrary/Partie.cs index a6488a6..4ac30cf 100644 --- a/Sources/CoreLibrary/Partie.cs +++ b/Sources/CoreLibrary/Partie.cs @@ -3,56 +3,166 @@ using CoreLibrary.Exceptions; namespace CoreLibrary { + /// + /// ReprĂ©sente une partie de jeu. + /// public class Partie { private readonly IRegles regles; + + /// + /// DĂ©finit le dĂ©lĂ©guĂ© pour gĂ©rer les Ă©vĂ©nements avec des arguments de type string. + /// public delegate string? StringEventHandler(Object? sender, TEventArgs e); + + /// + /// DĂ©finit le dĂ©lĂ©guĂ© pour gĂ©rer les Ă©vĂ©nements avec des arguments de type Jeton. + /// public delegate Jeton? JetonEventHandler(Object? sender, TEventArgs e); + /// + /// ÉvĂ©nement dĂ©clenchĂ© lorsqu'il est nĂ©cessaire de d'ajouter un joueur. + /// public event StringEventHandler? DemanderJoueur; + + /// + /// ÉvĂ©nement dĂ©clenchĂ© lorsqu'il est nĂ©cessaire d'ajouter un jeton. + /// public event JetonEventHandler? DemanderJeton; + /// + /// ÉvĂ©nement dĂ©clenchĂ© lorsqu'il est nĂ©cessaire d'ajouter un joueur. + /// public event EventHandler? AjouterJoueur; + + /// + /// ÉvĂ©nement dĂ©clenchĂ© lorsqu'une partie commence. + /// public event EventHandler? DebutPartie; + + /// + /// ÉvĂ©nement dĂ©clenchĂ© lorsqu'un nouveau tour commence. + /// public event EventHandler? NouveauTour; + + /// + /// ÉvĂ©nement dĂ©clenchĂ© lorsqu'il est nĂ©cessaire d'ajouter un jeton. + /// public event EventHandler? AjouterJeton; + + + /// + /// ÉvĂ©nement dĂ©clenchĂ© lorsqu'un jeton est supprimĂ©. + /// public event EventHandler? SupprimerDernierJeton; + + /// + /// ÉvĂ©nement dĂ©clenchĂ© lorsqu'un code est ajoutĂ©. + /// public event EventHandler? AjouterCode; + + /// + /// ÉvĂ©nement dĂ©clenchĂ© lorsque la main est passĂ©e au joueur suivant. + /// public event EventHandler? PasserMain; + + /// + /// ÉvĂ©nement dĂ©clenchĂ© lorsque la partie est terminĂ©e. + /// public event EventHandler? PartieTerminee; + /// + /// MĂ©thode pour dĂ©clencher l'Ă©vĂ©nement de demande d'ajout d'un joueur. + /// + /// Le numĂ©ro du joueur Ă  ajouter + /// Le nom du joueur demandĂ© private string? QuandDemanderJoueur(int numero) => DemanderJoueur?.Invoke(this, new DemanderJoueurEventArgs(numero)); - private Jeton? QuandDemanderJeton() => DemanderJeton?.Invoke(this, new DemanderJetonEventArgs()); + /// + /// MĂ©thode pour dĂ©clencher l'Ă©vĂ©nement de demande d'ajout d'un jeton. + /// + /// Le jeton demandĂ© + private Jeton? QuandDemanderJeton() => DemanderJeton?.Invoke(this, new DemanderJetonEventArgs()); + /// + /// MĂ©thode pour dĂ©clencher l'Ă©vĂ©nement d'ajout d'un joueur. + /// + /// Le joueur Ă  ajouter. private void QuandAjouterJoueur(Joueur joueur) => AjouterJoueur?.Invoke(this, new AjouterJoueursEventArgs(joueur)); + + /// + /// MĂ©thode pour dĂ©clencher l'Ă©vĂ©nement du dĂ©but d'un partie. + /// private void QuandDebutPartie() => DebutPartie?.Invoke(this, new DebutPartieEventArgs()); + + + /// + /// MĂ©thode pour dĂ©clencher l'Ă©vĂ©nement d'un nouveau tour. + /// + /// Le joueur dont c'est le tour. + /// Le numĂ©ro du tour. + /// La grille de jeu. + /// Les indicateurs de jeu. private void QuandNouveauTour(Joueur joueur, int tour, IEnumerable> grille, IEnumerable> indicateurs) => NouveauTour?.Invoke(this, new NouveauTourEventArgs(joueur, tour, grille, indicateurs)); + + /// + /// MĂ©thode pour dĂ©clencher l'Ă©vĂ©nement d'ajout d'un nouveau jeton. + /// + /// Le jeton Ă  ajouter. private void QuandNouveauJeton(Jeton jeton) => AjouterJeton?.Invoke(this, new AjouterJetonEventArgs(jeton)); + + /// + /// MĂ©thode pour dĂ©clencher l'Ă©vĂ©nement de suppression du dernier jeton du code. + /// private void QuandSupprimerDernierJeton() => SupprimerDernierJeton?.Invoke(this, new SupprimerDernierJetonEventArgs()); + + /// + /// MĂ©thode pour dĂ©clencher l'Ă©vĂ©nement d'ajout d'un nouveau code. + /// + /// Le code Ă  ajouter. private void QuandNouveauCode(Code code) => AjouterCode?.Invoke(this, new AjouterCodeEventArgs(code)); + + /// + /// MĂ©thode pour dĂ©clencher l'Ă©vĂ©nement de passage de la main au joueur suivant. + /// private void QuandPasserMain() => PasserMain?.Invoke(this, new PasserMainEventArgs()); - private void QuandPartieTerminee(IEnumerable gagnants, IEnumerable perdants) => PartieTerminee?.Invoke(this, new PartieTermineeEventArgs(gagnants, perdants)); + /// + /// MĂ©thode pour dĂ©clencher l'Ă©vĂ©nement de fin de partie. + /// + /// La liste des joueurs gagnants. + /// La liste des joueurs perdants. + private void QuandPartieTerminee(IEnumerable gagnants, IEnumerable perdants) => PartieTerminee?.Invoke(this, new PartieTermineeEventArgs(gagnants, perdants)); + /// + /// CrĂ©e une nouvelle instance de la classe Partie. + /// + /// Les règles de la partie. public Partie(IRegles regles) { this.regles = regles; } + /// + /// Lance le dĂ©roulement de la partie. + /// public void Jouer() { + /// Ajout des joueurs jusqu'Ă  atteindre le nombre maximum de joueurs dĂ©fini par les règles while (regles.NbJoueurs != regles.NbJoueursMaximum) + while (regles.NbJoueurs != regles.NbJoueursMaximum) { string nom = QuandDemanderJoueur(regles.NbJoueurs + 1) ?? $"Joueur {regles.NbJoueurs+1}"; Joueur joueur = regles.AjouterJoueur(nom); QuandAjouterJoueur(joueur); } + /// DĂ©but de la partie regles.CommencerLaPartie(); QuandDebutPartie(); + /// Boucle principale du jeu qui dure jusqu'Ă  qu'une condition de fin soit dĂ©clenchĂ©e while (!regles.EstTerminee()) { Joueur joueurCourant = regles.JoueurCourant(); @@ -62,6 +172,7 @@ namespace CoreLibrary Code code = regles.GenererCode(); + /// Phase de saisie du code par le joueur jusqu'Ă  que le code soit complet. while (!code.EstComplet()) { Jeton? jeton = QuandDemanderJeton(); From 362f1888f43b582d345e747eab53ada35cd8bff4 Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Mon, 13 May 2024 01:42:10 +0200 Subject: [PATCH 36/36] Correction doc --- Sources/CoreLibrary/Partie.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/CoreLibrary/Partie.cs b/Sources/CoreLibrary/Partie.cs index 4ac30cf..1596cf0 100644 --- a/Sources/CoreLibrary/Partie.cs +++ b/Sources/CoreLibrary/Partie.cs @@ -158,11 +158,10 @@ namespace CoreLibrary QuandAjouterJoueur(joueur); } - /// DĂ©but de la partie regles.CommencerLaPartie(); QuandDebutPartie(); - /// Boucle principale du jeu qui dure jusqu'Ă  qu'une condition de fin soit dĂ©clenchĂ©e + // Boucle principale du jeu qui dure jusqu'Ă  qu'une condition de fin soit dĂ©clenchĂ©e while (!regles.EstTerminee()) { Joueur joueurCourant = regles.JoueurCourant(); @@ -172,7 +171,7 @@ namespace CoreLibrary Code code = regles.GenererCode(); - /// Phase de saisie du code par le joueur jusqu'Ă  que le code soit complet. + // Phase de saisie du code par le joueur jusqu'Ă  que le code soit complet. while (!code.EstComplet()) { Jeton? jeton = QuandDemanderJeton();