Tableau bouton trier
continuous-integration/drone/push Build is passing Details

master
parent cb312a435c
commit 9ed8196d3e

@ -1,177 +1,177 @@
using CoreLibrary.Exceptions; using CoreLibrary.Exceptions;
namespace CoreLibrary.Core namespace CoreLibrary.Core
{ {
/// <summary> /// <summary>
/// Classe représentant un code composé de jetons et ses différentes méthodes. /// Classe représentant un code composé de jetons et ses différentes méthodes.
/// </summary> /// </summary>
public class Code public class Code
{ {
private readonly Jeton?[] lesJetons; private readonly Jeton?[] lesJetons;
/// <summary> /// <summary>
/// Le nombre de jetons dans le code. /// Le nombre de jetons dans le code.
/// </summary> /// </summary>
public int NbJetons { get; private set; } = 0; public int NbJetons { get; private set; } = 0;
/// <summary> /// <summary>
/// Initialise une nouvelle instance de la classe <see cref="Code"/> avec la longueur de code spécifiée. /// Initialise une nouvelle instance de la classe <see cref="Code"/> avec la longueur de code spécifiée.
/// </summary> /// </summary>
/// <param name="tailleCode">La longueur du code.</param> /// <param name="tailleCode">La longueur du code.</param>
/// <exception cref="TailleCodeException">Levée lorsque la longueur du code spécifiée est inférieure ou égale à zéro.</exception> /// <exception cref="TailleCodeException">Levée lorsque la longueur du code spécifiée est inférieure ou égale à zéro.</exception>
public Code(int tailleCode) public Code(int tailleCode)
{
if (tailleCode <= 0)
{
throw new TailleCodeException(tailleCode);
}
lesJetons = new Jeton?[tailleCode];
}
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="Code"/> avec les jetons spécifiés.
/// </summary>
/// <param name="jetons">Les jetons pour initaliser le code.</param>
/// <exception cref="TailleCodeException">Levée lorsque la collection de jetons spécifiée est vide.</exception>
public Code(IEnumerable<Jeton> jetons)
{
if (!jetons.Any())
{
throw new TailleCodeException(jetons.Count());
}
lesJetons = new Jeton?[jetons.Count()];
foreach (Jeton jeton in jetons)
{
AjouterJeton(jeton);
}
}
/// <summary>
/// Ajoute un jeton au code.
/// </summary>
/// <param name="jeton">Le jeton à ajouter.</param>
/// <exception cref="CodeCompletException">Levée lorsque le code est plein.</exception>
public void AjouterJeton(Jeton jeton)
{
if (NbJetons == TailleMaximale())
{
throw new CodeCompletException();
}
lesJetons[NbJetons++] = jeton;
}
/// <summary>
/// Supprime le dernier jeton ajouté au code.
/// </summary>
/// <exception cref="CodeVideException">Levée lorsque le code est vide.</exception>
public void SupprimerDernierJeton()
{ {
if (tailleCode <= 0) if (NbJetons == 0)
{ {
throw new TailleCodeException(tailleCode); throw new CodeVideException();
}
lesJetons = new Jeton?[tailleCode];
}
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="Code"/> avec les jetons spécifiés.
/// </summary>
/// <param name="jetons">Les jetons pour initaliser le code.</param>
/// <exception cref="TailleCodeException">Levée lorsque la collection de jetons spécifiée est vide.</exception>
public Code(IEnumerable<Jeton> jetons)
{
if (!jetons.Any())
{
throw new TailleCodeException(jetons.Count());
}
lesJetons = new Jeton?[jetons.Count()];
foreach (Jeton jeton in jetons)
{
AjouterJeton(jeton);
}
}
/// <summary>
/// Ajoute un jeton au code.
/// </summary>
/// <param name="jeton">Le jeton à ajouter.</param>
/// <exception cref="CodeCompletException">Levée lorsque le code est plein.</exception>
public void AjouterJeton(Jeton jeton)
{
if (NbJetons == TailleMaximale())
{
throw new CodeCompletException();
}
lesJetons[NbJetons++] = jeton;
}
/// <summary>
/// Supprime le dernier jeton ajouté au code.
/// </summary>
/// <exception cref="CodeVideException">Levée lorsque le code est vide.</exception>
public void SupprimerDernierJeton()
{
if (NbJetons == 0)
{
throw new CodeVideException();
} }
lesJetons[--NbJetons] = null; lesJetons[--NbJetons] = null;
} }
/// <summary> /// <summary>
/// Récupère le jeton à l'indice spécifié dans le code. /// Récupère le jeton à l'indice spécifié dans le code.
/// </summary> /// </summary>
/// <param name="indice">L'indice du jeton a récupéré.</param> /// <param name="indice">L'indice du jeton a récupéré.</param>
/// <returns>Le jeton situé à l'indice spécifié.</returns> /// <returns>Le jeton situé à l'indice spécifié.</returns>
/// <exception cref="IndiceCodeException">Levée lorsque l'indice est supérieur à la taille maximale du code, inférieur à 0 ou qu'il n'y a pas de jeton à l'indice spécifié</exception> /// <exception cref="IndiceCodeException">Levée lorsque l'indice est supérieur à la taille maximale du code, inférieur à 0 ou qu'il n'y a pas de jeton à l'indice spécifié</exception>
public Jeton RecupererJeton(int indice) public Jeton RecupererJeton(int indice)
{ {
if (indice < 0 || indice >= TailleMaximale()) if (indice < 0 || indice >= TailleMaximale())
throw new IndiceCodeException(indice, NbJetons - 1); throw new IndiceCodeException(indice, NbJetons - 1);
Jeton? jeton = lesJetons[indice]; Jeton? jeton = lesJetons[indice];
if (!jeton.HasValue) if (!jeton.HasValue)
throw new IndiceCodeException(indice, NbJetons - 1); throw new IndiceCodeException(indice, NbJetons - 1);
return jeton.Value; return jeton.Value;
} }
/// <summary> /// <summary>
/// Récupère une liste des jetons dans le code. /// Récupère une liste des jetons dans le code.
/// </summary> /// </summary>
/// <returns>Les jetons du code.</returns> /// <returns>Les jetons du code.</returns>
public IEnumerable<Jeton?> Jetons() public IEnumerable<Jeton?> Jetons()
{ {
return lesJetons; return lesJetons;
} }
/// <summary> /// <summary>
/// Vérifie si le code est complet. /// Vérifie si le code est complet.
/// </summary> /// </summary>
/// <returns>True si le code est complet, sinon False.</returns> /// <returns>True si le code est complet, sinon False.</returns>
public bool EstComplet() public bool EstComplet()
{ {
return NbJetons == lesJetons.Length; return NbJetons == lesJetons.Length;
} }
/// <summary> /// <summary>
/// Recupère la taille maximale du code. /// Recupère la taille maximale du code.
/// </summary> /// </summary>
/// <returns>Taille maximale du code.</returns> /// <returns>Taille maximale du code.</returns>
public int TailleMaximale() public int TailleMaximale()
{ {
return lesJetons.Length; return lesJetons.Length;
} }
/// <summary> /// <summary>
/// Compare le code avec un autre code et génère des indicateurs. /// Compare le code avec un autre code et génère des indicateurs.
/// </summary> /// </summary>
/// <param name="autreCode">Le code à comparer avec le code actuel.</param> /// <param name="autreCode">Le code à comparer avec le code actuel.</param>
/// <returns>Les indicateurs de bonne place et bonne couleur entre les deux codes.</returns> /// <returns>Les indicateurs de bonne place et bonne couleur entre les deux codes.</returns>
public IEnumerable<Indicateur> Comparer(Code autreCode) public IEnumerable<Indicateur> Comparer(Code autreCode)
{ {
// Mon code est le code correct, l'autre code est celui qui teste // Mon code est le code correct, l'autre code est celui qui teste
Indicateur[] indicateurs = []; Indicateur[] indicateurs = [];
if (!autreCode.EstComplet()) if (!autreCode.EstComplet())
return indicateurs; return indicateurs;
List<Jeton?> mesJetons = new List<Jeton?>(Jetons()); List<Jeton?> mesJetons = new List<Jeton?>(Jetons());
List<Jeton?> sesJetons = new List<Jeton?>(autreCode.Jetons()); List<Jeton?> sesJetons = new List<Jeton?>(autreCode.Jetons());
for (int i = 0; i < mesJetons.Count; ++i) for (int i = 0; i < mesJetons.Count; ++i)
{ {
Jeton? monJeton = mesJetons[i]; Jeton? monJeton = mesJetons[i];
Jeton? sonJeton = sesJetons[i]; Jeton? sonJeton = sesJetons[i];
if (monJeton.HasValue && sonJeton.HasValue && monJeton.Value.Couleur.Equals(sonJeton.Value.Couleur)) if (monJeton.HasValue && sonJeton.HasValue && monJeton.Value.Couleur.Equals(sonJeton.Value.Couleur))
{ {
indicateurs = indicateurs.Append(Indicateur.BONNEPLACE).ToArray(); indicateurs = indicateurs.Append(Indicateur.BONNEPLACE).ToArray();
mesJetons[i] = null; mesJetons[i] = null;
sesJetons[i] = null; sesJetons[i] = null;
} }
} }
for (int i = 0; i < sesJetons.Count; ++i) for (int i = 0; i < sesJetons.Count; ++i)
{ {
Jeton? sonJeton = sesJetons[i]; Jeton? sonJeton = sesJetons[i];
if (sonJeton.HasValue && mesJetons.Contains(sonJeton.Value)) if (sonJeton.HasValue && mesJetons.Contains(sonJeton.Value))
{ {
indicateurs = indicateurs.Append(Indicateur.BONNECOULEUR).ToArray(); indicateurs = indicateurs.Append(Indicateur.BONNECOULEUR).ToArray();
mesJetons[mesJetons.IndexOf(sonJeton)] = null; mesJetons[mesJetons.IndexOf(sonJeton)] = null;
sesJetons[i] = null; sesJetons[i] = null;
} }
} }
return indicateurs; return indicateurs;
} }
} }
} }

@ -18,15 +18,13 @@
</Grid> </Grid>
</FlexLayout> </FlexLayout>
<Frame Margin="20" > <Frame Margin="20" >
<Grid ColumnDefinitions="auto,auto,*,auto,auto,auto,auto" RowDefinitions="1,*,1" RowSpacing="0" ColumnSpacing="10" > <Grid ColumnDefinitions="auto,*,auto,auto,auto,auto" ColumnSpacing="10" >
<Label Margin="5" Grid.Column="0" Grid.Row="1" Text="RANK" Style="{StaticResource ButtonTableau}" VerticalOptions="Center"></Label> <Button Margin="5" Grid.Column="0" Text="RANK" Style="{StaticResource ButtonTableau}" VerticalOptions="Center"></Button>
<Label Margin="5" Grid.Column="1" Grid.Row="1" Text="PSEUDO" Style="{StaticResource ButtonTableau}" VerticalOptions="Center"></Label> <Button Margin="5" Grid.Column="1" Text="PSEUDO" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" HorizontalOptions="Start" Clicked="QuandAlphabetButtonClicked" ></Button>
<Button Margin="0" Grid.Column="2" Grid.Row="0" Text="+" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" HorizontalOptions="Start" Clicked="QuandAlphabetHautButtonClicked" ></Button> <Button Margin="5" Grid.Column="2" Text="Coût Moyen" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandNbCoutMoyenButtonClicked"></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" Text="Partie Gagnée" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandGagneeButtonClicked"></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" Text="Partie Perdue" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandPerduButtonClicked"></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" Text="Partie Egalité" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandEgaliteButtonClicked"></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> </Grid>
</Frame> </Frame>
<views:CTableauScore x:Name="CTableauScore"/> <views:CTableauScore x:Name="CTableauScore"/>

