Fin du classement et application maui 100%
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
4fc193ce37
commit
15e83989a7
@ -0,0 +1,125 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"Nom": "Céleste",
|
||||||
|
"statistiques": [
|
||||||
|
{
|
||||||
|
"Key": {
|
||||||
|
"Item1": {
|
||||||
|
"__type": "ReglesClassiques:#CoreLibrary.Regles"
|
||||||
|
},
|
||||||
|
"Item2": 0
|
||||||
|
},
|
||||||
|
"Value": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Key": {
|
||||||
|
"Item1": {
|
||||||
|
"__type": "ReglesClassiques:#CoreLibrary.Regles"
|
||||||
|
},
|
||||||
|
"Item2": 1
|
||||||
|
},
|
||||||
|
"Value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Key": {
|
||||||
|
"Item1": {
|
||||||
|
"__type": "ReglesClassiques:#CoreLibrary.Regles"
|
||||||
|
},
|
||||||
|
"Item2": 2
|
||||||
|
},
|
||||||
|
"Value": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Key": {
|
||||||
|
"Item1": {
|
||||||
|
"__type": "ReglesClassiques:#CoreLibrary.Regles"
|
||||||
|
},
|
||||||
|
"Item2": 3
|
||||||
|
},
|
||||||
|
"Value": 5
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Nom": "Pauline",
|
||||||
|
"statistiques": [
|
||||||
|
{
|
||||||
|
"Key": {
|
||||||
|
"Item1": {
|
||||||
|
"__type": "ReglesClassiques:#CoreLibrary.Regles"
|
||||||
|
},
|
||||||
|
"Item2": 0
|
||||||
|
},
|
||||||
|
"Value": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Key": {
|
||||||
|
"Item1": {
|
||||||
|
"__type": "ReglesClassiques:#CoreLibrary.Regles"
|
||||||
|
},
|
||||||
|
"Item2": 1
|
||||||
|
},
|
||||||
|
"Value": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Key": {
|
||||||
|
"Item1": {
|
||||||
|
"__type": "ReglesClassiques:#CoreLibrary.Regles"
|
||||||
|
},
|
||||||
|
"Item2": 2
|
||||||
|
},
|
||||||
|
"Value": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Key": {
|
||||||
|
"Item1": {
|
||||||
|
"__type": "ReglesClassiques:#CoreLibrary.Regles"
|
||||||
|
},
|
||||||
|
"Item2": 3
|
||||||
|
},
|
||||||
|
"Value": 10
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Nom": "Camille",
|
||||||
|
"statistiques": [
|
||||||
|
{
|
||||||
|
"Key": {
|
||||||
|
"Item1": {
|
||||||
|
"__type": "ReglesClassiques:#CoreLibrary.Regles"
|
||||||
|
},
|
||||||
|
"Item2": 0
|
||||||
|
},
|
||||||
|
"Value": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Key": {
|
||||||
|
"Item1": {
|
||||||
|
"__type": "ReglesClassiques:#CoreLibrary.Regles"
|
||||||
|
},
|
||||||
|
"Item2": 1
|
||||||
|
},
|
||||||
|
"Value": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Key": {
|
||||||
|
"Item1": {
|
||||||
|
"__type": "ReglesClassiques:#CoreLibrary.Regles"
|
||||||
|
},
|
||||||
|
"Item2": 2
|
||||||
|
},
|
||||||
|
"Value": 6
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Key": {
|
||||||
|
"Item1": {
|
||||||
|
"__type": "ReglesClassiques:#CoreLibrary.Regles"
|
||||||
|
},
|
||||||
|
"Item2": 3
|
||||||
|
},
|
||||||
|
"Value": 50
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
File diff suppressed because it is too large
Load Diff
@ -1,139 +1,137 @@
|
|||||||
using CoreLibrary.Joueurs;
|
using CoreLibrary.Joueurs;
|
||||||
using CoreLibrary.Statistiques;
|
using CoreLibrary.Statistiques;
|
||||||
using CoreLibrary.Regles;
|
using CoreLibrary.Regles;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace MauiSpark.Pages
|
namespace MauiSpark.Pages
|
||||||
{
|
{
|
||||||
partial class Enfant
|
partial class Enfant
|
||||||
{
|
{
|
||||||
private readonly Classement classement;
|
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 Joueur Joueur { get; set; }
|
public IEnumerable<int> Statistiques => Enum.GetValues<Statistique>()
|
||||||
public int Place => classement.Enfants.ToList().IndexOf(this) + 1;
|
.Select(statistique => Joueur.Statistique(classement.Regles, statistique));
|
||||||
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 IEnumerable<string> Objets => new List<string>([$"{Place}", Joueur.Nom])
|
||||||
public int PartiePerdue => Joueur.Statistique(classement.Regles, Statistique.PartiePerdue);
|
.Concat(Statistiques.Select(statistique => $"{statistique}"));
|
||||||
public int PartieEgalite => Joueur.Statistique(classement.Regles, Statistique.PartieEgalite);
|
|
||||||
|
public Enfant(Joueur joueur, Classement classement)
|
||||||
public Enfant(Joueur joueur, Classement classement)
|
{
|
||||||
{
|
this.classement = classement;
|
||||||
this.classement = classement;
|
Joueur = joueur;
|
||||||
Joueur = joueur;
|
}
|
||||||
}
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
public override bool Equals(object? obj)
|
{
|
||||||
{
|
if (obj == null || obj is not Enfant)
|
||||||
if (obj == null || obj is not Enfant)
|
return false;
|
||||||
return false;
|
|
||||||
|
return Joueur == ((Enfant)obj).Joueur;
|
||||||
return ((Enfant)obj).Joueur.Equals(Joueur);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public override int GetHashCode() => Joueur.GetHashCode();
|
public override int GetHashCode() => Joueur.GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
partial class Classement : INotifyPropertyChanged
|
partial class Classement : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
public event PropertyChangedEventHandler? PropertyChanged;
|
|
||||||
|
public event PropertyChangedEventHandler? PropertyChanged;
|
||||||
public void QuandProprieteChangee([CallerMemberName] string? nomPropriete = null)
|
|
||||||
{
|
public void QuandProprieteChangee([CallerMemberName] string? propriete = null) =>
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nomPropriete));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propriete));
|
||||||
}
|
|
||||||
|
private int indiceRegles = 0;
|
||||||
private static Dictionary<string, IComparer<Enfant>> Tris => new Dictionary<string, IComparer<Enfant>> {
|
public IRegles Regles => ClassementPage.ToutesRegles.ElementAt(indiceRegles);
|
||||||
{ "Nom", Comparer<Enfant>.Create((enfant1, enfant2) => string.Compare(enfant1.Joueur.Nom, enfant2.Joueur.Nom)) },
|
|
||||||
{ "CoupMoyen", Comparer<Enfant>.Create((enfant1, enfant2) => enfant2.NbCoupMoyen - enfant1.NbCoupMoyen) },
|
private Statistique statistique = Enum.GetValues<Statistique>().First();
|
||||||
{ "Gagnee", Comparer<Enfant>.Create((enfant1, enfant2) => enfant2.PartieGagnee - enfant1.PartieGagnee) },
|
public Statistique Statistique
|
||||||
{ "Perdue", Comparer<Enfant>.Create((enfant1, enfant2) => enfant2.PartiePerdue - enfant1.PartiePerdue) },
|
{
|
||||||
{ "Egalite", Comparer<Enfant>.Create((enfant1, enfant2) => enfant2.PartieEgalite - enfant1.PartieEgalite) },
|
get => statistique;
|
||||||
};
|
set
|
||||||
|
{
|
||||||
private string typeTri = "CoupMoyen";
|
statistique = value;
|
||||||
public string TypeTri {
|
QuandProprieteChangee(nameof(Enfants));
|
||||||
get
|
}
|
||||||
{
|
}
|
||||||
return typeTri;
|
|
||||||
}
|
private bool inverser = true;
|
||||||
set
|
public bool Inverser {
|
||||||
{
|
get => inverser;
|
||||||
typeTri = value;
|
set
|
||||||
QuandProprieteChangee(nameof(Enfants));
|
{
|
||||||
}
|
inverser = value;
|
||||||
}
|
QuandProprieteChangee(nameof(Enfants));
|
||||||
|
}
|
||||||
private bool inverser = false;
|
}
|
||||||
public bool Inverser
|
|
||||||
{
|
public IEnumerable<string> Titres => new List<string>(["Place", "Nom"]).Concat(
|
||||||
get
|
Enum.GetValues<Statistique>().Select(
|
||||||
{
|
statistique => string.Concat((Enum.GetName(typeof(Statistique), statistique) ?? "").Select(
|
||||||
return inverser;
|
(lettre, indice) => indice > 0 && char.IsUpper(lettre) ? $" {lettre}" : $"{lettre}")
|
||||||
}
|
)
|
||||||
set
|
)
|
||||||
{
|
);
|
||||||
inverser = value;
|
|
||||||
QuandProprieteChangee(nameof(Enfants));
|
public IEnumerable<Enfant> Enfants => Inverser ?
|
||||||
}
|
MauiProgram.Manageur.Joueurs
|
||||||
}
|
.OrderBy(joueur => joueur.Statistique(Regles, Statistique))
|
||||||
|
.Select(joueur => new Enfant(joueur, this)).Reverse() :
|
||||||
private IRegles regles = new ReglesClassiques();
|
MauiProgram.Manageur.Joueurs
|
||||||
public IRegles Regles
|
.OrderBy(joueur => joueur.Statistique(Regles, Statistique))
|
||||||
{
|
.Select(joueur => new Enfant(joueur, this));
|
||||||
get
|
|
||||||
{
|
public void IncrementerRegles(int valeur)
|
||||||
return regles;
|
{
|
||||||
}
|
if ((indiceRegles += valeur) < 0)
|
||||||
set
|
indiceRegles = ClassementPage.ToutesRegles.Count() - 1;
|
||||||
{
|
else if (indiceRegles >= ClassementPage.ToutesRegles.Count())
|
||||||
regles = value;
|
indiceRegles = 0;
|
||||||
QuandProprieteChangee(nameof(Enfants));
|
|
||||||
}
|
QuandProprieteChangee(nameof(Regles));
|
||||||
}
|
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() :
|
public partial class ClassementPage : ContentPage
|
||||||
MauiProgram.Manageur.Joueurs.Select(joueur => new Enfant(joueur, this)).Order(Tri);
|
{
|
||||||
}
|
public static IEnumerable<IRegles> ToutesRegles => typeof(IRegles).Assembly.GetTypes()
|
||||||
|
.Where(type => typeof(IRegles).IsAssignableFrom(type) && type.IsClass)
|
||||||
public partial class ClassementPage : ContentPage
|
.Select(type => (Activator.CreateInstance(type) as IRegles)!)
|
||||||
{
|
.OrderBy(regles => regles.Indice);
|
||||||
public ClassementPage()
|
|
||||||
{
|
public ClassementPage()
|
||||||
InitializeComponent();
|
{
|
||||||
|
InitializeComponent();
|
||||||
NavigationPage.SetHasNavigationBar(this, false);
|
|
||||||
|
NavigationPage.SetHasNavigationBar(this, false);
|
||||||
BindingContext = new Classement();
|
|
||||||
}
|
BindingContext = new Classement();
|
||||||
|
}
|
||||||
private void QuandBoutonPresse(object sender, EventArgs e)
|
|
||||||
{
|
public void ChangerReglesPresse(object sender, EventArgs e)
|
||||||
Classement classement = (Classement)BindingContext;
|
{
|
||||||
|
((Classement)BindingContext).IncrementerRegles(sender == DiminuerRegles ? -1 : 1);
|
||||||
if (sender == ReglesClassiques)
|
}
|
||||||
{
|
|
||||||
classement.Regles = new ReglesClassiques();
|
public void StatistiquePressee(object sender, EventArgs e)
|
||||||
return;
|
{
|
||||||
}
|
if (sender is not Label || !Enum.IsDefined(typeof(Statistique), ((Label)sender).Text.Replace(" ", "")))
|
||||||
|
return;
|
||||||
if (sender == ReglesDifficiles)
|
|
||||||
{
|
Statistique statistique = Enum.Parse<Statistique>(((Label)sender).Text.Replace(" ", ""));
|
||||||
classement.Regles = new ReglesDifficiles();
|
Classement classement = (Classement)BindingContext;
|
||||||
return;
|
|
||||||
}
|
if (classement.Statistique == statistique)
|
||||||
|
{
|
||||||
if (classement.TypeTri == nameof(sender)) {
|
classement.Inverser = !classement.Inverser;
|
||||||
classement.Inverser = !classement.Inverser;
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
classement.Inverser = true;
|
||||||
classement.Inverser = false;
|
classement.Statistique = statistique;
|
||||||
classement.TypeTri = nameof(sender);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
x:Class="MauiSpark.Vues.ModeVue"
|
||||||
|
x:Name="modeVue">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
Text="{Binding Regles.Nom, Source={x:Reference modeVue}}"
|
||||||
|
Clicked="QuandReglesPresse"
|
||||||
|
Margin="0, 50"/>
|
||||||
|
</ContentView>
|
@ -0,0 +1,32 @@
|
|||||||
|
using CoreLibrary;
|
||||||
|
using CoreLibrary.Regles;
|
||||||
|
using MauiSpark.Pages;
|
||||||
|
|
||||||
|
namespace MauiSpark.Vues;
|
||||||
|
|
||||||
|
public partial class ModeVue : ContentView
|
||||||
|
{
|
||||||
|
public static readonly BindableProperty ReglesProperty = BindableProperty.Create(nameof(Regles), typeof(IRegles), typeof(ModeVue), null);
|
||||||
|
|
||||||
|
public IRegles Regles
|
||||||
|
{
|
||||||
|
get => (IRegles)GetValue(ReglesProperty);
|
||||||
|
set => SetValue(ReglesProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModeVue()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void QuandReglesPresse(Object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Partie partie = MauiProgram.Manageur.NouvellePartie(Regles);
|
||||||
|
|
||||||
|
partie.PartieDemanderJoueur += new ConnexionPage().QuandDemanderNom;
|
||||||
|
partie.PartiePartieTerminee += new VictoirePage().QuandPartieTerminee;
|
||||||
|
partie.PartieNouveauTour += new PlateauPage().QuandNouveauTour;
|
||||||
|
|
||||||
|
partie.Jouer();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue