using CoreLibrary.Exceptions; 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 Joueur AjouterJoueur(string nom) { Joueur joueur = new Joueur(nom, new Plateau(TailleCodeMaximum, TourMaximum)) joueurs[nbJoueurs++] = joueur; return joueur; } public Joueur JoueurCourant() { if (!joueurCourant.HasValue) throw new PartieNonCommenceeException(); return joueurs[joueurCourant.Value]; } public void PasserLaMain() { if (!joueurCourant.HasValue) { throw new PartieNonCommenceeException(); } 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 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 Perdants() { Joueur[] perdants = []; for (int i = 0; i < joueurs.Length; ++i) { if (!joueurs[i].Plateau.Victoire) { perdants = perdants.Append(joueurs[i]).ToArray(); } } return perdants; } } }