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); } } }