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/Partie.cs

89 lines
3.0 KiB

using CoreLibrary.Events;
namespace CoreLibrary
{
public class Partie
{
private IRegles regles;
public event EventHandler<AjouterJoueursEventArgs> ajouterJoueur;
public event EventHandler<DebutPartieEventArgs> debutPartie;
public event EventHandler<NouveauTourEventArgs> nouveauTour;
public event EventHandler<AjouterJetonEventArgs> ajouterJeton;
public event EventHandler<AjouterCodeEventArgs> ajouterCode;
public event EventHandler<PasserMainEventArgs> passerMain;
public event EventHandler<PartieTermineeEventArgs> partieTerminee;
private void QuandAjouterJoueur(Joueur joueur) => ajouterJoueur?.Invoke(this, new AjouterJoueursEventArgs(joueur));
private void QuandDebutPartie() => debutPartie?.Invoke(this, new DebutPartieEventArgs());
private void QuandNouveauTour(Joueur joueur, int tour) => nouveauTour?.Invoke(this, new NouveauTourEventArgs(joueur, tour));
private void QuandNouveauJeton(Jeton jeton) => ajouterJeton?.Invoke(this, new AjouterJetonEventArgs(jeton));
private void QuandNouveauCode(Code code) => ajouterCode?.Invoke(this, new AjouterCodeEventArgs(code));
private void QuandPasserMain() => passerMain?.Invoke(this, new PasserMainEventArgs());
private void QuandPartieTerminee(IEnumerable<Joueur> gagnants, IEnumerable<Joueur> perdants) => partieTerminee?.Invoke(this, new PartieTermineeEventArgs(gagnants, perdants));
public Partie(IRegles regles)
{
this.regles = regles;
}
public void Jouer()
{
DefinirJoueurs();
regles.CommencerLaPartie();
QuandDebutPartie();
while (!regles.EstTerminee())
{
Joueur joueurCourant = regles.JoueurCourant();
Plateau plateauCourant = joueurCourant.Plateau;
QuandNouveauTour(joueurCourant, plateauCourant.Tour);
Code code = regles.GenererCode();
while (!code.EstComplet())
{
AjouterJeton(code);
}
plateauCourant.AjouterCode(code);
QuandNouveauCode(code);
regles.PasserLaMain();
QuandPasserMain();
}
PartieTerminee();
QuandPartieTerminee(regles.Gagnants(), regles.Perdants());
}
private void AjouterJeton(Code code)
{
Jeton jeton = new Jeton(Couleur.ROUGE);
code.AjouterJeton(jeton);
QuandNouveauJeton(jeton);
}
private void DefinirJoueurs()
{
while(regles.NbJoueurs != regles.NbJoueursMaximum)
{
string nom = "pauline";
regles.AjouterJoueur(nom);
//QuandAjouterJoueur()
}
}
private void PartieTerminee()
{
regles.Gagnants();
regles.Perdants();
}
}
}