From e1ea013388c9863acbe8bf405a616b9dd7cc6f2e Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Fri, 3 May 2024 17:30:38 +0200 Subject: [PATCH] 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; }