|
|
|
@ -26,12 +26,7 @@ namespace CoreLibrary
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Événement déclenché lorsqu'il est nécessaire de d'ajouter un joueur.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event StringEventHandler<DemanderJoueurEventArgs>? DemanderJoueur;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Événement déclenché lorsqu'il est nécessaire d'ajouter un jeton.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event JetonEventHandler<DemanderJetonEventArgs>? DemanderJeton;
|
|
|
|
|
public event StringEventHandler<DemanderNomEventArgs>? DemanderNom;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Événement déclenché lorsqu'il est nécessaire d'ajouter un joueur.
|
|
|
|
@ -79,13 +74,7 @@ namespace CoreLibrary
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="numero">Le numéro du joueur à ajouter</param>
|
|
|
|
|
/// <returns>Le nom du joueur demandé</returns></returns>
|
|
|
|
|
private string? QuandDemanderJoueur(int numero) => DemanderJoueur?.Invoke(this, new DemanderJoueurEventArgs(numero));
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Méthode pour déclencher l'événement de demande d'ajout d'un jeton.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Le jeton demandé</returns>
|
|
|
|
|
private Jeton? QuandDemanderJeton(int indice) => DemanderJeton?.Invoke(this, new DemanderJetonEventArgs(indice));
|
|
|
|
|
private string? QuandDemanderNom(int numero, JoueurBuilder joueurBuilder) => DemanderNom?.Invoke(this, new DemanderNomEventArgs(numero, joueurBuilder));
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Méthode pour déclencher l'événement d'ajout d'un joueur.
|
|
|
|
@ -151,31 +140,44 @@ namespace CoreLibrary
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Jouer()
|
|
|
|
|
{
|
|
|
|
|
/// Ajout des joueurs jusqu'à atteindre le nombre maximum de joueurs défini par les règles
|
|
|
|
|
AjouterJoueurs();
|
|
|
|
|
regles.CommencerLaPartie();
|
|
|
|
|
QuandDebutPartie();
|
|
|
|
|
|
|
|
|
|
Joueur joueurCourant = regles.JoueurCourant();
|
|
|
|
|
Plateau plateauCourant = joueurCourant.Plateau;
|
|
|
|
|
|
|
|
|
|
QuandNouveauTour(joueurCourant, plateauCourant.Tour, plateauCourant.Grille(), plateauCourant.Indicateurs());
|
|
|
|
|
JoueurBuilder joueurBuilder = new JoueurBuilder();
|
|
|
|
|
joueurBuilder.ConstruireJoueur += Joueur;
|
|
|
|
|
|
|
|
|
|
QuandDemanderNom(regles.NbJoueurs + 1, joueurBuilder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Joueur(Object? sender, )
|
|
|
|
|
public void Joueur(Object? sender, ConstruireJoueurEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Joueur joueur = regles.AjouterJoueur(e.Nom);
|
|
|
|
|
QuandAjouterJoueur(joueur);
|
|
|
|
|
joueur.JouerCode += Tour;
|
|
|
|
|
|
|
|
|
|
if (regles.NbJoueurs != regles.NbJoueursMaximum)
|
|
|
|
|
{
|
|
|
|
|
JoueurBuilder joueurBuilder = new JoueurBuilder();
|
|
|
|
|
joueurBuilder.ConstruireJoueur += Joueur;
|
|
|
|
|
QuandDemanderNom(regles.NbJoueurs + 1, joueurBuilder);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Commencer();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Tour()
|
|
|
|
|
public void Commencer()
|
|
|
|
|
{
|
|
|
|
|
Code code = regles.GenererCode();
|
|
|
|
|
regles.CommencerLaPartie();
|
|
|
|
|
QuandDebutPartie();
|
|
|
|
|
|
|
|
|
|
CreerCode(code);
|
|
|
|
|
(Joueur joueurCourant, Plateau plateauCourant) = regles.JoueurCourant();
|
|
|
|
|
QuandNouveauTour(joueurCourant, plateauCourant.Tour, plateauCourant.Grille(), plateauCourant.Indicateurs());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
plateauCourant.AjouterCode(code);
|
|
|
|
|
QuandNouveauCode(code);
|
|
|
|
|
private void Tour(Object? sender, JouerCodeEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
(Joueur joueurCourant, Plateau plateauCourant) = regles.JoueurCourant();
|
|
|
|
|
plateauCourant.AjouterCode(e.Code);
|
|
|
|
|
QuandNouveauCode(e.Code);
|
|
|
|
|
|
|
|
|
|
if(regles.EstTerminee())
|
|
|
|
|
{
|
|
|
|
@ -186,46 +188,11 @@ namespace CoreLibrary
|
|
|
|
|
regles.PasserLaMain();
|
|
|
|
|
QuandPasserMain();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Terminee()
|
|
|
|
|
{
|
|
|
|
|
QuandPartieTerminee(regles.Gagnants(), regles.Perdants());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AjouterJoueurs()
|
|
|
|
|
{
|
|
|
|
|
while (regles.NbJoueurs != regles.NbJoueursMaximum)
|
|
|
|
|
{
|
|
|
|
|
string nom = QuandDemanderJoueur(regles.NbJoueurs + 1) ?? $"Joueur {regles.NbJoueurs + 1}";
|
|
|
|
|
Joueur joueur = regles.AjouterJoueur(nom);
|
|
|
|
|
QuandAjouterJoueur(joueur);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreerCode(Code code)
|
|
|
|
|
{
|
|
|
|
|
while (!code.EstComplet())
|
|
|
|
|
{
|
|
|
|
|
Jeton? jeton = QuandDemanderJeton(code.NbJetons);
|
|
|
|
|
|
|
|
|
|
if (DemanderJeton == null)
|
|
|
|
|
{
|
|
|
|
|
jeton = new Jeton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!jeton.HasValue)
|
|
|
|
|
{
|
|
|
|
|
code.SupprimerDernierJeton();
|
|
|
|
|
QuandSupprimerDernierJeton();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
code.AjouterJeton(jeton.Value);
|
|
|
|
|
QuandNouveauJeton(jeton.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|