Ajout de toutes les nouvelles exceptions
continuous-integration/drone/push Build is failing Details

master
Céleste BARBOSA 12 months ago
commit ff4edfe0e4

@ -1,4 +1,6 @@
namespace CoreLibrary using CoreLibrary.Exceptions;
namespace CoreLibrary
{ {
public class Code public class Code
{ {
@ -8,42 +10,57 @@
public Code(int tailleCode) public Code(int tailleCode)
{ {
if(tailleCode <= 0)
{
throw new TailleCodeException(tailleCode);
}
lesJetons = new Jeton?[tailleCode]; lesJetons = new Jeton?[tailleCode];
} }
public Code(IEnumerable<Jeton> jetons) public Code(IEnumerable<Jeton> jetons)
{ {
if (jetons.Count() == 0)
{
throw new TailleCodeException(jetons.Count());
}
lesJetons = new Jeton?[jetons.Count()]; lesJetons = new Jeton?[jetons.Count()];
foreach(Jeton jeton in jetons) foreach(Jeton jeton in jetons)
{
AjouterJeton(jeton); AjouterJeton(jeton);
} }
}
public void AjouterJeton(Jeton jeton) public void AjouterJeton(Jeton jeton)
{ {
if (EstComplet()) if (NbJetons == TailleMaximale())
throw new CodeTableauLesJetonsCompletException(); {
throw new CodeCompletException();
}
lesJetons[NbJetons++] = jeton; lesJetons[NbJetons++] = jeton;
} }
public void SupprimerDernierJeton() public void SupprimerDernierJeton()
{ {
if(NbJetons <= 0) if(NbJetons == 0)
throw new CodeTableauLesJetonsVideException(); {
throw new CodeVideException();
}
lesJetons[NbJetons-1] = null; lesJetons[--NbJetons] = null;
--NbJetons;
} }
public Jeton RecupererJeton(int indice) public Jeton RecupererJeton(int indice)
{ {
if(indice < 0 || indice > TailleMaximale()) if(indice < 0 || indice > TailleMaximale())
throw new CodeIndiceHorsDePorteeException(); throw new IndiceCodeException(indice, NbJetons-1);
Jeton? jeton = lesJetons[indice]; Jeton? jeton = lesJetons[indice];
if (!jeton.HasValue) if (!jeton.HasValue)
throw new CodeJetonNullException(); throw new IndiceCodeException(indice, NbJetons-1);
return jeton.Value; return jeton.Value;
} }
@ -66,11 +83,12 @@
public IEnumerable<Indicateur> Comparer(Code autreCode) public IEnumerable<Indicateur> Comparer(Code autreCode)
{ {
// Mon code est le code correct, l'autre code est celui qui teste // Mon code est le code correct, l'autre code est celui qui teste
if (!autreCode.EstComplet())
throw new CodeTableauLesJetonsIncompletException();
Indicateur[] indicateurs = []; Indicateur[] indicateurs = [];
if (EstComplet() || !autreCode.EstComplet())
return indicateurs;
Jeton?[] mesJetons = Jetons().ToArray(); Jeton?[] mesJetons = Jetons().ToArray();
Jeton?[] sesJetons = autreCode.Jetons().ToArray(); Jeton?[] sesJetons = autreCode.Jetons().ToArray();

@ -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")
{ }
}
}

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CoreLibrary
{
public class CodeJetonNullException : Exception
{
public CodeJetonNullException() : base("le jeton est 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")
{ }
}
}

@ -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")
{ }
}
}

@ -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")
{ }
}
}

@ -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.")
{ }
}
}

@ -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.")
{ }
}
}

@ -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}.")
{ }
}
}

@ -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.")
{ }
}
}

@ -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.")
{ }
}
}

@ -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}.")
{ }
}
}

@ -0,0 +1,9 @@
namespace CoreLibrary.Exceptions
{
public class PartieNonCommenceeException : Exception
{
public PartieNonCommenceeException() :
base("La partie n'a pas encore commencée.")
{ }
}
}

@ -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}.")
{ }
}
}

@ -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}.")
{ }
}
}

