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

master
Camille TURPIN-ETIENNE 11 months ago
parent cb312a435c
commit 9ed8196d3e

@ -1,177 +1,177 @@
using CoreLibrary.Exceptions;
namespace CoreLibrary.Core
{
/// <summary>
/// Classe représentant un code composé de jetons et ses différentes méthodes.
/// </summary>
public class Code
{
private readonly Jeton?[] lesJetons;
/// <summary>
/// Le nombre de jetons dans le code.
/// </summary>
public int NbJetons { get; private set; } = 0;
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="Code"/> avec la longueur de code spécifiée.
/// </summary>
/// <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>
public Code(int tailleCode)
using CoreLibrary.Exceptions;
namespace CoreLibrary.Core
{
/// <summary>
/// Classe représentant un code composé de jetons et ses différentes méthodes.
/// </summary>
public class Code
{
private readonly Jeton?[] lesJetons;
/// <summary>
/// Le nombre de jetons dans le code.
/// </summary>
public int NbJetons { get; private set; } = 0;
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="Code"/> avec la longueur de code spécifiée.
/// </summary>
/// <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>
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)
{
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 (NbJetons == 0)
{
throw new CodeVideException();
if (NbJetons == 0)
{
throw new CodeVideException();
}
lesJetons[--NbJetons] = null;
}
/// <summary>
/// Récupère le jeton à l'indice spécifié dans le code.
/// </summary>
/// <param name="indice">L'indice du jeton a récupéré.</param>
/// <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>
public Jeton RecupererJeton(int indice)
{
if (indice < 0 || indice >= TailleMaximale())
lesJetons[--NbJetons] = null;
}
/// <summary>
/// Récupère le jeton à l'indice spécifié dans le code.
/// </summary>
/// <param name="indice">L'indice du jeton a récupéré.</param>
/// <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>
public Jeton RecupererJeton(int indice)
{
if (indice < 0 || indice >= TailleMaximale())
throw new IndiceCodeException(indice, NbJetons - 1);
Jeton? jeton = lesJetons[indice];
if (!jeton.HasValue)
throw new IndiceCodeException(indice, NbJetons - 1);
return jeton.Value;
}
/// <summary>
/// Récupère une liste des jetons dans le code.
/// </summary>
/// <returns>Les jetons du code.</returns>
public IEnumerable<Jeton?> Jetons()
{
return lesJetons;
}
/// <summary>
/// Vérifie si le code est complet.
/// </summary>
/// <returns>True si le code est complet, sinon False.</returns>
public bool EstComplet()
{
return NbJetons == lesJetons.Length;
}
/// <summary>
/// Recupère la taille maximale du code.
/// </summary>
/// <returns>Taille maximale du code.</returns>
public int TailleMaximale()
{
return lesJetons.Length;
}
/// <summary>
/// Compare le code avec un autre code et génère des indicateurs.
/// </summary>
/// <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>
public IEnumerable<Indicateur> Comparer(Code autreCode)
{
// Mon code est le code correct, l'autre code est celui qui teste
Indicateur[] indicateurs = [];
if (!autreCode.EstComplet())
return indicateurs;
List<Jeton?> mesJetons = new List<Jeton?>(Jetons());
List<Jeton?> sesJetons = new List<Jeton?>(autreCode.Jetons());
for (int i = 0; i < mesJetons.Count; ++i)
{
Jeton? monJeton = mesJetons[i];
Jeton? sonJeton = sesJetons[i];
if (monJeton.HasValue && sonJeton.HasValue && monJeton.Value.Couleur.Equals(sonJeton.Value.Couleur))
{
indicateurs = indicateurs.Append(Indicateur.BONNEPLACE).ToArray();
mesJetons[i] = null;
sesJetons[i] = null;
}
}
for (int i = 0; i < sesJetons.Count; ++i)
{
Jeton? jeton = lesJetons[indice];
if (!jeton.HasValue)
throw new IndiceCodeException(indice, NbJetons - 1);
return jeton.Value;
}
/// <summary>
/// Récupère une liste des jetons dans le code.
/// </summary>
/// <returns>Les jetons du code.</returns>
public IEnumerable<Jeton?> Jetons()
{
return lesJetons;
}
/// <summary>
/// Vérifie si le code est complet.
/// </summary>
/// <returns>True si le code est complet, sinon False.</returns>
public bool EstComplet()
{
return NbJetons == lesJetons.Length;
}
/// <summary>
/// Recupère la taille maximale du code.
/// </summary>
/// <returns>Taille maximale du code.</returns>
public int TailleMaximale()
{
return lesJetons.Length;
}
/// <summary>
/// Compare le code avec un autre code et génère des indicateurs.
/// </summary>
/// <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>
public IEnumerable<Indicateur> Comparer(Code autreCode)
{
// Mon code est le code correct, l'autre code est celui qui teste
Indicateur[] indicateurs = [];
if (!autreCode.EstComplet())
return indicateurs;
List<Jeton?> mesJetons = new List<Jeton?>(Jetons());
List<Jeton?> sesJetons = new List<Jeton?>(autreCode.Jetons());
for (int i = 0; i < mesJetons.Count; ++i)
{
Jeton? monJeton = mesJetons[i];
Jeton? sonJeton = sesJetons[i];
if (monJeton.HasValue && sonJeton.HasValue && monJeton.Value.Couleur.Equals(sonJeton.Value.Couleur))
{
indicateurs = indicateurs.Append(Indicateur.BONNEPLACE).ToArray();
mesJetons[i] = null;
sesJetons[i] = null;
}
}
for (int i = 0; i < sesJetons.Count; ++i)
{
Jeton? sonJeton = sesJetons[i];
if (sonJeton.HasValue && mesJetons.Contains(sonJeton.Value))
{
indicateurs = indicateurs.Append(Indicateur.BONNECOULEUR).ToArray();
mesJetons[mesJetons.IndexOf(sonJeton)] = null;
sesJetons[i] = null;
}
}
return indicateurs;
}
}
}
if (sonJeton.HasValue && mesJetons.Contains(sonJeton.Value))
{
indicateurs = indicateurs.Append(Indicateur.BONNECOULEUR).ToArray();
mesJetons[mesJetons.IndexOf(sonJeton)] = null;
sesJetons[i] = null;
}
}
return indicateurs;
}
}
}

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

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

@ -2,22 +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" >
<ListView ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ListView ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame CornerRadius="5" Padding="0" VerticalOptions="Start" Margin="20,0,20,10" >
<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="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="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}" />
<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="55,20,100,20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="5" Text="{Binding Joueur.NbPartieEgalite}" Margin="55,20,100,20" Style="{StaticResource TexteFrame}" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Frame>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentView>

@ -137,48 +137,102 @@ public class JoueurClassementAlphabet
public partial class CTableauScore : ContentView
{
public int NbCliquer { get; set; } = 0;
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))
.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()
{
return MauiProgram.Manager.Joueurs
.OrderByDescending(joueur => joueur.NbPartieGagnee)
.Select(joueur => new JoueurClassementPartieGagnee(joueur, MauiProgram.Manager));
if(NbCliquer % 2 == 0)
{
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()
{
return MauiProgram.Manager.Joueurs
.OrderByDescending(joueur => joueur.NbPartieEgalite)
.Select(joueur => new JoueurClassementPartieEgalite(joueur, MauiProgram.Manager));
if(NbCliquer % 2 == 0)
{
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()
{
return MauiProgram.Manager.Joueurs
if(NbCliquer % 2 == 0)
{
NbCliquer++;
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
}
else
{
NbCliquer++;
; return MauiProgram.Manager.Joueurs
.OrderBy(joueur => joueur.NbPartiePerdue)
.Select(joueur => new JoueurClassementPartiePerdue(joueur, MauiProgram.Manager));
}
}
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)
.Select(joueur => new JoueurClassementAlphabet(joueur, MauiProgram.Manager));
}
}
public CTableauScore()
{
InitializeComponent();

Loading…
Cancel
Save