From 7833e48ebdf3e479ab08a687a9633f0aad808ce3 Mon Sep 17 00:00:00 2001 From: "pauline.prady" Date: Tue, 21 May 2024 18:55:25 +0200 Subject: [PATCH 1/6] =?UTF-8?q?D=C3=A9but=20du=20databinding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Manager/IPersistanceManager.cs | 11 +++++++ Sources/CoreLibrary/Manager/Manager.cs | 26 +++++++++++++++ Sources/MauiSpark/MauiProgram.cs | 7 +++- Sources/MauiSpark/MauiSpark.csproj | 4 +++ Sources/MauiSpark/Pages/TableauScore.xaml | 11 ------- Sources/MauiSpark/Views/CTableauScore.xaml | 19 ++++++++--- Sources/MauiSpark/Views/CTableauScore.xaml.cs | 32 +++++++++++++++++-- 7 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 Sources/CoreLibrary/Manager/IPersistanceManager.cs create mode 100644 Sources/CoreLibrary/Manager/Manager.cs diff --git a/Sources/CoreLibrary/Manager/IPersistanceManager.cs b/Sources/CoreLibrary/Manager/IPersistanceManager.cs new file mode 100644 index 0000000..5795d3a --- /dev/null +++ b/Sources/CoreLibrary/Manager/IPersistanceManager.cs @@ -0,0 +1,11 @@ +namespace CoreLibrary.Manager +{ + public interface IPersistanceManager + { + public void Charger(); + + public void Enregistrer(); + + + } +} diff --git a/Sources/CoreLibrary/Manager/Manager.cs b/Sources/CoreLibrary/Manager/Manager.cs new file mode 100644 index 0000000..f6ee342 --- /dev/null +++ b/Sources/CoreLibrary/Manager/Manager.cs @@ -0,0 +1,26 @@ +using CoreLibrary.Joueurs; +using CoreLibrary.Regles; + +namespace CoreLibrary.Manager +{ + public class Manager : IPersistanceManager + { + private Joueur[] classement = []; + public List Classement => new List(classement); + + public void Charger() + { + classement = [ + new Joueur("Pauline", new Core.Plateau(4, 12)), + new Joueur("Céleste", new Core.Plateau(4, 12)), + new Joueur("Camille", new Core.Plateau(4, 12)), + new Joueur("Toto", new Core.Plateau(4, 12)), + ]; + } + + public void Enregistrer() + { + + } + } +} diff --git a/Sources/MauiSpark/MauiProgram.cs b/Sources/MauiSpark/MauiProgram.cs index a44a012..be3b5b2 100644 --- a/Sources/MauiSpark/MauiProgram.cs +++ b/Sources/MauiSpark/MauiProgram.cs @@ -1,11 +1,16 @@ -using Microsoft.Extensions.Logging; +using CoreLibrary.Manager; +using Microsoft.Extensions.Logging; namespace MauiSpark { public static class MauiProgram { + public static Manager Manager { get; private set; } = new Manager(); + public static MauiApp CreateMauiApp() { + Manager.Charger(); + var builder = MauiApp.CreateBuilder(); builder .UseMauiApp() diff --git a/Sources/MauiSpark/MauiSpark.csproj b/Sources/MauiSpark/MauiSpark.csproj index 9f70617..01cba09 100644 --- a/Sources/MauiSpark/MauiSpark.csproj +++ b/Sources/MauiSpark/MauiSpark.csproj @@ -62,6 +62,10 @@ + + + + MSBuild:Compile diff --git a/Sources/MauiSpark/Pages/TableauScore.xaml b/Sources/MauiSpark/Pages/TableauScore.xaml index f637c5c..1882f81 100644 --- a/Sources/MauiSpark/Pages/TableauScore.xaml +++ b/Sources/MauiSpark/Pages/TableauScore.xaml @@ -26,17 +26,6 @@ - - - - - - - - - - - diff --git a/Sources/MauiSpark/Views/CTableauScore.xaml b/Sources/MauiSpark/Views/CTableauScore.xaml index 5ef6dcd..1e0c542 100644 --- a/Sources/MauiSpark/Views/CTableauScore.xaml +++ b/Sources/MauiSpark/Views/CTableauScore.xaml @@ -5,10 +5,21 @@ - diff --git a/Sources/MauiSpark/Views/CTableauScore.xaml.cs b/Sources/MauiSpark/Views/CTableauScore.xaml.cs index 28a60c1..97cffca 100644 --- a/Sources/MauiSpark/Views/CTableauScore.xaml.cs +++ b/Sources/MauiSpark/Views/CTableauScore.xaml.cs @@ -1,9 +1,37 @@ +using CoreLibrary.Joueurs; +using CoreLibrary.Manager; + namespace MauiSpark.Views; +internal class JoueurClassement +{ + private Manager manager; + private Joueur joueur; + + public Joueur Joueur + { + get => joueur; + private set => joueur = value; + } + + public int Place + { + get => manager.Classement.IndexOf(Joueur) + 1; + } + + public JoueurClassement(Joueur joueur, Manager manager) + { + this.manager = manager; + this.joueur = joueur; + } +} + public partial class CTableauScore : ContentView { public CTableauScore() { - InitializeComponent(); - } + InitializeComponent(); + + BindingContext = MauiProgram.Manager.Classement.Select(joueur => new JoueurClassement(joueur, MauiProgram.Manager)); + } } \ No newline at end of file From 7ec7ae63c4ee138fdad616dd45f31c37d4f9c342 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Tue, 21 May 2024 18:58:13 +0200 Subject: [PATCH 2/6] Nouveau joueur avec stats --- Sources/CoreLibrary/Joueurs/Joueur.cs | 32 +- Sources/CoreLibrary/Partie.cs | 3 +- Sources/CoreLibrary/Regles/IRegles.cs | 2 +- .../CoreLibrary/Regles/ReglesClassiques.cs | 343 +++++++++--------- 4 files changed, 196 insertions(+), 184 deletions(-) diff --git a/Sources/CoreLibrary/Joueurs/Joueur.cs b/Sources/CoreLibrary/Joueurs/Joueur.cs index 7d8e484..7838b76 100644 --- a/Sources/CoreLibrary/Joueurs/Joueur.cs +++ b/Sources/CoreLibrary/Joueurs/Joueur.cs @@ -1,6 +1,4 @@ -using CoreLibrary.Core; - -namespace CoreLibrary.Joueurs +namespace CoreLibrary.Joueurs { /// /// Classe représentant un joueur. @@ -11,20 +9,32 @@ namespace CoreLibrary.Joueurs /// Le nom du joueur. /// public string Nom { get; private init; } - /// - /// Le plateau du joueur. - /// - 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; } /// - /// 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 /// /// Le nom du joueur. - /// Le plateau du joueur. - 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; } } } diff --git a/Sources/CoreLibrary/Partie.cs b/Sources/CoreLibrary/Partie.cs index 3ea6cfe..c56a8bd 100644 --- a/Sources/CoreLibrary/Partie.cs +++ b/Sources/CoreLibrary/Partie.cs @@ -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()); diff --git a/Sources/CoreLibrary/Regles/IRegles.cs b/Sources/CoreLibrary/Regles/IRegles.cs index bb0945f..a66b5a3 100644 --- a/Sources/CoreLibrary/Regles/IRegles.cs +++ b/Sources/CoreLibrary/Regles/IRegles.cs @@ -44,7 +44,7 @@ namespace CoreLibrary.Regles /// Récupère le joueur courant. /// /// Le joueur courant. - Joueur JoueurCourant(); + (Joueur, Plateau) JoueurCourant(); /// /// Passe la main au joueur suivant. diff --git a/Sources/CoreLibrary/Regles/ReglesClassiques.cs b/Sources/CoreLibrary/Regles/ReglesClassiques.cs index 7ef929c..e329a83 100644 --- a/Sources/CoreLibrary/Regles/ReglesClassiques.cs +++ b/Sources/CoreLibrary/Regles/ReglesClassiques.cs @@ -1,171 +1,174 @@ -using CoreLibrary.Core; -using CoreLibrary.Exceptions; -using CoreLibrary.Joueurs; - -namespace CoreLibrary.Regles -{ - /// - /// Classe définissant les règles classiques du jeu. - /// - public class ReglesClassiques : IRegles - { - private int nbJoueurs = 0; - private int? joueurCourant; - private readonly Joueur[] joueurs; - - /// - /// Le nom des règles. - /// - public string Nom { get => "Règles classiques"; } - - /// - /// Le nombre maximum de tour. - /// - public int TourMaximum { get => 12; } - - /// - /// La taille maximale d'un code. - /// - - public int TailleCodeMaximum { get => 4; } - /// - /// Le nombre de joueurs actuels dans le jeu. - /// - +using CoreLibrary.Core; +using CoreLibrary.Exceptions; +using CoreLibrary.Joueurs; + +namespace CoreLibrary.Regles +{ + /// + /// Classe définissant les règles classiques du jeu. + /// + public class ReglesClassiques : IRegles + { + private int nbJoueurs = 0; + private int? joueurCourant; + private readonly Joueur[] joueurs; + private readonly Plateau[] plateaux; + + /// + /// Le nom des règles. + /// + public string Nom { get => "Règles classiques"; } + + /// + /// Le nombre maximum de tour. + /// + public int TourMaximum { get => 12; } + + /// + /// La taille maximale d'un code. + /// + + public int TailleCodeMaximum { get => 4; } + /// + /// Le nombre de joueurs actuels dans le jeu. + /// + public int NbJoueurs { get => nbJoueurs; } - /// - /// Me nombre maximum de joueurs possibles pour le jeu. - /// - - public int NbJoueursMaximum { get => 2; } - - - /// - /// Initialise une nouvelle instance de la classe - /// - public ReglesClassiques() - { - joueurs = new Joueur[NbJoueursMaximum]; - } - - /// - /// Ajoute un joueur avec le nom spécifié. - /// - /// Le nom du joueur à ajouter. - /// Le joueur ajouté. - public Joueur AjouterJoueur(string nom) - { - Joueur joueur = new Joueur(nom, new Plateau(TailleCodeMaximum, TourMaximum)); - joueurs[nbJoueurs++] = joueur; - return joueur; - } - - /// - /// Obtient le joueur dont c'est actuellement le tour. - /// - /// Le joueur actuel. - /// Levée lorsque la partie n'a pas commencée. - - public Joueur JoueurCourant() - { - if (!joueurCourant.HasValue) - throw new PartieNonCommenceeException(); - - return joueurs[joueurCourant.Value]; - } - - /// - /// Passe la main au joueur suivant. - /// - /// Levée lorsque la partie n'a pas commmencée. - public void PasserLaMain() - { - if (!joueurCourant.HasValue) - { - throw new PartieNonCommenceeException(); - } - - ++joueurCourant; - - if (joueurCourant >= joueurs.Length) - { - joueurCourant = 0; - } - - } - - /// - /// Génère un nouveau code respectant les règles classiques. - /// - /// Le code généré. - public Code GenererCode() - { - return new Code(TailleCodeMaximum); - } - - /// - /// Démarre la partie en décidant que le premier joueur commence. - /// - public void CommencerLaPartie() - { - joueurCourant = 0; - } - - /// - /// Vérifie si la partie est terminée. - /// - /// True si la partie est terminée, sinon False. - public bool EstTerminee() - { - if (!joueurCourant.HasValue || joueurCourant != 0) - return false; - - if (JoueurCourant().Plateau.Tour > TourMaximum) - return true; - - for (int i = 0; i < joueurs.Length; ++i) - { - if (joueurs[i].Plateau.Victoire) - return true; - } - - return false; - } - - /// - /// Obtient les joueurs gagnants de la partie. - /// - /// La liste des joueurs gagnants. - public IEnumerable Gagnants() - { - Joueur[] gagnants = []; - for (int i = 0; i < joueurs.Length; ++i) - { - if (joueurs[i].Plateau.Victoire) - { - gagnants = gagnants.Append(joueurs[i]).ToArray(); - } - } - - return gagnants; - } - - /// - /// Obtient les joueurs perdants de la partie. - /// - /// La liste des joueurs perdants. - public IEnumerable Perdants() - { - Joueur[] perdants = []; - for (int i = 0; i < joueurs.Length; ++i) - { - if (!joueurs[i].Plateau.Victoire) - { - perdants = perdants.Append(joueurs[i]).ToArray(); - } - } - - return perdants; - } - } -} + /// + /// Me nombre maximum de joueurs possibles pour le jeu. + /// + + public int NbJoueursMaximum { get => 2; } + + + /// + /// Initialise une nouvelle instance de la classe + /// + public ReglesClassiques() + { + joueurs = new Joueur[NbJoueursMaximum]; + plateaux = new Plateau[NbJoueursMaximum]; + } + + /// + /// Ajoute un joueur avec le nom spécifié. + /// + /// Le nom du joueur à ajouter. + /// Le joueur ajouté. + public Joueur AjouterJoueur(string nom) + { + Joueur joueur = new Joueur(nom); + joueurs[nbJoueurs] = joueur; + plateaux[nbJoueurs++] = new Plateau(TailleCodeMaximum, TourMaximum); + return joueur; + } + + /// + /// Obtient le joueur dont c'est actuellement le tour. + /// + /// Le joueur actuel. + /// Levée lorsque la partie n'a pas commencée. + + public (Joueur, Plateau) JoueurCourant() + { + if (!joueurCourant.HasValue) + throw new PartieNonCommenceeException(); + + return (joueurs[joueurCourant.Value], plateaux[joueurCourant.Value]); + } + + /// + /// Passe la main au joueur suivant. + /// + /// Levée lorsque la partie n'a pas commmencée. + public void PasserLaMain() + { + if (!joueurCourant.HasValue) + { + throw new PartieNonCommenceeException(); + } + + ++joueurCourant; + + if (joueurCourant >= joueurs.Length) + { + joueurCourant = 0; + } + + } + + /// + /// Génère un nouveau code respectant les règles classiques. + /// + /// Le code généré. + public Code GenererCode() + { + return new Code(TailleCodeMaximum); + } + + /// + /// Démarre la partie en décidant que le premier joueur commence. + /// + public void CommencerLaPartie() + { + joueurCourant = 0; + } + + /// + /// Vérifie si la partie est terminée. + /// + /// True si la partie est terminée, sinon False. + public bool EstTerminee() + { + if (!joueurCourant.HasValue || joueurCourant != 0) + return false; + + if (JoueurCourant().Item2.Tour > TourMaximum) + return true; + + for (int i = 0; i < joueurs.Length; ++i) + { + if (plateaux[i].Victoire) + return true; + } + + return false; + } + + /// + /// Obtient les joueurs gagnants de la partie. + /// + /// La liste des joueurs gagnants. + public IEnumerable Gagnants() + { + Joueur[] gagnants = []; + for (int i = 0; i < joueurs.Length; ++i) + { + if (plateaux[i].Victoire) + { + gagnants = gagnants.Append(joueurs[i]).ToArray(); + } + } + + return gagnants; + } + + /// + /// Obtient les joueurs perdants de la partie. + /// + /// La liste des joueurs perdants. + public IEnumerable Perdants() + { + Joueur[] perdants = []; + for (int i = 0; i < joueurs.Length; ++i) + { + if (!plateaux[i].Victoire) + { + perdants = perdants.Append(joueurs[i]).ToArray(); + } + } + + return perdants; + } + } +} From c9cf49ab78fa467a5da8b67237bea145f74958fb Mon Sep 17 00:00:00 2001 From: "pauline.prady" Date: Tue, 21 May 2024 19:22:21 +0200 Subject: [PATCH 3/6] =?UTF-8?q?D=C3=A9but=20binding=20sur=20un=20classemen?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/CoreLibrary/Manager/Manager.cs | 14 +-- Sources/MauiSpark/Views/CTableauScore.xaml | 4 +- Sources/MauiSpark/Views/CTableauScore.xaml.cs | 92 ++++++++++++++++++- 3 files changed, 97 insertions(+), 13 deletions(-) diff --git a/Sources/CoreLibrary/Manager/Manager.cs b/Sources/CoreLibrary/Manager/Manager.cs index f6ee342..9988d53 100644 --- a/Sources/CoreLibrary/Manager/Manager.cs +++ b/Sources/CoreLibrary/Manager/Manager.cs @@ -5,16 +5,16 @@ namespace CoreLibrary.Manager { public class Manager : IPersistanceManager { - private Joueur[] classement = []; - public List Classement => new List(classement); + private Joueur[] joueurs = []; + public Joueur[] Joueurs => (Joueur[]) joueurs.Clone(); public void Charger() { - classement = [ - new Joueur("Pauline", new Core.Plateau(4, 12)), - new Joueur("Céleste", new Core.Plateau(4, 12)), - new Joueur("Camille", new Core.Plateau(4, 12)), - new Joueur("Toto", new Core.Plateau(4, 12)), + joueurs = [ + new Joueur("Pauline", 50, 5, 2, 0), + new Joueur("Céleste", 40, 6, 2, 0), + new Joueur("Camille", 55, 8, 0, 1), + new Joueur("Toto", 70, 0, 0, 10), ]; } diff --git a/Sources/MauiSpark/Views/CTableauScore.xaml b/Sources/MauiSpark/Views/CTableauScore.xaml index 1e0c542..5f2e4e9 100644 --- a/Sources/MauiSpark/Views/CTableauScore.xaml +++ b/Sources/MauiSpark/Views/CTableauScore.xaml @@ -12,8 +12,8 @@ diff --git a/Sources/MauiSpark/Views/CTableauScore.xaml.cs b/Sources/MauiSpark/Views/CTableauScore.xaml.cs index 97cffca..d9e5d68 100644 --- a/Sources/MauiSpark/Views/CTableauScore.xaml.cs +++ b/Sources/MauiSpark/Views/CTableauScore.xaml.cs @@ -3,7 +3,7 @@ using CoreLibrary.Manager; namespace MauiSpark.Views; -internal class JoueurClassement +internal class JoueurClassementNbCoupParPartie { private Manager manager; private Joueur joueur; @@ -16,10 +16,89 @@ internal class JoueurClassement public int Place { - get => manager.Classement.IndexOf(Joueur) + 1; + get => manager.Joueurs + .OrderBy(joueur => joueur.NbCoutTotal/(joueur.NbPartiePerdue+joueur.NbPartieGagnee+joueur.NbPartieEgalite)).ToList() + .IndexOf(Joueur) + 1; } - public JoueurClassement(Joueur joueur, Manager manager) + public int Point => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite); + + public JoueurClassementNbCoupParPartie(Joueur joueur, Manager manager) + { + this.manager = manager; + this.joueur = joueur; + } +} + +internal class JoueurClassementPartieGagnee +{ + private Manager manager; + private Joueur joueur; + + public Joueur Joueur + { + get => joueur; + private set => joueur = value; + } + + public int Place + { + get => manager.Joueurs.OrderByDescending(joueur => joueur.NbPartieGagnee).ToList().IndexOf(Joueur) + 1; + } + + public int Point => joueur.NbPartieGagnee; + + public JoueurClassementPartieGagnee(Joueur joueur, Manager manager) + { + this.manager = manager; + this.joueur = joueur; + } +} + +internal class JoueurClassementPartieEgalite +{ + private Manager manager; + private Joueur joueur; + + public Joueur Joueur + { + get => joueur; + private set => joueur = value; + } + + public int Place + { + get => manager.Joueurs.OrderByDescending(joueur => joueur.NbPartieEgalite).ToList().IndexOf(joueur)+1; + } + + public int Point => joueur.NbPartieEgalite; + + public JoueurClassementPartieEgalite(Joueur joueur, Manager manager) + { + this.manager = manager; + this.joueur = joueur; + } +} + +internal class JoueurClassementPartiePerdue +{ + private Manager manager; + private Joueur joueur; + + public Joueur Joueur + { + get => joueur; + private set => joueur = value; + } + + public int Place + { + get => manager.Joueurs.OrderByDescending(joueur => joueur.NbPartiePerdue).ToList().IndexOf(joueur)+1; + } + + public int Point => joueur.NbPartiePerdue; + + public JoueurClassementPartiePerdue(Joueur joueur, Manager manager) { this.manager = manager; this.joueur = joueur; @@ -32,6 +111,11 @@ public partial class CTableauScore : ContentView { InitializeComponent(); - BindingContext = MauiProgram.Manager.Classement.Select(joueur => new JoueurClassement(joueur, MauiProgram.Manager)); + IEnumerable classement1 = MauiProgram.Manager.Joueurs.OrderBy(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite)).Select(joueur => new JoueurClassementNbCoupParPartie(joueur, MauiProgram.Manager)); + IEnumerable classement2 = MauiProgram.Manager.Joueurs.OrderByDescending(joueur => joueur.NbPartieGagnee).Select(joueur => new JoueurClassementPartieGagnee(joueur, MauiProgram.Manager)); + IEnumerable classement3 = MauiProgram.Manager.Joueurs.OrderByDescending(joueur => joueur.NbPartieEgalite).Select(joueur => new JoueurClassementPartieEgalite(joueur, MauiProgram.Manager)); + IEnumerable classement4 = MauiProgram.Manager.Joueurs.OrderByDescending(joueur => joueur.NbPartiePerdue).Select(joueur => new JoueurClassementPartiePerdue(joueur, MauiProgram.Manager)); + + BindingContext = classement4; } } \ No newline at end of file From a0cee7e7c76b5f0e0e7b94b216baf682ba266594 Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Fri, 24 May 2024 20:03:54 +0200 Subject: [PATCH 4/6] Data Biding avec les boutons (alphabet, nbpartiegagnee, NbpartiePerdu,NbPartieEgalite) et correction des tests pour que sa marche avec la nouvel class joueur. --- .../Events/DemanderJetonEventArgs.cs | 28 ++--- Sources/MauiSpark/Pages/TableauScore.xaml | 16 ++- Sources/MauiSpark/Pages/TableauScore.xaml.cs | 47 +++++++- Sources/MauiSpark/Views/CTableauScore.xaml | 46 ++++--- Sources/MauiSpark/Views/CTableauScore.xaml.cs | 114 ++++++++++++++---- Sources/UnitTesting/AjouterJoueurEventArgs.cs | 2 +- Sources/UnitTesting/JoueurUT.cs | 35 +++++- Sources/UnitTesting/NouveauTourEventArgsUT.cs | 2 +- .../UnitTesting/PartieTermineeEventArgsUT.cs | 4 +- Sources/UnitTesting/ReglesClassiquesUT.cs | 16 +-- 10 files changed, 223 insertions(+), 87 deletions(-) diff --git a/Sources/CoreLibrary/Events/DemanderJetonEventArgs.cs b/Sources/CoreLibrary/Events/DemanderJetonEventArgs.cs index 78dacc1..a8f3bae 100644 --- a/Sources/CoreLibrary/Events/DemanderJetonEventArgs.cs +++ b/Sources/CoreLibrary/Events/DemanderJetonEventArgs.cs @@ -1,22 +1,22 @@ -namespace CoreLibrary.Events -{ +namespace CoreLibrary.Events +{ /// /// Classe contenant les arguments passées en paramètre lors de l'événement DemanderJeton. - /// - public class DemanderJetonEventArgs : EventArgs - { + /// + public class DemanderJetonEventArgs : EventArgs + { /// /// L'indice du code où le jeton va être ajouté. - /// - public int Indice { get; private set; } - + /// + public int Indice { get; private set; } + /// /// Initialise une nouvelle instance de la classe avec l'indice spécifié. /// - /// L'indice du jeton qui va été ajouté. - public DemanderJetonEventArgs(int indice) + /// L'indice du jeton qui va été ajouté. + public DemanderJetonEventArgs(int indice) { - Indice = indice; - } - } -} + Indice = indice; + } + } +} diff --git a/Sources/MauiSpark/Pages/TableauScore.xaml b/Sources/MauiSpark/Pages/TableauScore.xaml index 1882f81..c095872 100644 --- a/Sources/MauiSpark/Pages/TableauScore.xaml +++ b/Sources/MauiSpark/Pages/TableauScore.xaml @@ -18,14 +18,18 @@ - - - - - + + + + + + + + + - + diff --git a/Sources/MauiSpark/Pages/TableauScore.xaml.cs b/Sources/MauiSpark/Pages/TableauScore.xaml.cs index db2de05..febd769 100644 --- a/Sources/MauiSpark/Pages/TableauScore.xaml.cs +++ b/Sources/MauiSpark/Pages/TableauScore.xaml.cs @@ -1,9 +1,48 @@ + +using CoreLibrary.Joueurs; +using MauiSpark.Views; +using System.Collections.ObjectModel; namespace MauiSpark.Pages; public partial class TableauScore : ContentPage { - public TableauScore() - { - InitializeComponent(); - } + public TableauScore() + { + InitializeComponent(); + SetDefaultClassement(); + } + private void SetDefaultClassement() + { + CTableauScore.UpdateClassement(CTableauScore.GetClassementNbCoupParPartie); + } + + private void QuandNbCoutMoyenButtonClicked(object sender, EventArgs e) + { + CTableauScore.UpdateClassement(CTableauScore.GetClassementNbCoupParPartie); + } + + private void QuandGagneeButtonClicked(object sender, EventArgs e) + { + CTableauScore.UpdateClassement(CTableauScore.GetClassementPartieGagnee); + } + + private void QuandPerduButtonClicked(object sender, EventArgs e) + { + CTableauScore.UpdateClassement(CTableauScore.GetClassementPartiePerdue); + } + + private void QuandEgaliteButtonClicked(object sender, EventArgs e) + { + CTableauScore.UpdateClassement(CTableauScore.GetClassementPartieEgalite); + } + + private void QuandAlphabetHautButtonClicked(object sender, EventArgs e) + { + CTableauScore.UpdateClassement(CTableauScore.GetClassementAlphabetHaut); + } + + private void QuandAlphabetBasButtonClicked(object sender, EventArgs e) + { + CTableauScore.UpdateClassement(CTableauScore.GetClassementAlphabetBas); + } } \ No newline at end of file diff --git a/Sources/MauiSpark/Views/CTableauScore.xaml b/Sources/MauiSpark/Views/CTableauScore.xaml index 5f2e4e9..684ab52 100644 --- a/Sources/MauiSpark/Views/CTableauScore.xaml +++ b/Sources/MauiSpark/Views/CTableauScore.xaml @@ -1,25 +1,23 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Sources/MauiSpark/Views/CTableauScore.xaml.cs b/Sources/MauiSpark/Views/CTableauScore.xaml.cs index d9e5d68..5f7430e 100644 --- a/Sources/MauiSpark/Views/CTableauScore.xaml.cs +++ b/Sources/MauiSpark/Views/CTableauScore.xaml.cs @@ -1,9 +1,13 @@ +using CoreLibrary.Events; using CoreLibrary.Joueurs; -using CoreLibrary.Manager; +using CoreLibrary.Manager; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Runtime.CompilerServices; namespace MauiSpark.Views; -internal class JoueurClassementNbCoupParPartie +public class JoueurClassementNbCoupParPartie { private Manager manager; private Joueur joueur; @@ -13,7 +17,6 @@ internal class JoueurClassementNbCoupParPartie get => joueur; private set => joueur = value; } - public int Place { get => manager.Joueurs @@ -21,7 +24,7 @@ internal class JoueurClassementNbCoupParPartie .IndexOf(Joueur) + 1; } - public int Point => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite); + public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite); public JoueurClassementNbCoupParPartie(Joueur joueur, Manager manager) { @@ -30,7 +33,7 @@ internal class JoueurClassementNbCoupParPartie } } -internal class JoueurClassementPartieGagnee +public class JoueurClassementPartieGagnee { private Manager manager; private Joueur joueur; @@ -46,7 +49,7 @@ internal class JoueurClassementPartieGagnee get => manager.Joueurs.OrderByDescending(joueur => joueur.NbPartieGagnee).ToList().IndexOf(Joueur) + 1; } - public int Point => joueur.NbPartieGagnee; + public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite); public JoueurClassementPartieGagnee(Joueur joueur, Manager manager) { @@ -55,7 +58,7 @@ internal class JoueurClassementPartieGagnee } } -internal class JoueurClassementPartieEgalite +public class JoueurClassementPartieEgalite { private Manager manager; private Joueur joueur; @@ -71,7 +74,7 @@ internal class JoueurClassementPartieEgalite get => manager.Joueurs.OrderByDescending(joueur => joueur.NbPartieEgalite).ToList().IndexOf(joueur)+1; } - public int Point => joueur.NbPartieEgalite; + public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite); public JoueurClassementPartieEgalite(Joueur joueur, Manager manager) { @@ -80,7 +83,7 @@ internal class JoueurClassementPartieEgalite } } -internal class JoueurClassementPartiePerdue +public class JoueurClassementPartiePerdue { private Manager manager; private Joueur joueur; @@ -96,26 +99,93 @@ internal class JoueurClassementPartiePerdue get => manager.Joueurs.OrderByDescending(joueur => joueur.NbPartiePerdue).ToList().IndexOf(joueur)+1; } - public int Point => joueur.NbPartiePerdue; + public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite); public JoueurClassementPartiePerdue(Joueur joueur, Manager manager) { this.manager = manager; this.joueur = joueur; } -} - -public partial class CTableauScore : ContentView -{ - public CTableauScore() - { - InitializeComponent(); +} + +public class JoueurClassementAlphabet +{ + private Manager manager; + private Joueur joueur; + + public Joueur Joueur + { + get => joueur; + private set => joueur = value; + } + + public int Place + { + get => manager.Joueurs + .OrderBy(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite)).ToList() + .IndexOf(Joueur) + 1; + } + + public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite); + + public JoueurClassementAlphabet(Joueur joueur, Manager manager) + { + this.manager = manager; + this.joueur = joueur; + } +} + + public partial class CTableauScore : ContentView +{ + public IEnumerable GetClassementNbCoupParPartie() + { + return MauiProgram.Manager.Joueurs + .OrderBy(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite)) + .Select(joueur => new JoueurClassementNbCoupParPartie(joueur, MauiProgram.Manager)); + } + + public IEnumerable GetClassementPartieGagnee() + { + return MauiProgram.Manager.Joueurs + .OrderByDescending(joueur => joueur.NbPartieGagnee) + .Select(joueur => new JoueurClassementPartieGagnee(joueur, MauiProgram.Manager)); + } + + public IEnumerable GetClassementPartieEgalite() + { + return MauiProgram.Manager.Joueurs + .OrderByDescending(joueur => joueur.NbPartieEgalite) + .Select(joueur => new JoueurClassementPartieEgalite(joueur, MauiProgram.Manager)); + } + + public IEnumerable GetClassementPartiePerdue() + { + return MauiProgram.Manager.Joueurs + .OrderByDescending(joueur => joueur.NbPartiePerdue) + .Select(joueur => new JoueurClassementPartiePerdue(joueur, MauiProgram.Manager)); + } + + public IEnumerable GetClassementAlphabetHaut() + { + return MauiProgram.Manager.Joueurs + .OrderBy(joueur => joueur.Nom) + .Select(joueur => new JoueurClassementAlphabet(joueur, MauiProgram.Manager)); + } + public IEnumerable GetClassementAlphabetBas() + { + return MauiProgram.Manager.Joueurs + .OrderByDescending(joueur => joueur.Nom) + .Select(joueur => new JoueurClassementAlphabet(joueur, MauiProgram.Manager)); + } - IEnumerable classement1 = MauiProgram.Manager.Joueurs.OrderBy(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite)).Select(joueur => new JoueurClassementNbCoupParPartie(joueur, MauiProgram.Manager)); - IEnumerable classement2 = MauiProgram.Manager.Joueurs.OrderByDescending(joueur => joueur.NbPartieGagnee).Select(joueur => new JoueurClassementPartieGagnee(joueur, MauiProgram.Manager)); - IEnumerable classement3 = MauiProgram.Manager.Joueurs.OrderByDescending(joueur => joueur.NbPartieEgalite).Select(joueur => new JoueurClassementPartieEgalite(joueur, MauiProgram.Manager)); - IEnumerable classement4 = MauiProgram.Manager.Joueurs.OrderByDescending(joueur => joueur.NbPartiePerdue).Select(joueur => new JoueurClassementPartiePerdue(joueur, MauiProgram.Manager)); - BindingContext = classement4; + public CTableauScore() + { + InitializeComponent(); + } + + public void UpdateClassement(Func> getClassement) + { + BindingContext = getClassement(); } } \ No newline at end of file diff --git a/Sources/UnitTesting/AjouterJoueurEventArgs.cs b/Sources/UnitTesting/AjouterJoueurEventArgs.cs index 5433ab5..f614d6b 100644 --- a/Sources/UnitTesting/AjouterJoueurEventArgs.cs +++ b/Sources/UnitTesting/AjouterJoueurEventArgs.cs @@ -10,7 +10,7 @@ namespace UnitTesting [Fact] public void TestConstructeurValide() { - Joueur monJoueur = new Joueur("Céleste", new Plateau(4, 12)); + Joueur monJoueur = new Joueur("Céleste"); AjouterJoueursEventArgs evenement = new AjouterJoueursEventArgs(monJoueur); diff --git a/Sources/UnitTesting/JoueurUT.cs b/Sources/UnitTesting/JoueurUT.cs index 5de0df7..147f3ee 100644 --- a/Sources/UnitTesting/JoueurUT.cs +++ b/Sources/UnitTesting/JoueurUT.cs @@ -7,13 +7,38 @@ namespace UnitTesting public class JoueurUT { [Fact] - public void TestConstructeurValide() + public void TestConstructeur1Valide() { - Plateau plateau = new Plateau(4, 10); - Joueur joueur = new Joueur("MonJoueur", plateau); + string nom = "toto"; - Assert.Equal("MonJoueur", joueur.Nom); - Assert.Equal(plateau, joueur.Plateau); + Joueur joueur = new Joueur(nom); + + + Assert.Equal(nom, joueur.Nom); + Assert.Equal(0, joueur.NbCoutTotal); + Assert.Equal(0, joueur.NbPartieGagnee); + Assert.Equal(0, joueur.NbPartieEgalite); + Assert.Equal(0, joueur.NbPartiePerdue); } + + + [Fact] + public void TestConstructeur2Valide() + { + string nom = "Bob"; + int nbCoutTotal = 10; + int nbPartieGagnee = 5; + int nbPartieEgalite = 2; + int nbPartiePerdue = 3; + + Joueur joueur = new Joueur(nom, nbCoutTotal, nbPartieGagnee, nbPartieEgalite, nbPartiePerdue); + + Assert.Equal(nom, joueur.Nom); + Assert.Equal(nbCoutTotal, joueur.NbCoutTotal); + Assert.Equal(nbPartieGagnee, joueur.NbPartieGagnee); + Assert.Equal(nbPartieEgalite, joueur.NbPartieEgalite); + Assert.Equal(nbPartiePerdue, joueur.NbPartiePerdue); + } + } } diff --git a/Sources/UnitTesting/NouveauTourEventArgsUT.cs b/Sources/UnitTesting/NouveauTourEventArgsUT.cs index a634a5f..d1f877a 100644 --- a/Sources/UnitTesting/NouveauTourEventArgsUT.cs +++ b/Sources/UnitTesting/NouveauTourEventArgsUT.cs @@ -11,7 +11,7 @@ namespace UnitTesting public void TestConstructeurValide() { Plateau monPlateau = new Plateau(4, 12); - Joueur monJoueur = new Joueur("Céleste", monPlateau); + Joueur monJoueur = new Joueur("Céleste"); NouveauTourEventArgs evenement = new NouveauTourEventArgs(monJoueur, 5, monPlateau.Grille(), monPlateau.Indicateurs()); diff --git a/Sources/UnitTesting/PartieTermineeEventArgsUT.cs b/Sources/UnitTesting/PartieTermineeEventArgsUT.cs index 9b96d40..09f0e6a 100644 --- a/Sources/UnitTesting/PartieTermineeEventArgsUT.cs +++ b/Sources/UnitTesting/PartieTermineeEventArgsUT.cs @@ -11,8 +11,8 @@ namespace UnitTesting public void TestConstructeurValide() { Plateau plateau = new Plateau(4, 12); - Joueur[] gagnants = [new Joueur("Pauline", plateau), new Joueur("Camille", plateau)]; - Joueur[] perdants = [new Joueur("Céleste", plateau)]; + Joueur[] gagnants = [new Joueur("Pauline"), new Joueur("Camille")]; + Joueur[] perdants = [new Joueur("Céleste")]; PartieTermineeEventArgs evenement = new PartieTermineeEventArgs(gagnants, perdants); diff --git a/Sources/UnitTesting/ReglesClassiquesUT.cs b/Sources/UnitTesting/ReglesClassiquesUT.cs index 25fcfb9..b58aa1c 100644 --- a/Sources/UnitTesting/ReglesClassiquesUT.cs +++ b/Sources/UnitTesting/ReglesClassiquesUT.cs @@ -52,14 +52,14 @@ namespace UnitTesting regles.CommencerLaPartie(); int? joueurCourantAvant = (int?) fieldInfo.GetValue(regles); - Joueur courantAvant = regles.JoueurCourant(); + Joueur courantAvant = regles.JoueurCourant().Item1; Assert.NotNull(joueurCourantAvant); Assert.Equal(0, joueurCourantAvant); regles.PasserLaMain(); int? joueurCourantApres = (int?)fieldInfo.GetValue(regles); - Joueur courantApres = regles.JoueurCourant(); + Joueur courantApres = regles.JoueurCourant().Item1; Assert.NotNull(joueurCourantApres); Assert.Equal(1, joueurCourantApres); Assert.NotEqual(joueurCourantAvant, joueurCourantApres); @@ -68,7 +68,7 @@ namespace UnitTesting regles.PasserLaMain(); int? joueurCourantBoucle = (int?)fieldInfo.GetValue(regles); - Joueur courantBoucle = regles.JoueurCourant(); + Joueur courantBoucle = regles.JoueurCourant().Item1; Assert.NotNull(joueurCourantBoucle); Assert.Equal(0, joueurCourantBoucle); Assert.NotEqual(joueurCourantApres, joueurCourantBoucle); @@ -103,7 +103,7 @@ namespace UnitTesting regles.PasserLaMain(); - Plateau plateauj1 = regles.JoueurCourant().Plateau; + Plateau plateauj1 = regles.JoueurCourant().Item2; type = typeof(Plateau); fieldInfo = type.GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance); @@ -112,7 +112,7 @@ namespace UnitTesting Code? codeSecret = (Code?)fieldInfo.GetValue(plateauj1); Assert.NotNull(codeSecret); - regles.JoueurCourant().Plateau.AjouterCode(codeSecret); + regles.JoueurCourant().Item2.AjouterCode(codeSecret); bool estTerminee = regles.EstTerminee(); @@ -132,7 +132,7 @@ namespace UnitTesting regles.CommencerLaPartie(); - Plateau plateauj1 = regles.JoueurCourant().Plateau; + Plateau plateauj1 = regles.JoueurCourant().Item2; Type type = typeof(Plateau); FieldInfo? fieldInfo = type.GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance); @@ -140,10 +140,10 @@ namespace UnitTesting Code? codeSecret = (Code?)fieldInfo.GetValue(plateauj1); Assert.NotNull(codeSecret); - regles.JoueurCourant().Plateau.AjouterCode(codeSecret); + regles.JoueurCourant().Item2.AjouterCode(codeSecret); IEnumerable gagnants = regles.Gagnants(); Assert.Single(gagnants); - Assert.Contains(regles.JoueurCourant(), gagnants); + Assert.Contains(regles.JoueurCourant().Item1, gagnants); } } } From 16d44c9b41dad8ad4bc4c288622c39c078183abe Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Fri, 24 May 2024 20:13:28 +0200 Subject: [PATCH 5/6] Correction smell copy --- Sources/CoreLibrary/Manager/IPersistanceManager.cs | 2 +- Sources/CoreLibrary/Manager/Manager.cs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/CoreLibrary/Manager/IPersistanceManager.cs b/Sources/CoreLibrary/Manager/IPersistanceManager.cs index 5795d3a..539a0d7 100644 --- a/Sources/CoreLibrary/Manager/IPersistanceManager.cs +++ b/Sources/CoreLibrary/Manager/IPersistanceManager.cs @@ -4,7 +4,7 @@ { public void Charger(); - public void Enregistrer(); + //public void Enregistrer(); } diff --git a/Sources/CoreLibrary/Manager/Manager.cs b/Sources/CoreLibrary/Manager/Manager.cs index 9988d53..357a472 100644 --- a/Sources/CoreLibrary/Manager/Manager.cs +++ b/Sources/CoreLibrary/Manager/Manager.cs @@ -6,7 +6,7 @@ namespace CoreLibrary.Manager public class Manager : IPersistanceManager { private Joueur[] joueurs = []; - public Joueur[] Joueurs => (Joueur[]) joueurs.Clone(); + public IReadOnlyList Joueurs => Array.AsReadOnly(joueurs); public void Charger() { @@ -18,9 +18,11 @@ namespace CoreLibrary.Manager ]; } + /* public void Enregistrer() { } + */ } } From cb312a435c05e481ee7c6db6ad8c51f71df8fe7f Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Fri, 24 May 2024 20:15:41 +0200 Subject: [PATCH 6/6] Correction smell Enregistrer --- Sources/CoreLibrary/Manager/IPersistanceManager.cs | 2 +- Sources/CoreLibrary/Manager/Manager.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/CoreLibrary/Manager/IPersistanceManager.cs b/Sources/CoreLibrary/Manager/IPersistanceManager.cs index 539a0d7..5795d3a 100644 --- a/Sources/CoreLibrary/Manager/IPersistanceManager.cs +++ b/Sources/CoreLibrary/Manager/IPersistanceManager.cs @@ -4,7 +4,7 @@ { public void Charger(); - //public void Enregistrer(); + public void Enregistrer(); } diff --git a/Sources/CoreLibrary/Manager/Manager.cs b/Sources/CoreLibrary/Manager/Manager.cs index 357a472..55ad615 100644 --- a/Sources/CoreLibrary/Manager/Manager.cs +++ b/Sources/CoreLibrary/Manager/Manager.cs @@ -18,11 +18,11 @@ namespace CoreLibrary.Manager ]; } - /* + public void Enregistrer() { - + throw new NotImplementedException(); } - */ + } }