@ -10,7 +10,7 @@
int NbJoueurs { get; } int NbJoueurs { get; }
int NbJoueursMaximum { get; } int NbJoueursMaximum { get; }
void AjouterJoueur(string nom); Joueur AjouterJoueur(string nom);
Joueur JoueurCourant(); Joueur JoueurCourant();
void PasserLaMain(); void PasserLaMain();

@ -1,4 +1,6 @@
namespace CoreLibrary using CoreLibrary.Exceptions;
namespace CoreLibrary
{ {
public class Plateau public class Plateau
{ {
@ -17,12 +19,12 @@
{ {
if(tailleCode <= 0) if(tailleCode <= 0)
{ {
throw new PlateauTailleCodeException(); throw new TailleCodeException(tailleCode);
} }
if (tailleGrille <= 0) if (tailleGrille <= 0)
{ {
throw new PlateauTailleGrilleException(); throw new TailleGrilleException(tailleGrille);
} }
codeSecret = new Code(tailleCode); codeSecret = new Code(tailleCode);
@ -53,12 +55,12 @@
{ {
if (code.TailleMaximale() != tailleCode) if (code.TailleMaximale() != tailleCode)
{ {
throw new PlateauTailleCodeException(); throw new CodeInvalideException(code.TailleMaximale(), tailleCode);
} }
if (!code.EstComplet()) if (!code.EstComplet())
{ {
throw new PlateauCodeIncompletException(); throw new CodeIncompletException();
} }
indicateurs[Tour - 1] = codeSecret.Comparer(code); indicateurs[Tour - 1] = codeSecret.Comparer(code);
@ -73,6 +75,16 @@
public bool EstBonCode(Code code) public bool EstBonCode(Code code)
{ {
if (code.TailleMaximale() != tailleCode)
{
throw new CodeInvalideException(code.TailleMaximale(), tailleCode);
}
if (!code.EstComplet())
{
throw new CodeIncompletException();
}
IEnumerable<Indicateur> indicateurs = codeSecret.Comparer(code); IEnumerable<Indicateur> indicateurs = codeSecret.Comparer(code);
if (indicateurs.Count() != tailleCode) if (indicateurs.Count() != tailleCode)

@ -1,8 +0,0 @@
namespace CoreLibrary
{
public class PlateauCodeIncompletException : Exception
{
public PlateauCodeIncompletException() : base("Le code est incomplet")
{ }
}
}

@ -1,7 +0,0 @@
namespace CoreLibrary
{
public class PlateauTailleCodeException : Exception
{
public PlateauTailleCodeException() : base("La taille du code doit être positive non nulle.") { }
}
}

@ -1,7 +0,0 @@
namespace CoreLibrary
{
public class PlateauTailleCodeIncompleteException : Exception
{
public PlateauTailleCodeIncompleteException() : base("Le code n'est pas remplit au maximum") { }
}
}

@ -1,8 +0,0 @@
namespace CoreLibrary
{
public class PlateauTailleGrilleException : Exception
{
public PlateauTailleGrilleException() : base("La taille de la grille doit être égale positive non nulle.")
{ }
}
}

@ -1,4 +1,6 @@
namespace CoreLibrary using CoreLibrary.Exceptions;
namespace CoreLibrary
{ {
public class ReglesClassiques : IRegles public class ReglesClassiques : IRegles
{ {
@ -20,15 +22,17 @@
} }
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() public Joueur JoueurCourant()
{ {
if (!joueurCourant.HasValue) if (!joueurCourant.HasValue)
throw new ReglesClassiquesJoueurCourantNull(); throw new PartieNonCommenceeException();
return joueurs[joueurCourant.Value]; return joueurs[joueurCourant.Value];
} }
@ -37,7 +41,7 @@
{ {
if (!joueurCourant.HasValue) if (!joueurCourant.HasValue)
{ {
throw new ReglesClassiquesJoueurCourantNull(); throw new PartieNonCommenceeException();
} }
joueurCourant++; joueurCourant++;

@ -1,8 +0,0 @@
namespace CoreLibrary
{
public class ReglesClassiquesJoueurCourantNull : Exception
{
public ReglesClassiquesJoueurCourantNull() : base("Le joueur courant est null")
{ }
}
}
Loading…
Cancel
Save