From 0eae7d04a0356efc6ddc8cfaadd4305425eae057 Mon Sep 17 00:00:00 2001 From: "pauline.prady" Date: Fri, 3 May 2024 15:49:47 +0200 Subject: [PATCH 1/8] =?UTF-8?q?Cr=C3=A9ation=20branche=20exception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/CoreLibrary/Plateau.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/CoreLibrary/Plateau.cs b/Sources/CoreLibrary/Plateau.cs index 2017fa7..52d806f 100644 --- a/Sources/CoreLibrary/Plateau.cs +++ b/Sources/CoreLibrary/Plateau.cs @@ -94,3 +94,4 @@ } } } + From 438f36364203e49c22df733414e0989eb9a19d8b Mon Sep 17 00:00:00 2001 From: "pauline.prady" Date: Fri, 3 May 2024 17:08:14 +0200 Subject: [PATCH 2/8] Mise en place des exception pour Plateau et ReglesClassiques --- Sources/CoreLibrary/Plateau.cs | 20 ++++++++++++++----- .../PlateauCodeIncompletException.cs | 8 ++++++++ .../CoreLibrary/PlateauTailleCodeException.cs | 7 +++++++ .../PlateauTailleGrilleException.cs | 8 ++++++++ Sources/CoreLibrary/ReglesClassiques.cs | 6 ++++-- .../ReglesClassiquesJoueurCourantNull.cs | 8 ++++++++ 6 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 Sources/CoreLibrary/PlateauCodeIncompletException.cs create mode 100644 Sources/CoreLibrary/PlateauTailleCodeException.cs create mode 100644 Sources/CoreLibrary/PlateauTailleGrilleException.cs create mode 100644 Sources/CoreLibrary/ReglesClassiquesJoueurCourantNull.cs diff --git a/Sources/CoreLibrary/Plateau.cs b/Sources/CoreLibrary/Plateau.cs index 52d806f..3a78e43 100644 --- a/Sources/CoreLibrary/Plateau.cs +++ b/Sources/CoreLibrary/Plateau.cs @@ -15,6 +15,16 @@ public Plateau(int tailleCode, int tailleGrille) { + if(tailleCode <= 0) + { + throw new PlateauTailleCodeException(); + } + + if (tailleGrille != tailleCode) + { + throw new PlateauTailleCodeException(); + } + codeSecret = new Code(tailleCode); grille = new Code?[tailleGrille]; indicateurs = new IEnumerable[tailleGrille]; @@ -22,11 +32,6 @@ this.tailleCode = tailleCode; GenererCodeAleatoire(); - - foreach (Jeton? jeton in codeSecret.Jetons()) - { - Console.WriteLine(jeton.Value.Couleur); - } } private void GenererCodeAleatoire() @@ -46,6 +51,11 @@ public void AjouterCode(Code code) { + if (code.NbJetons < tailleCode || !code.EstComplet()) + { + throw new PlateauCodeIncompletException(); + } + indicateurs[Tour - 1] = codeSecret.Comparer(code); grille[Tour - 1] = code; ++Tour; diff --git a/Sources/CoreLibrary/PlateauCodeIncompletException.cs b/Sources/CoreLibrary/PlateauCodeIncompletException.cs new file mode 100644 index 0000000..d522cb4 --- /dev/null +++ b/Sources/CoreLibrary/PlateauCodeIncompletException.cs @@ -0,0 +1,8 @@ +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 new file mode 100644 index 0000000..45d3253 --- /dev/null +++ b/Sources/CoreLibrary/PlateauTailleCodeException.cs @@ -0,0 +1,7 @@ +namespace CoreLibrary +{ + public class PlateauTailleCodeException : Exception + { + public PlateauTailleCodeException() : base("La taille du code doit être positif") { } + } +} diff --git a/Sources/CoreLibrary/PlateauTailleGrilleException.cs b/Sources/CoreLibrary/PlateauTailleGrilleException.cs new file mode 100644 index 0000000..5d0bbfe --- /dev/null +++ b/Sources/CoreLibrary/PlateauTailleGrilleException.cs @@ -0,0 +1,8 @@ +namespace CoreLibrary +{ + public class PlateauTailleGrilleException : Exception + { + public PlateauTailleGrilleException() : base("La taille de la grille doit être égale à la taille du code") + { } + } +} diff --git a/Sources/CoreLibrary/ReglesClassiques.cs b/Sources/CoreLibrary/ReglesClassiques.cs index 632c259..fb1b839 100644 --- a/Sources/CoreLibrary/ReglesClassiques.cs +++ b/Sources/CoreLibrary/ReglesClassiques.cs @@ -29,7 +29,7 @@ public Joueur JoueurCourant() { if (!joueurCourant.HasValue) - throw new Exception(); + throw new ReglesClassiquesJoueurCourantNull(); return joueurs[joueurCourant.Value]; } @@ -37,7 +37,9 @@ public void PasserLaMain() { if (!joueurCourant.HasValue) - throw new Exception(); + { + throw new ReglesClassiquesJoueurCourantNull(); + } joueurCourant++; if (joueurCourant >= joueurs.Length) diff --git a/Sources/CoreLibrary/ReglesClassiquesJoueurCourantNull.cs b/Sources/CoreLibrary/ReglesClassiquesJoueurCourantNull.cs new file mode 100644 index 0000000..89e6df5 --- /dev/null +++ b/Sources/CoreLibrary/ReglesClassiquesJoueurCourantNull.cs @@ -0,0 +1,8 @@ +namespace CoreLibrary +{ + public class ReglesClassiquesJoueurCourantNull : Exception + { + public ReglesClassiquesJoueurCourantNull() : base("Le joueur courant est null") + { } + } +} From f6e5af324b3ea46482c38ffe502f23832a822625 Mon Sep 17 00:00:00 2001 From: "pauline.prady" Date: Fri, 3 May 2024 17:19:23 +0200 Subject: [PATCH 3/8] Correction exception Plateau --- Sources/CoreLibrary/Plateau.cs | 7 ++++++- .../CoreLibrary/PlateauTailleCodeIncompleteException.cs | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 Sources/CoreLibrary/PlateauTailleCodeIncompleteException.cs diff --git a/Sources/CoreLibrary/Plateau.cs b/Sources/CoreLibrary/Plateau.cs index 3a78e43..b1c885f 100644 --- a/Sources/CoreLibrary/Plateau.cs +++ b/Sources/CoreLibrary/Plateau.cs @@ -51,7 +51,12 @@ public void AjouterCode(Code code) { - if (code.NbJetons < tailleCode || !code.EstComplet()) + if (code.NbJetons < tailleCode) + { + throw new PlateauTailleCodeIncompleteException(); + } + + if (!code.EstComplet()) { throw new PlateauCodeIncompletException(); } diff --git a/Sources/CoreLibrary/PlateauTailleCodeIncompleteException.cs b/Sources/CoreLibrary/PlateauTailleCodeIncompleteException.cs new file mode 100644 index 0000000..38133c7 --- /dev/null +++ b/Sources/CoreLibrary/PlateauTailleCodeIncompleteException.cs @@ -0,0 +1,7 @@ +namespace CoreLibrary +{ + public class PlateauTailleCodeIncompleteException : Exception + { + public PlateauTailleCodeIncompleteException() : base("Le code n'est pas remplit au maximum") { } + } +} From 4d41996e8a5b4bee9e38d1a61ef535da1051d6bf Mon Sep 17 00:00:00 2001 From: "pauline.prady" Date: Fri, 3 May 2024 17:29:37 +0200 Subject: [PATCH 4/8] =?UTF-8?q?Modificaion=20incompl=C3=A8te?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/CoreLibrary/Plateau.cs | 10 +++++----- Sources/CoreLibrary/PlateauTailleCodeException.cs | 2 +- Sources/CoreLibrary/PlateauTailleGrilleException.cs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/CoreLibrary/Plateau.cs b/Sources/CoreLibrary/Plateau.cs index b1c885f..900718e 100644 --- a/Sources/CoreLibrary/Plateau.cs +++ b/Sources/CoreLibrary/Plateau.cs @@ -20,9 +20,9 @@ throw new PlateauTailleCodeException(); } - if (tailleGrille != tailleCode) + if (tailleGrille <= 0) { - throw new PlateauTailleCodeException(); + throw new PlateauTailleGrilleException(); } codeSecret = new Code(tailleCode); @@ -51,14 +51,14 @@ public void AjouterCode(Code code) { - if (code.NbJetons < tailleCode) + if (code.TailleMaximale() != tailleCode) { - throw new PlateauTailleCodeIncompleteException(); + throw new CodeTailleMaximaleException(); } if (!code.EstComplet()) { - throw new PlateauCodeIncompletException(); + throw new CodeIncompletException(); } indicateurs[Tour - 1] = codeSecret.Comparer(code); diff --git a/Sources/CoreLibrary/PlateauTailleCodeException.cs b/Sources/CoreLibrary/PlateauTailleCodeException.cs index 45d3253..a73ed73 100644 --- a/Sources/CoreLibrary/PlateauTailleCodeException.cs +++ b/Sources/CoreLibrary/PlateauTailleCodeException.cs @@ -2,6 +2,6 @@ { public class PlateauTailleCodeException : Exception { - public PlateauTailleCodeException() : base("La taille du code doit être positif") { } + public PlateauTailleCodeException() : base("La taille du code doit être positive non nulle.") { } } } diff --git a/Sources/CoreLibrary/PlateauTailleGrilleException.cs b/Sources/CoreLibrary/PlateauTailleGrilleException.cs index 5d0bbfe..1305e65 100644 --- a/Sources/CoreLibrary/PlateauTailleGrilleException.cs +++ b/Sources/CoreLibrary/PlateauTailleGrilleException.cs @@ -2,7 +2,7 @@ { public class PlateauTailleGrilleException : Exception { - public PlateauTailleGrilleException() : base("La taille de la grille doit être égale à la taille du code") + public PlateauTailleGrilleException() : base("La taille de la grille doit être égale positive non nulle.") { } } } From e1ea013388c9863acbe8bf405a616b9dd7cc6f2e Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Fri, 3 May 2024 17:30:38 +0200 Subject: [PATCH 5/8] Exception code --- Sources/CoreLibrary/Code.cs | 21 +++++++++++++++---- .../CodeIndiceInvalideException.cs | 19 +++++++++++++++++ .../CoreLibrary/CodeJetonInvalideException.cs | 19 +++++++++++++++++ .../CoreLibrary/CodeTailleTableauException.cs | 19 +++++++++++++++++ .../CodeTailleTableauLesJetonsException.cs | 19 +++++++++++++++++ Sources/CoreLibrary/ReglesClassiques.cs | 1 - 6 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 Sources/CoreLibrary/CodeIndiceInvalideException.cs create mode 100644 Sources/CoreLibrary/CodeJetonInvalideException.cs create mode 100644 Sources/CoreLibrary/CodeTailleTableauException.cs create mode 100644 Sources/CoreLibrary/CodeTailleTableauLesJetonsException.cs diff --git a/Sources/CoreLibrary/Code.cs b/Sources/CoreLibrary/Code.cs index 29c865f..5a05346 100644 --- a/Sources/CoreLibrary/Code.cs +++ b/Sources/CoreLibrary/Code.cs @@ -7,7 +7,7 @@ public int NbJetons { get; private set; } = 0; public Code(int tailleCode) - { + { lesJetons = new Jeton?[tailleCode]; } @@ -17,22 +17,31 @@ } public void AjouterJeton(Jeton jeton) - { + { + if (NbJetons >= TailleMaximale() ) + throw new CodeTailleTableauLesJetonsException(); + lesJetons[NbJetons++] = jeton; } public void SupprimerDernierJeton() { + if(NbJetons <= 0) + throw new CodeTailleTableauLesJetonsException(); + lesJetons[NbJetons--] = null; } public Jeton RecupererJeton(int indice) { + if(indice < 0 || indice > TailleMaximale()) + throw new CodeIndiceInvalideException(); + Jeton? jeton = lesJetons[indice]; if (!jeton.HasValue) - throw new Exception(); - + throw new CodeJetonInvalideException(); + return jeton.Value; } @@ -54,6 +63,8 @@ public IEnumerable Comparer(Code autreCode) { // Mon code est le code correct, l'autre code est celui qui teste + if (autreCode.NbJetons <= TailleMaximale() ) + throw new CodeTailleTableauLesJetonsException(); Indicateur[] indicateurs = []; @@ -100,3 +111,5 @@ } } } + + diff --git a/Sources/CoreLibrary/CodeIndiceInvalideException.cs b/Sources/CoreLibrary/CodeIndiceInvalideException.cs new file mode 100644 index 0000000..d6ba08f --- /dev/null +++ b/Sources/CoreLibrary/CodeIndiceInvalideException.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CoreLibrary +{ + public class CodeIndiceInvalideException : Exception + { + public CodeIndiceInvalideException() { } + + public CodeIndiceInvalideException(string message) + : base(message) { } + + public CodeIndiceInvalideException(string message, Exception inner) + : base(message, inner) { } + } +} diff --git a/Sources/CoreLibrary/CodeJetonInvalideException.cs b/Sources/CoreLibrary/CodeJetonInvalideException.cs new file mode 100644 index 0000000..dcdccd3 --- /dev/null +++ b/Sources/CoreLibrary/CodeJetonInvalideException.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CoreLibrary +{ + internal class CodeJetonInvalideException : Exception + { + public CodeJetonInvalideException() { } + + public CodeJetonInvalideException(string message) + : base(message) { } + + public CodeJetonInvalideException(string message, Exception inner) + : base(message, inner) { } + } +} diff --git a/Sources/CoreLibrary/CodeTailleTableauException.cs b/Sources/CoreLibrary/CodeTailleTableauException.cs new file mode 100644 index 0000000..a8b817b --- /dev/null +++ b/Sources/CoreLibrary/CodeTailleTableauException.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CoreLibrary +{ + public class CodeTailleTableauException : Exception + { + public CodeTailleTableauException() { } + + public CodeTailleTableauException(string message) + : base(message) { } + + public CodeTailleTableauException(string message, Exception inner) + : base(message, inner) { } + } +} diff --git a/Sources/CoreLibrary/CodeTailleTableauLesJetonsException.cs b/Sources/CoreLibrary/CodeTailleTableauLesJetonsException.cs new file mode 100644 index 0000000..6b5e95d --- /dev/null +++ b/Sources/CoreLibrary/CodeTailleTableauLesJetonsException.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CoreLibrary +{ + public class CodeTailleTableauLesJetonsException : Exception + { + public CodeTailleTableauLesJetonsException() { } + + public CodeTailleTableauLesJetonsException(string message) + : base(message) { } + + public CodeTailleTableauLesJetonsException(string message, Exception inner) + : base(message, inner) { } + } +} diff --git a/Sources/CoreLibrary/ReglesClassiques.cs b/Sources/CoreLibrary/ReglesClassiques.cs index 632c259..85ba7d9 100644 --- a/Sources/CoreLibrary/ReglesClassiques.cs +++ b/Sources/CoreLibrary/ReglesClassiques.cs @@ -10,7 +10,6 @@ public int TourMaximum { get => 12; } public int TailleCodeMaximum { get => 4; } - public int NbJoueurs { get => nbJoueurs; } public int NbJoueursMaximum { get => 2; } From e0ad921724a5a01c1bead09b68d47aba794f0087 Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Fri, 3 May 2024 18:49:48 +0200 Subject: [PATCH 6/8] Exception de la Class code --- Sources/CoreLibrary/Code.cs | 14 +++++++------- .../CodeIndiceHorsDePortéeException.cs | 14 ++++++++++++++ .../CodeIndiceInvalideException.cs | 19 ------------------- .../CoreLibrary/CodeJetonInvalideException.cs | 19 ------------------- Sources/CoreLibrary/CodeJetonNullException.cs | 14 ++++++++++++++ .../CodeTableauLesJetonsIncompletException.cs | 14 ++++++++++++++ .../CodeTableauLesJetonsVideException.cs | 14 ++++++++++++++ .../CoreLibrary/CodeTailleTableauException.cs | 19 ------------------- ...eTailleTableauLesJetonsCompletException.cs | 15 +++++++++++++++ .../CodeTailleTableauLesJetonsException.cs | 19 ------------------- Sources/CoreLibrary/Plateau.cs | 4 ++-- 11 files changed, 80 insertions(+), 85 deletions(-) create mode 100644 Sources/CoreLibrary/CodeIndiceHorsDePortéeException.cs delete mode 100644 Sources/CoreLibrary/CodeIndiceInvalideException.cs delete mode 100644 Sources/CoreLibrary/CodeJetonInvalideException.cs create mode 100644 Sources/CoreLibrary/CodeJetonNullException.cs create mode 100644 Sources/CoreLibrary/CodeTableauLesJetonsIncompletException.cs create mode 100644 Sources/CoreLibrary/CodeTableauLesJetonsVideException.cs delete mode 100644 Sources/CoreLibrary/CodeTailleTableauException.cs create mode 100644 Sources/CoreLibrary/CodeTailleTableauLesJetonsCompletException.cs delete mode 100644 Sources/CoreLibrary/CodeTailleTableauLesJetonsException.cs diff --git a/Sources/CoreLibrary/Code.cs b/Sources/CoreLibrary/Code.cs index 5a05346..6a1c653 100644 --- a/Sources/CoreLibrary/Code.cs +++ b/Sources/CoreLibrary/Code.cs @@ -18,8 +18,8 @@ public void AjouterJeton(Jeton jeton) { - if (NbJetons >= TailleMaximale() ) - throw new CodeTailleTableauLesJetonsException(); + if (EstComplet()) + throw new CodeTailleTableauLesJetonsCompletException(); lesJetons[NbJetons++] = jeton; } @@ -27,7 +27,7 @@ public void SupprimerDernierJeton() { if(NbJetons <= 0) - throw new CodeTailleTableauLesJetonsException(); + throw new CodeTableauLesJetonsVideException(); lesJetons[NbJetons--] = null; } @@ -35,12 +35,12 @@ public Jeton RecupererJeton(int indice) { if(indice < 0 || indice > TailleMaximale()) - throw new CodeIndiceInvalideException(); + throw new CodeIndiceHorsDePortéeException(); Jeton? jeton = lesJetons[indice]; if (!jeton.HasValue) - throw new CodeJetonInvalideException(); + throw new CodeJetonNullException(); return jeton.Value; } @@ -63,8 +63,8 @@ public IEnumerable Comparer(Code autreCode) { // Mon code est le code correct, l'autre code est celui qui teste - if (autreCode.NbJetons <= TailleMaximale() ) - throw new CodeTailleTableauLesJetonsException(); + if (!autreCode.EstComplet()) + throw new CodeTailleTableauLesJetonsCompletException(); Indicateur[] indicateurs = []; diff --git a/Sources/CoreLibrary/CodeIndiceHorsDePortéeException.cs b/Sources/CoreLibrary/CodeIndiceHorsDePortéeException.cs new file mode 100644 index 0000000..1dd987e --- /dev/null +++ b/Sources/CoreLibrary/CodeIndiceHorsDePortéeException.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CoreLibrary +{ + public class CodeIndiceHorsDePortéeException : Exception + { + public CodeIndiceHorsDePortéeException() : base("L'indice pointe en dehors du tableau") + { } + } +} diff --git a/Sources/CoreLibrary/CodeIndiceInvalideException.cs b/Sources/CoreLibrary/CodeIndiceInvalideException.cs deleted file mode 100644 index d6ba08f..0000000 --- a/Sources/CoreLibrary/CodeIndiceInvalideException.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CoreLibrary -{ - public class CodeIndiceInvalideException : Exception - { - public CodeIndiceInvalideException() { } - - public CodeIndiceInvalideException(string message) - : base(message) { } - - public CodeIndiceInvalideException(string message, Exception inner) - : base(message, inner) { } - } -} diff --git a/Sources/CoreLibrary/CodeJetonInvalideException.cs b/Sources/CoreLibrary/CodeJetonInvalideException.cs deleted file mode 100644 index dcdccd3..0000000 --- a/Sources/CoreLibrary/CodeJetonInvalideException.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CoreLibrary -{ - internal class CodeJetonInvalideException : Exception - { - public CodeJetonInvalideException() { } - - public CodeJetonInvalideException(string message) - : base(message) { } - - public CodeJetonInvalideException(string message, Exception inner) - : base(message, inner) { } - } -} diff --git a/Sources/CoreLibrary/CodeJetonNullException.cs b/Sources/CoreLibrary/CodeJetonNullException.cs new file mode 100644 index 0000000..9fcc9f3 --- /dev/null +++ b/Sources/CoreLibrary/CodeJetonNullException.cs @@ -0,0 +1,14 @@ +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/CodeTableauLesJetonsIncompletException.cs b/Sources/CoreLibrary/CodeTableauLesJetonsIncompletException.cs new file mode 100644 index 0000000..2205f9c --- /dev/null +++ b/Sources/CoreLibrary/CodeTableauLesJetonsIncompletException.cs @@ -0,0 +1,14 @@ +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 new file mode 100644 index 0000000..d9300f8 --- /dev/null +++ b/Sources/CoreLibrary/CodeTableauLesJetonsVideException.cs @@ -0,0 +1,14 @@ +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/CodeTailleTableauException.cs b/Sources/CoreLibrary/CodeTailleTableauException.cs deleted file mode 100644 index a8b817b..0000000 --- a/Sources/CoreLibrary/CodeTailleTableauException.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CoreLibrary -{ - public class CodeTailleTableauException : Exception - { - public CodeTailleTableauException() { } - - public CodeTailleTableauException(string message) - : base(message) { } - - public CodeTailleTableauException(string message, Exception inner) - : base(message, inner) { } - } -} diff --git a/Sources/CoreLibrary/CodeTailleTableauLesJetonsCompletException.cs b/Sources/CoreLibrary/CodeTailleTableauLesJetonsCompletException.cs new file mode 100644 index 0000000..b0ec0c9 --- /dev/null +++ b/Sources/CoreLibrary/CodeTailleTableauLesJetonsCompletException.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CoreLibrary +{ + public class CodeTailleTableauLesJetonsCompletException : Exception + { + public CodeTailleTableauLesJetonsCompletException() : base("Le tableau des jetons est plein") + { } + + } +} diff --git a/Sources/CoreLibrary/CodeTailleTableauLesJetonsException.cs b/Sources/CoreLibrary/CodeTailleTableauLesJetonsException.cs deleted file mode 100644 index 6b5e95d..0000000 --- a/Sources/CoreLibrary/CodeTailleTableauLesJetonsException.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CoreLibrary -{ - public class CodeTailleTableauLesJetonsException : Exception - { - public CodeTailleTableauLesJetonsException() { } - - public CodeTailleTableauLesJetonsException(string message) - : base(message) { } - - public CodeTailleTableauLesJetonsException(string message, Exception inner) - : base(message, inner) { } - } -} diff --git a/Sources/CoreLibrary/Plateau.cs b/Sources/CoreLibrary/Plateau.cs index 900718e..d8b0c16 100644 --- a/Sources/CoreLibrary/Plateau.cs +++ b/Sources/CoreLibrary/Plateau.cs @@ -53,12 +53,12 @@ { if (code.TailleMaximale() != tailleCode) { - throw new CodeTailleMaximaleException(); + throw new PlateauTailleCodeException(); } if (!code.EstComplet()) { - throw new CodeIncompletException(); + throw new PlateauCodeIncompletException(); } indicateurs[Tour - 1] = codeSecret.Comparer(code); From f96fe5ab9ff2784780ddd9a91949d055168c6fc8 Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Fri, 3 May 2024 20:00:03 +0200 Subject: [PATCH 7/8] Exception de la class code --- Sources/CoreLibrary/Code.cs | 4 ++-- .../CodeTableauLesJetonsCompletException.cs | 15 +++++++++++++++ .../CodeTailleTableauLesJetonsCompletException.cs | 15 --------------- 3 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 Sources/CoreLibrary/CodeTableauLesJetonsCompletException.cs delete mode 100644 Sources/CoreLibrary/CodeTailleTableauLesJetonsCompletException.cs diff --git a/Sources/CoreLibrary/Code.cs b/Sources/CoreLibrary/Code.cs index 6a1c653..c8d3d7a 100644 --- a/Sources/CoreLibrary/Code.cs +++ b/Sources/CoreLibrary/Code.cs @@ -19,7 +19,7 @@ public void AjouterJeton(Jeton jeton) { if (EstComplet()) - throw new CodeTailleTableauLesJetonsCompletException(); + throw new CodeTableauLesJetonsCompletException(); lesJetons[NbJetons++] = jeton; } @@ -64,7 +64,7 @@ { // Mon code est le code correct, l'autre code est celui qui teste if (!autreCode.EstComplet()) - throw new CodeTailleTableauLesJetonsCompletException(); + throw new CodeTableauLesJetonsIncompletException(); Indicateur[] indicateurs = []; diff --git a/Sources/CoreLibrary/CodeTableauLesJetonsCompletException.cs b/Sources/CoreLibrary/CodeTableauLesJetonsCompletException.cs new file mode 100644 index 0000000..dfc3d44 --- /dev/null +++ b/Sources/CoreLibrary/CodeTableauLesJetonsCompletException.cs @@ -0,0 +1,15 @@ +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/CodeTailleTableauLesJetonsCompletException.cs b/Sources/CoreLibrary/CodeTailleTableauLesJetonsCompletException.cs deleted file mode 100644 index b0ec0c9..0000000 --- a/Sources/CoreLibrary/CodeTailleTableauLesJetonsCompletException.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 CodeTailleTableauLesJetonsCompletException : Exception - { - public CodeTailleTableauLesJetonsCompletException() : base("Le tableau des jetons est plein") - { } - - } -} From 1211235cd36ac02e6a42db3ca3dbad739e4c887d Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Sat, 4 May 2024 11:15:18 +0200 Subject: [PATCH 8/8] Exception application console --- Sources/ConsoleApp/Program.cs | 32 +++++++++++++++++-- Sources/ConsoleApp/Utils.cs | 17 ++++++++-- .../ConsoleApp/UtilsNomJoueurNullException.cs | 14 ++++++++ Sources/CoreLibrary/Code.cs | 2 +- ....cs => CodeIndiceHorsDePorteeException.cs} | 4 +-- 5 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 Sources/ConsoleApp/UtilsNomJoueurNullException.cs rename Sources/CoreLibrary/{CodeIndiceHorsDePortéeException.cs => CodeIndiceHorsDePorteeException.cs} (51%) diff --git a/Sources/ConsoleApp/Program.cs b/Sources/ConsoleApp/Program.cs index fc9e32a..475a617 100644 --- a/Sources/ConsoleApp/Program.cs +++ b/Sources/ConsoleApp/Program.cs @@ -10,8 +10,36 @@ ReglesClassiques partie = new ReglesClassiques(); Utils.AfficherTitre(); Utils.AfficherTitre("Joueurs"); -string joueur1 = Utils.SaisirNom(); -string joueur2 = Utils.SaisirNom(); + +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); diff --git a/Sources/ConsoleApp/Utils.cs b/Sources/ConsoleApp/Utils.cs index b19d651..76b1885 100644 --- a/Sources/ConsoleApp/Utils.cs +++ b/Sources/ConsoleApp/Utils.cs @@ -62,8 +62,13 @@ namespace ConsoleApp Console.WriteLine(nom); Console.Write(">>> "); nom = Console.ReadLine() ?? nom; + if (nom == "") + { + --nombreJoueurs; + throw new UtilsNomJoueurNullException(); + } Console.WriteLine(); - + return nom; } @@ -218,7 +223,15 @@ namespace ConsoleApp else { Console.Write("\b\b\b \b\b\b\b\b\b\b\b\b\b\b\b"); - code.SupprimerDernierJeton(); + try + { + code.SupprimerDernierJeton(); + } + catch(CodeTableauLesJetonsVideException) + { + Console.WriteLine("Il n'y a pas de jetons! Impossible de supprimer"); + } + } } } diff --git a/Sources/ConsoleApp/UtilsNomJoueurNullException.cs b/Sources/ConsoleApp/UtilsNomJoueurNullException.cs new file mode 100644 index 0000000..20187e7 --- /dev/null +++ b/Sources/ConsoleApp/UtilsNomJoueurNullException.cs @@ -0,0 +1,14 @@ +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/Code.cs b/Sources/CoreLibrary/Code.cs index c8d3d7a..79e10b3 100644 --- a/Sources/CoreLibrary/Code.cs +++ b/Sources/CoreLibrary/Code.cs @@ -35,7 +35,7 @@ public Jeton RecupererJeton(int indice) { if(indice < 0 || indice > TailleMaximale()) - throw new CodeIndiceHorsDePortéeException(); + throw new CodeIndiceHorsDePorteeException(); Jeton? jeton = lesJetons[indice]; diff --git a/Sources/CoreLibrary/CodeIndiceHorsDePortéeException.cs b/Sources/CoreLibrary/CodeIndiceHorsDePorteeException.cs similarity index 51% rename from Sources/CoreLibrary/CodeIndiceHorsDePortéeException.cs rename to Sources/CoreLibrary/CodeIndiceHorsDePorteeException.cs index 1dd987e..36c0929 100644 --- a/Sources/CoreLibrary/CodeIndiceHorsDePortéeException.cs +++ b/Sources/CoreLibrary/CodeIndiceHorsDePorteeException.cs @@ -6,9 +6,9 @@ using System.Threading.Tasks; namespace CoreLibrary { - public class CodeIndiceHorsDePortéeException : Exception + public class CodeIndiceHorsDePorteeException : Exception { - public CodeIndiceHorsDePortéeException() : base("L'indice pointe en dehors du tableau") + public CodeIndiceHorsDePorteeException() : base("L'indice pointe en dehors du tableau") { } } }