@ -18,6 +18,7 @@ public partial class TableauScore : ContentPage
private void QuandNbCoutMoyenButtonClicked(object sender, EventArgs e) private void QuandNbCoutMoyenButtonClicked(object sender, EventArgs e)
{ {
CTableauScore.UpdateClassement(CTableauScore.GetClassementNbCoupParPartie); CTableauScore.UpdateClassement(CTableauScore.GetClassementNbCoupParPartie);
} }
@ -36,13 +37,8 @@ public partial class TableauScore : ContentPage
CTableauScore.UpdateClassement(CTableauScore.GetClassementPartieEgalite); CTableauScore.UpdateClassement(CTableauScore.GetClassementPartieEgalite);
} }
private void QuandAlphabetHautButtonClicked(object sender, EventArgs e) private void QuandAlphabetButtonClicked(object sender, EventArgs e)
{ {
CTableauScore.UpdateClassement(CTableauScore.GetClassementAlphabetHaut); CTableauScore.UpdateClassement(CTableauScore.GetClassementAlphabet);
}
private void QuandAlphabetBasButtonClicked(object sender, EventArgs e)
{
CTableauScore.UpdateClassement(CTableauScore.GetClassementAlphabetBas);
} }
} }

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

@ -137,48 +137,102 @@ public class JoueurClassementAlphabet
public partial class CTableauScore : ContentView public partial class CTableauScore : ContentView
{ {
public int NbCliquer { get; set; } = 0;
public IEnumerable<JoueurClassementNbCoupParPartie> GetClassementNbCoupParPartie() public IEnumerable<JoueurClassementNbCoupParPartie> GetClassementNbCoupParPartie()
{ {
return MauiProgram.Manager.Joueurs if(NbCliquer % 2 == 0)
{
NbCliquer++;
return MauiProgram.Manager.Joueurs
.OrderBy(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite)) .OrderBy(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite))
.Select(joueur => new JoueurClassementNbCoupParPartie(joueur, MauiProgram.Manager)); .Select(joueur => new JoueurClassementNbCoupParPartie(joueur, MauiProgram.Manager));
}
else
{
NbCliquer++;
return MauiProgram.Manager.Joueurs
.OrderByDescending(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite))
.Select(joueur => new JoueurClassementNbCoupParPartie(joueur, MauiProgram.Manager));
}
} }
public IEnumerable<JoueurClassementPartieGagnee> GetClassementPartieGagnee() public IEnumerable<JoueurClassementPartieGagnee> GetClassementPartieGagnee()
{ {
return MauiProgram.Manager.Joueurs if(NbCliquer % 2 == 0)
.OrderByDescending(joueur => joueur.NbPartieGagnee) {
.Select(joueur => new JoueurClassementPartieGagnee(joueur, MauiProgram.Manager)); NbCliquer++;
return MauiProgram.Manager.Joueurs
.OrderByDescending(joueur => joueur.NbPartieGagnee)
.Select(joueur => new JoueurClassementPartieGagnee(joueur, MauiProgram.Manager));
}
else
{
NbCliquer++;
return MauiProgram.Manager.Joueurs
.OrderBy(joueur => joueur.NbPartieGagnee)
.Select(joueur => new JoueurClassementPartieGagnee(joueur, MauiProgram.Manager));
}
} }
public IEnumerable<JoueurClassementPartieEgalite> GetClassementPartieEgalite() public IEnumerable<JoueurClassementPartieEgalite> GetClassementPartieEgalite()
{ {
return MauiProgram.Manager.Joueurs if(NbCliquer % 2 == 0)
.OrderByDescending(joueur => joueur.NbPartieEgalite) {
.Select(joueur => new JoueurClassementPartieEgalite(joueur, MauiProgram.Manager)); NbCliquer++;
return MauiProgram.Manager.Joueurs
.OrderByDescending(joueur => joueur.NbPartieEgalite)
.Select(joueur => new JoueurClassementPartieEgalite(joueur, MauiProgram.Manager));
}
else
{
NbCliquer++;
return MauiProgram.Manager.Joueurs
.OrderBy(joueur => joueur.NbPartieEgalite)
.Select(joueur => new JoueurClassementPartieEgalite(joueur, MauiProgram.Manager));
}
} }
public IEnumerable<JoueurClassementPartiePerdue> GetClassementPartiePerdue() public IEnumerable<JoueurClassementPartiePerdue> GetClassementPartiePerdue()
{ {
return MauiProgram.Manager.Joueurs if(NbCliquer % 2 == 0)
{
NbCliquer++;
return MauiProgram.Manager.Joueurs
.OrderByDescending(joueur => joueur.NbPartiePerdue) .OrderByDescending(joueur => joueur.NbPartiePerdue)
.Select(joueur => new JoueurClassementPartiePerdue(joueur, MauiProgram.Manager)); .Select(joueur => new JoueurClassementPartiePerdue(joueur, MauiProgram.Manager));
} }
else
public IEnumerable<JoueurClassementAlphabet> GetClassementAlphabetHaut() {
{ NbCliquer++;
return MauiProgram.Manager.Joueurs ; return MauiProgram.Manager.Joueurs
.OrderBy(joueur => joueur.Nom) .OrderBy(joueur => joueur.NbPartiePerdue)
.Select(joueur => new JoueurClassementAlphabet(joueur, MauiProgram.Manager)); .Select(joueur => new JoueurClassementPartiePerdue(joueur, MauiProgram.Manager));
} }
public IEnumerable<JoueurClassementAlphabet> GetClassementAlphabetBas()
{ }
return MauiProgram.Manager.Joueurs
public IEnumerable<JoueurClassementAlphabet> GetClassementAlphabet()
{
if(NbCliquer % 2 == 0)
{
NbCliquer++;
return MauiProgram.Manager.Joueurs
.OrderBy(joueur => joueur.Nom)
.Select(joueur => new JoueurClassementAlphabet(joueur, MauiProgram.Manager));
}
else
{
NbCliquer++;
return MauiProgram.Manager.Joueurs
.OrderByDescending(joueur => joueur.Nom) .OrderByDescending(joueur => joueur.Nom)
.Select(joueur => new JoueurClassementAlphabet(joueur, MauiProgram.Manager)); .Select(joueur => new JoueurClassementAlphabet(joueur, MauiProgram.Manager));
}
} }
public CTableauScore() public CTableauScore()
{ {
InitializeComponent(); InitializeComponent();

Loading…
Cancel
Save