You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mastermind/CoreLibrary/CombinaisonSecrete.cs

48 lines
1.4 KiB

namespace BibliothequeClasses
{
public class CombinaisonSecrete : Combinaison
{
private static readonly Couleur[] couleurs = (Couleur[])Enum.GetValues(typeof(Couleur));
private static readonly Random rand = new Random();
public CombinaisonSecrete()
{
for(int i = 0; i < Combinaison.taillePhysique; i++) {
this.AjouterJetonAleatoire();
}
}
private void AjouterJetonAleatoire()
{
JetonJoueur jeton = CombinaisonSecrete.GenererJetonAleatoire();
base.AjouterJeton(jeton);
}
private static JetonJoueur GenererJetonAleatoire()
{
int indice = rand.Next(couleurs.Length);
Couleur couleur = couleurs[indice];
return new JetonJoueur(couleur);
}
public bool EstEgale(CombinaisonJoueur combinaisonJoueur)
{
if(!combinaisonJoueur.EstComplete())
{
throw new Exception("Combinaison imcomplete");
}
for(int indice = 0; indice < CombinaisonSecrete.taillePhysique; ++indice)
{
if(this.GetJeton(indice).Couleur != combinaisonJoueur.GetJeton(indice).Couleur)
{
return false;
}
}
return true;
}
}
}