Nouveau joueur avec stats
continuous-integration/drone/push Build is failing Details

master
nicolas.barbosa 1 year ago
parent 7833e48ebd
commit 7ec7ae63c4

@ -1,6 +1,4 @@
using CoreLibrary.Core; namespace CoreLibrary.Joueurs
namespace CoreLibrary.Joueurs
{ {
/// <summary> /// <summary>
/// Classe représentant un joueur. /// Classe représentant un joueur.
@ -11,20 +9,32 @@ namespace CoreLibrary.Joueurs
/// Le nom du joueur. /// Le nom du joueur.
/// </summary> /// </summary>
public string Nom { get; private init; } public string Nom { get; private init; }
/// <summary>
/// Le plateau du joueur. public int NbCoutTotal { get; set; }
/// </summary> public int NbPartieGagnee { get; set; }
public Plateau Plateau { get; private init; } public int NbPartieEgalite { get; set; }
public int NbPartiePerdue { get; set; }
/// <summary> /// <summary>
/// Crée une nouvelle instance de joueur avec un nom et un plateau spécifié. /// Crée une nouvelle instance de joueur avec un nom
/// </summary> /// </summary>
/// <param name="nom">Le nom du joueur.</param> /// <param name="nom">Le nom du joueur.</param>
/// <param name="plateau">Le plateau du joueur.</param> public Joueur(string nom)
public Joueur(string nom, Plateau plateau) {
Nom = nom;
NbCoutTotal = 0;
NbPartieGagnee = 0;
NbPartieEgalite = 0;
NbPartiePerdue = 0;
}
public Joueur(string nom, int nbCoutTotal, int nbPartieGagnee, int nbPartieEgalite, int nbPartiePerdue)
{ {
Nom = nom; Nom = nom;
Plateau = plateau; NbCoutTotal = nbCoutTotal;
NbPartieGagnee = nbPartieGagnee;
NbPartieEgalite = nbPartieEgalite;
NbPartiePerdue = nbPartiePerdue;
} }
} }
} }

@ -160,8 +160,7 @@ namespace CoreLibrary
// Boucle principale du jeu qui dure jusqu'à qu'une condition de fin soit déclenchée // Boucle principale du jeu qui dure jusqu'à qu'une condition de fin soit déclenchée
while (!regles.EstTerminee()) while (!regles.EstTerminee())
{ {
Joueur joueurCourant = regles.JoueurCourant(); (Joueur joueurCourant, Plateau plateauCourant) = regles.JoueurCourant();
Plateau plateauCourant = joueurCourant.Plateau;
QuandNouveauTour(joueurCourant, plateauCourant.Tour, plateauCourant.Grille(), plateauCourant.Indicateurs()); QuandNouveauTour(joueurCourant, plateauCourant.Tour, plateauCourant.Grille(), plateauCourant.Indicateurs());

@ -44,7 +44,7 @@ namespace CoreLibrary.Regles
/// Récupère le joueur courant. /// Récupère le joueur courant.
/// </summary> /// </summary>
/// <returns>Le joueur courant.</returns> /// <returns>Le joueur courant.</returns>
Joueur JoueurCourant(); (Joueur, Plateau) JoueurCourant();
/// <summary> /// <summary>
/// Passe la main au joueur suivant. /// Passe la main au joueur suivant.

@ -12,6 +12,7 @@ namespace CoreLibrary.Regles
private int nbJoueurs = 0; private int nbJoueurs = 0;
private int? joueurCourant; private int? joueurCourant;
private readonly Joueur[] joueurs; private readonly Joueur[] joueurs;
private readonly Plateau[] plateaux;
/// <summary> /// <summary>
/// Le nom des règles. /// Le nom des règles.
@ -46,6 +47,7 @@ namespace CoreLibrary.Regles
public ReglesClassiques() public ReglesClassiques()
{ {
joueurs = new Joueur[NbJoueursMaximum]; joueurs = new Joueur[NbJoueursMaximum];
plateaux = new Plateau[NbJoueursMaximum];
} }
/// <summary> /// <summary>
@ -55,8 +57,9 @@ namespace CoreLibrary.Regles
/// <returns>Le joueur ajouté.</returns> /// <returns>Le joueur ajouté.</returns>
public Joueur AjouterJoueur(string nom) public Joueur AjouterJoueur(string nom)
{ {
Joueur joueur = new Joueur(nom, new Plateau(TailleCodeMaximum, TourMaximum)); Joueur joueur = new Joueur(nom);
joueurs[nbJoueurs++] = joueur; joueurs[nbJoueurs] = joueur;
plateaux[nbJoueurs++] = new Plateau(TailleCodeMaximum, TourMaximum);
return joueur; return joueur;
} }
@ -66,12 +69,12 @@ namespace CoreLibrary.Regles
/// <returns>Le joueur actuel.</returns> /// <returns>Le joueur actuel.</returns>
/// <exception cref="PartieNonCommenceeException">Levée lorsque la partie n'a pas commencée.</exception> /// <exception cref="PartieNonCommenceeException">Levée lorsque la partie n'a pas commencée.</exception>
public Joueur JoueurCourant() public (Joueur, Plateau) JoueurCourant()
{ {
if (!joueurCourant.HasValue) if (!joueurCourant.HasValue)
throw new PartieNonCommenceeException(); throw new PartieNonCommenceeException();
return joueurs[joueurCourant.Value]; return (joueurs[joueurCourant.Value], plateaux[joueurCourant.Value]);
} }
/// <summary> /// <summary>
@ -120,12 +123,12 @@ namespace CoreLibrary.Regles
if (!joueurCourant.HasValue || joueurCourant != 0) if (!joueurCourant.HasValue || joueurCourant != 0)
return false; return false;
if (JoueurCourant().Plateau.Tour > TourMaximum) if (JoueurCourant().Item2.Tour > TourMaximum)
return true; return true;
for (int i = 0; i < joueurs.Length; ++i) for (int i = 0; i < joueurs.Length; ++i)
{ {
if (joueurs[i].Plateau.Victoire) if (plateaux[i].Victoire)
return true; return true;
} }
@ -141,7 +144,7 @@ namespace CoreLibrary.Regles
Joueur[] gagnants = []; Joueur[] gagnants = [];
for (int i = 0; i < joueurs.Length; ++i) for (int i = 0; i < joueurs.Length; ++i)
{ {
if (joueurs[i].Plateau.Victoire) if (plateaux[i].Victoire)
{ {
gagnants = gagnants.Append(joueurs[i]).ToArray(); gagnants = gagnants.Append(joueurs[i]).ToArray();
} }
@ -159,7 +162,7 @@ namespace CoreLibrary.Regles
Joueur[] perdants = []; Joueur[] perdants = [];
for (int i = 0; i < joueurs.Length; ++i) for (int i = 0; i < joueurs.Length; ++i)
{ {
if (!joueurs[i].Plateau.Victoire) if (!plateaux[i].Victoire)
{ {
perdants = perdants.Append(joueurs[i]).ToArray(); perdants = perdants.Append(joueurs[i]).ToArray();
} }

Loading…
Cancel
Save