Merge branch 'master' of https://codefirst.iut.uca.fr/git/nicolas.barbosa/mastermind
continuous-integration/drone/push Build is passing Details

master
Céleste BARBOSA 12 months ago
commit 70abac1344

@ -10,8 +10,36 @@ ReglesClassiques partie = new ReglesClassiques();
Utils.AfficherTitre(); Utils.AfficherTitre();
Utils.AfficherTitre("Joueurs"); 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(); Utils.AfficherSeparateur();
partie.AjouterJoueur(joueur1); partie.AjouterJoueur(joueur1);

@ -62,8 +62,13 @@ namespace ConsoleApp
Console.WriteLine(nom); Console.WriteLine(nom);
Console.Write(">>> "); Console.Write(">>> ");
nom = Console.ReadLine() ?? nom; nom = Console.ReadLine() ?? nom;
if (nom == "")
{
--nombreJoueurs;
throw new UtilsNomJoueurNullException();
}
Console.WriteLine(); Console.WriteLine();
return nom; return nom;
} }
@ -218,7 +223,15 @@ namespace ConsoleApp
else else
{ {
Console.Write("\b\b\b \b\b\b\b\b\b\b\b\b\b\b\b"); 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");
}
} }
} }
} }

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

@ -7,7 +7,7 @@
public int NbJetons { get; private set; } = 0; public int NbJetons { get; private set; } = 0;
public Code(int tailleCode) public Code(int tailleCode)
{ {
lesJetons = new Jeton?[tailleCode]; lesJetons = new Jeton?[tailleCode];
} }
@ -19,22 +19,31 @@
} }
public void AjouterJeton(Jeton jeton) public void AjouterJeton(Jeton jeton)
{ {
if (EstComplet())
throw new CodeTableauLesJetonsCompletException();
lesJetons[NbJetons++] = jeton; lesJetons[NbJetons++] = jeton;
} }
public void SupprimerDernierJeton() public void SupprimerDernierJeton()
{ {
if(NbJetons <= 0)
throw new CodeTableauLesJetonsVideException();
lesJetons[NbJetons--] = null; lesJetons[NbJetons--] = null;
} }
public Jeton RecupererJeton(int indice) public Jeton RecupererJeton(int indice)
{ {
if(indice < 0 || indice > TailleMaximale())
throw new CodeIndiceHorsDePorteeException();
Jeton? jeton = lesJetons[indice]; Jeton? jeton = lesJetons[indice];
if (!jeton.HasValue) if (!jeton.HasValue)
throw new Exception(); throw new CodeJetonNullException();
return jeton.Value; return jeton.Value;
} }
@ -56,6 +65,8 @@
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 = [];
@ -102,3 +113,5 @@
} }
} }
} }

@ -0,0 +1,14 @@
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")
{ }
}
}

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

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

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

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

@ -15,6 +15,16 @@
public Plateau(int tailleCode, int tailleGrille) public Plateau(int tailleCode, int tailleGrille)
{ {
if(tailleCode <= 0)
{
throw new PlateauTailleCodeException();
}
if (tailleGrille <= 0)
{
throw new PlateauTailleGrilleException();
}
codeSecret = new Code(tailleCode); codeSecret = new Code(tailleCode);
grille = new Code?[tailleGrille]; grille = new Code?[tailleGrille];
indicateurs = new IEnumerable<Indicateur>[tailleGrille]; indicateurs = new IEnumerable<Indicateur>[tailleGrille];
@ -22,11 +32,6 @@
this.tailleCode = tailleCode; this.tailleCode = tailleCode;
GenererCodeAleatoire(); GenererCodeAleatoire();
foreach (Jeton? jeton in codeSecret.Jetons())
{
Console.WriteLine(jeton.Value.Couleur);
}
} }
private void GenererCodeAleatoire() private void GenererCodeAleatoire()
@ -46,6 +51,16 @@
public void AjouterCode(Code code) public void AjouterCode(Code code)
{ {
if (code.TailleMaximale() != tailleCode)
{
throw new PlateauTailleCodeException();
}
if (!code.EstComplet())
{
throw new PlateauCodeIncompletException();
}
indicateurs[Tour - 1] = codeSecret.Comparer(code); indicateurs[Tour - 1] = codeSecret.Comparer(code);
grille[Tour - 1] = code; grille[Tour - 1] = code;
++Tour; ++Tour;
@ -94,3 +109,4 @@
} }
} }
} }

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

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

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

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

@ -10,7 +10,6 @@
public int TourMaximum { get => 12; } public int TourMaximum { get => 12; }
public int TailleCodeMaximum { get => 4; } public int TailleCodeMaximum { get => 4; }
public int NbJoueurs { get => nbJoueurs; } public int NbJoueurs { get => nbJoueurs; }
public int NbJoueursMaximum { get => 2; } public int NbJoueursMaximum { get => 2; }
@ -29,7 +28,7 @@
public Joueur JoueurCourant() public Joueur JoueurCourant()
{ {
if (!joueurCourant.HasValue) if (!joueurCourant.HasValue)
throw new Exception(); throw new ReglesClassiquesJoueurCourantNull();
return joueurs[joueurCourant.Value]; return joueurs[joueurCourant.Value];
} }
@ -37,7 +36,9 @@
public void PasserLaMain() public void PasserLaMain()
{ {
if (!joueurCourant.HasValue) if (!joueurCourant.HasValue)
throw new Exception(); {
throw new ReglesClassiquesJoueurCourantNull();
}
joueurCourant++; joueurCourant++;
if (joueurCourant >= joueurs.Length) if (joueurCourant >= joueurs.Length)

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