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/Sources/CoreLibrary/ReglesClassiques.cs

111 lines
2.7 KiB

namespace CoreLibrary
{
public class ReglesClassiques : IRegles
{
private int nbJoueurs = 0;
private int? joueurCourant;
private readonly Joueur[] joueurs;
public string Nom { get => "Règles classiques"; }
public int TourMaximum { get => 12; }
public int TailleCodeMaximum { get => 4; }
public int NbJoueurs { get => nbJoueurs; }
public int NbJoueursMaximum { get => 2; }
public ReglesClassiques()
{
joueurs = new Joueur[NbJoueursMaximum];
}
public void AjouterJoueur(string nom)
{
joueurs[nbJoueurs++] = new Joueur(nom, new Plateau(TailleCodeMaximum, TourMaximum));
}
public Joueur JoueurCourant()
{
if (!joueurCourant.HasValue)
throw new ReglesClassiquesJoueurCourantNull();
return joueurs[joueurCourant.Value];
}
public void PasserLaMain()
{
if (!joueurCourant.HasValue)
{
throw new ReglesClassiquesJoueurCourantNull();
}
joueurCourant++;
if (joueurCourant >= joueurs.Length)
{
joueurCourant = 0;
}
}
public Code GenererCode()
{
return new Code(TailleCodeMaximum);
}
public void CommencerLaPartie()
{
joueurCourant = 0;
}
public bool EstTerminee()
{
if (!joueurCourant.HasValue || joueurCourant != 0)
return false;
if (JoueurCourant().Plateau.Tour > TourMaximum)
return true;
for (int i = 0; i < joueurs.Length; ++i)
{
if (joueurs[i].Plateau.Victoire)
return true;
}
return false;
}
public IEnumerable<Joueur> Gagnants()
{
Joueur[] gagnants = [];
for (int i = 0; i < joueurs.Length; ++i)
{
if (joueurs[i].Plateau.Victoire)
{
gagnants = gagnants.Append(joueurs[i]).ToArray();
}
}
return gagnants;
}
public IEnumerable<Joueur> Perdants()
{
Joueur[] perdants = [];
for (int i = 0; i < joueurs.Length; ++i)
{
if (!joueurs[i].Plateau.Victoire)
{
perdants = perdants.Append(joueurs[i]).ToArray();
}
}
return perdants;
}
}
}