You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
139 lines
4.6 KiB
139 lines
4.6 KiB
using CoreLibrary.Joueurs;
|
|
using CoreLibrary.Statistiques;
|
|
using CoreLibrary.Regles;
|
|
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace MauiSpark.Pages
|
|
{
|
|
partial class Enfant
|
|
{
|
|
private readonly Classement classement;
|
|
|
|
private int PartieJouee => PartieGagnee + PartieEgalite + PartiePerdue;
|
|
|
|
public Joueur Joueur { get; set; }
|
|
public int Place => classement.Enfants.ToList().IndexOf(this) + 1;
|
|
public int NbCoupMoyen => PartieJouee > 0 ? Joueur.Statistique(classement.Regles, Statistique.CoupJoue) / PartieJouee : Joueur.Statistique(classement.Regles, Statistique.CoupJoue);
|
|
public int PartieGagnee => Joueur.Statistique(classement.Regles, Statistique.PartieGagnee);
|
|
public int PartiePerdue => Joueur.Statistique(classement.Regles, Statistique.PartiePerdue);
|
|
public int PartieEgalite => Joueur.Statistique(classement.Regles, Statistique.PartieEgalite);
|
|
|
|
public Enfant(Joueur joueur, Classement classement)
|
|
{
|
|
this.classement = classement;
|
|
Joueur = joueur;
|
|
}
|
|
|
|
public override bool Equals(object? obj)
|
|
{
|
|
if (obj == null || obj is not Enfant)
|
|
return false;
|
|
|
|
return ((Enfant)obj).Joueur.Equals(Joueur);
|
|
}
|
|
|
|
public override int GetHashCode() => Joueur.GetHashCode();
|
|
}
|
|
|
|
partial class Classement : INotifyPropertyChanged
|
|
{
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
public void QuandProprieteChangee([CallerMemberName] string? nomPropriete = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nomPropriete));
|
|
}
|
|
|
|
private static Dictionary<string, IComparer<Enfant>> Tris => new Dictionary<string, IComparer<Enfant>> {
|
|
{ "Nom", Comparer<Enfant>.Create((enfant1, enfant2) => string.Compare(enfant1.Joueur.Nom, enfant2.Joueur.Nom)) },
|
|
{ "CoupMoyen", Comparer<Enfant>.Create((enfant1, enfant2) => enfant2.NbCoupMoyen - enfant1.NbCoupMoyen) },
|
|
{ "Gagnee", Comparer<Enfant>.Create((enfant1, enfant2) => enfant2.PartieGagnee - enfant1.PartieGagnee) },
|
|
{ "Perdue", Comparer<Enfant>.Create((enfant1, enfant2) => enfant2.PartiePerdue - enfant1.PartiePerdue) },
|
|
{ "Egalite", Comparer<Enfant>.Create((enfant1, enfant2) => enfant2.PartieEgalite - enfant1.PartieEgalite) },
|
|
};
|
|
|
|
private string typeTri = "CoupMoyen";
|
|
public string TypeTri {
|
|
get
|
|
{
|
|
return typeTri;
|
|
}
|
|
set
|
|
{
|
|
typeTri = value;
|
|
QuandProprieteChangee(nameof(Enfants));
|
|
}
|
|
}
|
|
|
|
private bool inverser = false;
|
|
public bool Inverser
|
|
{
|
|
get
|
|
{
|
|
return inverser;
|
|
}
|
|
set
|
|
{
|
|
inverser = value;
|
|
QuandProprieteChangee(nameof(Enfants));
|
|
}
|
|
}
|
|
|
|
private IRegles regles = new ReglesClassiques();
|
|
public IRegles Regles
|
|
{
|
|
get
|
|
{
|
|
return regles;
|
|
}
|
|
set
|
|
{
|
|
regles = value;
|
|
QuandProprieteChangee(nameof(Enfants));
|
|
}
|
|
}
|
|
|
|
public IComparer<Enfant> Tri => Tris.GetValueOrDefault(TypeTri) ?? Tris["CoupMoyen"];
|
|
public IEnumerable<Enfant> Enfants => Inverser ?
|
|
MauiProgram.Manageur.Joueurs.Select(joueur => new Enfant(joueur, this)).Order(Tri).Reverse() :
|
|
MauiProgram.Manageur.Joueurs.Select(joueur => new Enfant(joueur, this)).Order(Tri);
|
|
}
|
|
|
|
public partial class ClassementPage : ContentPage
|
|
{
|
|
public ClassementPage()
|
|
{
|
|
InitializeComponent();
|
|
|
|
NavigationPage.SetHasNavigationBar(this, false);
|
|
|
|
BindingContext = new Classement();
|
|
}
|
|
|
|
private void QuandBoutonPresse(object sender, EventArgs e)
|
|
{
|
|
Classement classement = (Classement)BindingContext;
|
|
|
|
if (sender == ReglesClassiques)
|
|
{
|
|
classement.Regles = new ReglesClassiques();
|
|
return;
|
|
}
|
|
|
|
if (sender == ReglesDifficiles)
|
|
{
|
|
classement.Regles = new ReglesDifficiles();
|
|
return;
|
|
}
|
|
|
|
if (classement.TypeTri == nameof(sender)) {
|
|
classement.Inverser = !classement.Inverser;
|
|
return;
|
|
}
|
|
|
|
classement.Inverser = false;
|
|
classement.TypeTri = nameof(sender);
|
|
}
|
|
}
|
|
} |