diff --git a/Sources/CoreLibrary/Events/JouerCodeEventArgs.cs b/Sources/CoreLibrary/Events/JouerCodeEventArgs.cs new file mode 100644 index 0000000..61e292c --- /dev/null +++ b/Sources/CoreLibrary/Events/JouerCodeEventArgs.cs @@ -0,0 +1,17 @@ +using CoreLibrary.Core; + +namespace CoreLibrary.Events +{ + /// + /// Classe contenant les arguments passées en paramètre lors de l'événement NouveauTour. + /// + public class JouerCodeEventArgs : EventArgs + { + public Code Code { get; private set; } + + public JouerCodeEventArgs(Code code) + { + Code = code; + } + } +} diff --git a/Sources/CoreLibrary/Events/NouveauJoueurEventArgs.cs b/Sources/CoreLibrary/Events/NouveauJoueurEventArgs.cs new file mode 100644 index 0000000..f9a0828 --- /dev/null +++ b/Sources/CoreLibrary/Events/NouveauJoueurEventArgs.cs @@ -0,0 +1,12 @@ +namespace CoreLibrary.Events +{ + public class NouveauJoueurEventArgs : EventArgs + { + public string Nom { get; private set; } + + public NouveauJoueurEventArgs(string nom) + { + Nom = nom; + } + } +} diff --git a/Sources/CoreLibrary/Joueurs/Joueur.cs b/Sources/CoreLibrary/Joueurs/Joueur.cs index 7d8e484..336a6ac 100644 --- a/Sources/CoreLibrary/Joueurs/Joueur.cs +++ b/Sources/CoreLibrary/Joueurs/Joueur.cs @@ -1,4 +1,5 @@ using CoreLibrary.Core; +using CoreLibrary.Events; namespace CoreLibrary.Joueurs { @@ -11,11 +12,22 @@ namespace CoreLibrary.Joueurs /// Le nom du joueur. /// public string Nom { get; private init; } + /// /// Le plateau du joueur. /// public Plateau Plateau { get; private init; } + /// + /// Evénement appelé pour jouer un code. + /// + public event EventHandler? JouerCode; + + /// + /// Appel de l'événement JouerCode. + /// + private void QuandJouerCode(Code code) => JouerCode?.Invoke(this, new JouerCodeEventArgs(code)); + /// /// Crée une nouvelle instance de joueur avec un nom et un plateau spécifié. /// diff --git a/Sources/CoreLibrary/Joueurs/JoueurBuilder.cs b/Sources/CoreLibrary/Joueurs/JoueurBuilder.cs new file mode 100644 index 0000000..6ce2d1f --- /dev/null +++ b/Sources/CoreLibrary/Joueurs/JoueurBuilder.cs @@ -0,0 +1,21 @@ +namespace CoreLibrary.Joueurs +{ + public class JoueurBuilder + { + private string nom; + + public JoueurBuilder Nom(string nom) + { + this.nom = nom; + return this; + } + + public Joueur Build() + { + return new Joueur() + } + + + + } +} diff --git a/Sources/CoreLibrary/Partie.cs b/Sources/CoreLibrary/Partie.cs index 3ea6cfe..b883db4 100644 --- a/Sources/CoreLibrary/Partie.cs +++ b/Sources/CoreLibrary/Partie.cs @@ -143,7 +143,7 @@ namespace CoreLibrary /// Les règles de la partie. public Partie(IRegles regles) { - this.regles = regles; + this.regles = regles; } /// @@ -153,35 +153,44 @@ namespace CoreLibrary { /// Ajout des joueurs jusqu'à atteindre le nombre maximum de joueurs défini par les règles AjouterJoueurs(); - regles.CommencerLaPartie(); QuandDebutPartie(); - // Boucle principale du jeu qui dure jusqu'à qu'une condition de fin soit déclenchée - while (!regles.EstTerminee()) - { - Joueur joueurCourant = regles.JoueurCourant(); - Plateau plateauCourant = joueurCourant.Plateau; + Joueur joueurCourant = regles.JoueurCourant(); + Plateau plateauCourant = joueurCourant.Plateau; + + QuandNouveauTour(joueurCourant, plateauCourant.Tour, plateauCourant.Grille(), plateauCourant.Indicateurs()); + + } - QuandNouveauTour(joueurCourant, plateauCourant.Tour, plateauCourant.Grille(), plateauCourant.Indicateurs()); + public void Joueur(Object? sender, ) + { - Code code = regles.GenererCode(); + } - CreerCode(code); + private void Tour() + { + Code code = regles.GenererCode(); - // Phase de saisie du code par le joueur jusqu'à que le code soit complet. + CreerCode(code); - plateauCourant.AjouterCode(code); - QuandNouveauCode(code); + plateauCourant.AjouterCode(code); + QuandNouveauCode(code); + if(regles.EstTerminee()) + { + Terminee(); + } + else + { regles.PasserLaMain(); QuandPasserMain(); } + + } - - regles.Gagnants(); - regles.Perdants(); - + private void Terminee() + { QuandPartieTerminee(regles.Gagnants(), regles.Perdants()); }