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

master
nicolas.barbosa 11 months ago
parent 7833e48ebd
commit 7ec7ae63c4

@ -1,6 +1,4 @@
using CoreLibrary.Core;
namespace CoreLibrary.Joueurs
namespace CoreLibrary.Joueurs
{
/// <summary>
/// Classe représentant un joueur.
@ -11,20 +9,32 @@ namespace CoreLibrary.Joueurs
/// Le nom du joueur.
/// </summary>
public string Nom { get; private init; }
/// <summary>
/// Le plateau du joueur.
/// </summary>
public Plateau Plateau { get; private init; }
public int NbCoutTotal { get; set; }
public int NbPartieGagnee { get; set; }
public int NbPartieEgalite { get; set; }
public int NbPartiePerdue { get; set; }
/// <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>
/// <param name="nom">Le nom du joueur.</param>
/// <param name="plateau">Le plateau du joueur.</param>
public Joueur(string nom, Plateau plateau)
public Joueur(string nom)
{
Nom = nom;
NbCoutTotal = 0;
NbPartieGagnee = 0;
NbPartieEgalite = 0;
NbPartiePerdue = 0;
}
public Joueur(string nom, int nbCoutTotal, int nbPartieGagnee, int nbPartieEgalite, int nbPartiePerdue)
{
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
while (!regles.EstTerminee())
{
Joueur joueurCourant = regles.JoueurCourant();
Plateau plateauCourant = joueurCourant.Plateau;
(Joueur joueurCourant, Plateau plateauCourant) = regles.JoueurCourant();
QuandNouveauTour(joueurCourant, plateauCourant.Tour, plateauCourant.Grille(), plateauCourant.Indicateurs());

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

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

Loading…
Cancel
Save