Data Biding avec les boutons (alphabet, nbpartiegagnee, NbpartiePerdu,NbPartieEgalite) et correction des tests pour que sa marche avec la nouvel class joueur.
continuous-integration/drone/push Build is passing Details

master
Camille TURPIN-ETIENNE 11 months ago
parent c9cf49ab78
commit a0cee7e7c7

@ -18,14 +18,18 @@
</Grid>
</FlexLayout>
<Frame Margin="20" >
<Grid ColumnDefinitions="auto,*,auto,auto" ColumnSpacing="10">
<Button Margin="0,5,5,5" Grid.Column="0" Text="RANK" Style="{StaticResource ButtonTableau}"></Button>
<Button Margin="5" Grid.Column="1" Text="PSEUDO" Style="{StaticResource ButtonTableau}" HorizontalOptions="Start" ></Button>
<Button Margin="5" Grid.Column="2" Text="Nombre de coût Moyen" Style="{StaticResource ButtonTableau}"></Button>
<Button Margin="5" Grid.Column="3" Text="POINT" Style="{StaticResource ButtonTableau}"></Button>
<Grid ColumnDefinitions="auto,auto,*,auto,auto,auto,auto" RowDefinitions="1,*,1" RowSpacing="0" ColumnSpacing="10" >
<Label Margin="5" Grid.Column="0" Grid.Row="1" Text="RANK" Style="{StaticResource ButtonTableau}" VerticalOptions="Center"></Label>
<Label Margin="5" Grid.Column="1" Grid.Row="1" Text="PSEUDO" Style="{StaticResource ButtonTableau}" VerticalOptions="Center"></Label>
<Button Margin="0" Grid.Column="2" Grid.Row="0" Text="+" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" HorizontalOptions="Start" Clicked="QuandAlphabetHautButtonClicked" ></Button>
<Button Margin="0" Grid.Column="2" Grid.Row="2" Text="-" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" HorizontalOptions="Start" Clicked="QuandAlphabetBasButtonClicked" ></Button>
<Button Margin="5" Grid.Column="3" Grid.Row="1" Text="Nombre de coût Moyen" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandNbCoutMoyenButtonClicked"></Button>
<Button Margin="5" Grid.Column="4" Grid.Row="1" Text="Partie Gagnee" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandGagneeButtonClicked"></Button>
<Button Margin="5" Grid.Column="5" Grid.Row="1" Text="Partie Perdue" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandPerduButtonClicked"></Button>
<Button Margin="5" Grid.Column="6" Grid.Row="1" Text="Partie Egalite" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandEgaliteButtonClicked"></Button>
</Grid>
</Frame>
<views:CTableauScore/>
<views:CTableauScore x:Name="CTableauScore"/>
</VerticalStackLayout>
</ScrollView>

@ -1,3 +1,7 @@
using CoreLibrary.Joueurs;
using MauiSpark.Views;
using System.Collections.ObjectModel;
namespace MauiSpark.Pages;
public partial class TableauScore : ContentPage
@ -5,5 +9,40 @@ public partial class TableauScore : ContentPage
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);
}
}

@ -2,24 +2,22 @@
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiSpark.Views.CTableauScore">
<Frame CornerRadius="5" Padding="0" VerticalOptions="Start" Margin="20,0,20,10" >
<Grid ColumnDefinitions="auto,*,auto,auto" ColumnSpacing="10">
<ListView ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid ColumnDefinitions="*,*,*,*">
<Label Grid.Column="0" Text="{Binding Place}" Margin="20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="1" Text="{Binding Joueur.Nom}" Margin="20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="3" Text="{Binding Point}" Margin="20" Style="{StaticResource TexteFrame}" />
<Grid ColumnDefinitions="auto,*,auto,auto,auto,auto">
<Label Grid.Column="0" Text="{Binding Place}" Margin="20,20,20,20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="1" Text="{Binding Joueur.Nom}" Margin="20,20,20,20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="2" Text="{Binding NbCoutMoyen}" Margin="20,20,100,20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="3" Text="{Binding Joueur.NbPartieGagnee}" Margin="75,20,100,20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="4" Text="{Binding Joueur.NbPartiePerdue}" Margin="75,20,100,20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="5" Text="{Binding Joueur.NbPartieEgalite}" Margin="75,20,100,20" Style="{StaticResource TexteFrame}" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Frame>
</ContentView>

