Le classement ne marche pas encore.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
1baca9f63a
commit
57f2cca38f
@ -1,11 +1,141 @@
|
|||||||
namespace MauiSpark.Pages;
|
using CoreLibrary.Joueurs;
|
||||||
|
using CoreLibrary.Manageurs;
|
||||||
|
using CoreLibrary.Statistiques;
|
||||||
|
using System.Linq;
|
||||||
|
using CoreLibrary.Regles;
|
||||||
|
|
||||||
public partial class TableauScore : ContentPage
|
namespace MauiSpark.Pages
|
||||||
{
|
{
|
||||||
public TableauScore()
|
public partial class TableauScore : ContentPage
|
||||||
{
|
{
|
||||||
NavigationPage.SetHasNavigationBar(this, false);
|
private IRegles regles = new ReglesClassiques();
|
||||||
|
public TableauScore()
|
||||||
|
{
|
||||||
|
NavigationPage.SetHasNavigationBar(this, false);
|
||||||
|
InitializeComponent();
|
||||||
|
QuandButtonClassementClique(null, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
InitializeComponent();
|
private void QuandButtonRegleClassiqueClique(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
regles = new ReglesClassiques();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int NbClique { get; set; } = 0;
|
||||||
|
|
||||||
|
public IEnumerable<Classement> GetClassement(Func<Joueur, object> critereTri)
|
||||||
|
{
|
||||||
|
IEnumerable<Joueur> joueursTries = NbClique % 2 == 0
|
||||||
|
? MauiProgram.Manageur.joueurs.OrderBy(critereTri)
|
||||||
|
: MauiProgram.Manageur.joueurs.OrderByDescending(critereTri);
|
||||||
|
|
||||||
|
NbClique++;
|
||||||
|
|
||||||
|
return joueursTries.Select(joueur => new Classement(joueur, MauiProgram.Manageur, critereTri, regles));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void QuandButtonClassementClique(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Button button = sender as Button;
|
||||||
|
string nom = button?.Text ?? string.Empty;
|
||||||
|
Func<Joueur, object> critereTri;
|
||||||
|
|
||||||
|
switch (nom)
|
||||||
|
{
|
||||||
|
case "PSEUDO":
|
||||||
|
critereTri = joueur => joueur.Nom;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Cout Moyen":
|
||||||
|
critereTri = joueur =>
|
||||||
|
{
|
||||||
|
int totalParties = joueur.Statistique(regles, Statistique.PartiePerdue) +
|
||||||
|
joueur.Statistique(regles, Statistique.PartieGagnee) +
|
||||||
|
joueur.Statistique(regles, Statistique.PartieEgalite);
|
||||||
|
return totalParties == 0 ? 0 : (double)joueur.Statistique(regles, Statistique.CoupJoue) / totalParties;
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Partie Gagnée":
|
||||||
|
critereTri = joueur => joueur.Statistique(regles, Statistique.PartieGagnee);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Partie Perdue":
|
||||||
|
critereTri = joueur => joueur.Statistique(regles, Statistique.PartiePerdue);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Partie Égalité":
|
||||||
|
critereTri = joueur => joueur.Statistique(regles, Statistique.PartieEgalite);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
critereTri = joueur =>
|
||||||
|
{
|
||||||
|
int totalParties = joueur.Statistique(regles, Statistique.PartiePerdue) +
|
||||||
|
joueur.Statistique(regles, Statistique.PartieGagnee) +
|
||||||
|
joueur.Statistique(regles, Statistique.PartieEgalite);
|
||||||
|
return totalParties == 0 ? 0 : (double)joueur.Statistique(regles, Statistique.CoupJoue) / totalParties;
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
BindingContext = GetClassement(critereTri);
|
||||||
|
int a = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Classement
|
||||||
|
{
|
||||||
|
private IRegles regles;
|
||||||
|
private Manageur manageur;
|
||||||
|
private Joueur joueur;
|
||||||
|
private Func<Joueur, object> critereTri;
|
||||||
|
|
||||||
|
public Joueur Joueur
|
||||||
|
{
|
||||||
|
get => joueur;
|
||||||
|
private set => joueur = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Place
|
||||||
|
{
|
||||||
|
get => manageur.joueurs
|
||||||
|
.OrderBy(critereTri)
|
||||||
|
.ToList()
|
||||||
|
.IndexOf(joueur) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int PartieGagnee
|
||||||
|
{
|
||||||
|
get => joueur.Statistique(regles, Statistique.PartieGagnee);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int PartiePerdue
|
||||||
|
{
|
||||||
|
get => joueur.Statistique(regles, Statistique.PartiePerdue);
|
||||||
|
}
|
||||||
|
public int PartieEgalite
|
||||||
|
{
|
||||||
|
get => joueur.Statistique(regles, Statistique.PartieEgalite);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double NbCoupMoyen
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
int totalParties = joueur.Statistique(regles, Statistique.PartiePerdue) +
|
||||||
|
joueur.Statistique(regles, Statistique.PartieGagnee) +
|
||||||
|
joueur.Statistique(regles, Statistique.PartieEgalite);
|
||||||
|
return totalParties == 0 ? 0 : (double)joueur.Statistique(regles, Statistique.CoupJoue) / totalParties;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Classement(Joueur joueur, Manageur manageur, Func<Joueur, object> critereTri, IRegles regles)
|
||||||
|
{
|
||||||
|
this.manageur = manageur;
|
||||||
|
this.joueur = joueur;
|
||||||
|
this.critereTri = critereTri;
|
||||||
|
this.regles = regles;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue