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.
136 lines
3.4 KiB
136 lines
3.4 KiB
namespace CoreLibrary
|
|
{
|
|
internal class Partie : IRegles
|
|
{
|
|
private static readonly int maximumJoueur = 2;
|
|
private static readonly int maximumTour = 12;
|
|
|
|
private int? indice;
|
|
private readonly Joueur[] joueurs = new Joueur[maximumJoueur];
|
|
|
|
private int tour = 1;
|
|
|
|
public void AjouterJoueur(Joueur joueur)
|
|
{
|
|
if(joueurs.Length >= maximumJoueur)
|
|
{
|
|
throw new Exception("Nombre de joueurs maximum atteint");
|
|
}
|
|
|
|
joueurs.Append(joueur);
|
|
}
|
|
|
|
public void CommencerPartie()
|
|
{
|
|
indice = 0;
|
|
}
|
|
|
|
public bool EstCombinaisonValide(CombinaisonJoueur combinaison)
|
|
{
|
|
return combinaison.EstComplete();
|
|
}
|
|
|
|
public bool EstTermine()
|
|
{
|
|
if (!indice.HasValue || indice != 0)
|
|
return false;
|
|
|
|
if (tour > maximumTour)
|
|
return true;
|
|
|
|
for (int i = 0; i < joueurs.Length; ++i)
|
|
{
|
|
if (joueurs[i].AGagne())
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public Joueur[] Gagnant()
|
|
{
|
|
Joueur[] gagnants = new Joueur[joueurs.Length];
|
|
|
|
if (!indice.HasValue)
|
|
throw new Exception("Partie non démarrée");
|
|
|
|
if (!EstTermine())
|
|
throw new Exception("Partie non terminée");
|
|
|
|
for (int i = 0; i < joueurs.Length; ++i)
|
|
{
|
|
if (joueurs[i].AGagne())
|
|
gagnants.Append(joueurs[i]);
|
|
}
|
|
|
|
return gagnants;
|
|
}
|
|
|
|
public void JouerCombinaison(CombinaisonJoueur combinaison)
|
|
{
|
|
if (!indice.HasValue)
|
|
throw new Exception("Partie non démarrée");
|
|
|
|
if (!EstCombinaisonValide(combinaison))
|
|
throw new Exception("Combinaison n'est pas valide");
|
|
|
|
joueurs[indice.Value].JouerCombinaison(combinaison);
|
|
}
|
|
|
|
public Joueur JoueurCourant()
|
|
{
|
|
if (!indice.HasValue)
|
|
throw new Exception("Partie non démarrée");
|
|
|
|
return joueurs[indice.Value];
|
|
}
|
|
|
|
public Joueur[] Joueurs()
|
|
{
|
|
return joueurs;
|
|
}
|
|
|
|
public void PasserLaMain()
|
|
{
|
|
if (!indice.HasValue)
|
|
throw new Exception("Partie non démarrée");
|
|
|
|
++indice;
|
|
if (indice >= joueurs.Length)
|
|
{
|
|
++tour;
|
|
indice = 0;
|
|
}
|
|
}
|
|
|
|
public Joueur[] Perdant()
|
|
{
|
|
if (!indice.HasValue)
|
|
throw new Exception("Partie non démarrée");
|
|
|
|
if (!EstTermine())
|
|
throw new Exception("Partie non terminée");
|
|
|
|
Joueur[] perdants = new Joueur[joueurs.Length];
|
|
|
|
for (int i = 0; i < joueurs.Length; ++i)
|
|
{
|
|
if (!joueurs[i].AGagne())
|
|
perdants.Append(joueurs[i]);
|
|
}
|
|
|
|
return perdants;
|
|
}
|
|
|
|
public CombinaisonJoueur Plateau()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public int Tour()
|
|
{
|
|
return tour;
|
|
}
|
|
}
|
|
}
|