@ -1,9 +1,13 @@
using CoreLibrary.Events;
using CoreLibrary.Joueurs;
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,7 +99,7 @@ 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)
{
@ -105,17 +108,84 @@ internal class JoueurClassementPartiePerdue
}
}
public partial class CTableauScore : ContentView
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<JoueurClassementNbCoupParPartie> GetClassementNbCoupParPartie()
{
return MauiProgram.Manager.Joueurs
.OrderBy(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite))
.Select(joueur => new JoueurClassementNbCoupParPartie(joueur, MauiProgram.Manager));
}
public IEnumerable<JoueurClassementPartieGagnee> GetClassementPartieGagnee()
{
return MauiProgram.Manager.Joueurs
.OrderByDescending(joueur => joueur.NbPartieGagnee)
.Select(joueur => new JoueurClassementPartieGagnee(joueur, MauiProgram.Manager));
}
public IEnumerable<JoueurClassementPartieEgalite> GetClassementPartieEgalite()
{
return MauiProgram.Manager.Joueurs
.OrderByDescending(joueur => joueur.NbPartieEgalite)
.Select(joueur => new JoueurClassementPartieEgalite(joueur, MauiProgram.Manager));
}
public IEnumerable<JoueurClassementPartiePerdue> GetClassementPartiePerdue()
{
return MauiProgram.Manager.Joueurs
.OrderByDescending(joueur => joueur.NbPartiePerdue)
.Select(joueur => new JoueurClassementPartiePerdue(joueur, MauiProgram.Manager));
}
public IEnumerable<JoueurClassementAlphabet> GetClassementAlphabetHaut()
{
return MauiProgram.Manager.Joueurs
.OrderBy(joueur => joueur.Nom)
.Select(joueur => new JoueurClassementAlphabet(joueur, MauiProgram.Manager));
}
public IEnumerable<JoueurClassementAlphabet> GetClassementAlphabetBas()
{
return MauiProgram.Manager.Joueurs
.OrderByDescending(joueur => joueur.Nom)
.Select(joueur => new JoueurClassementAlphabet(joueur, MauiProgram.Manager));
}
public CTableauScore()
{
InitializeComponent();
}
IEnumerable<JoueurClassementNbCoupParPartie> classement1 = MauiProgram.Manager.Joueurs.OrderBy(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite)).Select(joueur => new JoueurClassementNbCoupParPartie(joueur, MauiProgram.Manager));
IEnumerable<JoueurClassementPartieGagnee> classement2 = MauiProgram.Manager.Joueurs.OrderByDescending(joueur => joueur.NbPartieGagnee).Select(joueur => new JoueurClassementPartieGagnee(joueur, MauiProgram.Manager));
IEnumerable<JoueurClassementPartieEgalite> classement3 = MauiProgram.Manager.Joueurs.OrderByDescending(joueur => joueur.NbPartieEgalite).Select(joueur => new JoueurClassementPartieEgalite(joueur, MauiProgram.Manager));
IEnumerable<JoueurClassementPartiePerdue> classement4 = MauiProgram.Manager.Joueurs.OrderByDescending(joueur => joueur.NbPartiePerdue).Select(joueur => new JoueurClassementPartiePerdue(joueur, MauiProgram.Manager));
BindingContext = classement4;
public void UpdateClassement(Func<IEnumerable<object>> getClassement)
{
BindingContext = getClassement();
}
}

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

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

@ -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());

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

@ -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<Joueur> gagnants = regles.Gagnants();
Assert.Single(gagnants);
Assert.Contains(regles.JoueurCourant(), gagnants);
Assert.Contains(regles.JoueurCourant().Item1, gagnants);
}
}
}

Loading…
Cancel
Save