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.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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
public Joueur Joueur { get; set; }
|
||||
public int Place => classement.Enfants.ToList().IndexOf(this) + 1;
|
||||
public IEnumerable<int> Statistiques => Enum.GetValues<Statistique>()
|
||||
.Select(statistique => Joueur.Statistique(classement.Regles, statistique));
|
||||
|
||||
public IEnumerable<string> Objets => new List<string>([$"{Place}", Joueur.Nom])
|
||||
.Concat(Statistiques.Select(statistique => $"{statistique}"));
|
||||
|
||||
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 Joueur == ((Enfant)obj).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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
partial class Classement : INotifyPropertyChanged
|
||||
{
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public void QuandProprieteChangee([CallerMemberName] string? propriete = null) =>
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propriete));
|
||||
|
||||
private int indiceRegles = 0;
|
||||
public IRegles Regles => ClassementPage.ToutesRegles.ElementAt(indiceRegles);
|
||||
|
||||
private Statistique statistique = Enum.GetValues<Statistique>().First();
|
||||
public Statistique Statistique
|
||||
{
|
||||
get => statistique;
|
||||
set
|
||||
{
|
||||
statistique = value;
|
||||
QuandProprieteChangee(nameof(Enfants));
|
||||
}
|
||||
}
|
||||
|
||||
private bool inverser = true;
|
||||
public bool Inverser {
|
||||
get => inverser;
|
||||
set
|
||||
{
|
||||
inverser = value;
|
||||
QuandProprieteChangee(nameof(Enfants));
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> Titres => new List<string>(["Place", "Nom"]).Concat(
|
||||
Enum.GetValues<Statistique>().Select(
|
||||
statistique => string.Concat((Enum.GetName(typeof(Statistique), statistique) ?? "").Select(
|
||||
(lettre, indice) => indice > 0 && char.IsUpper(lettre) ? $" {lettre}" : $"{lettre}")
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
public IEnumerable<Enfant> Enfants => Inverser ?
|
||||
MauiProgram.Manageur.Joueurs
|
||||
.OrderBy(joueur => joueur.Statistique(Regles, Statistique))
|
||||
.Select(joueur => new Enfant(joueur, this)).Reverse() :
|
||||
MauiProgram.Manageur.Joueurs
|
||||
.OrderBy(joueur => joueur.Statistique(Regles, Statistique))
|
||||
.Select(joueur => new Enfant(joueur, this));
|
||||
|
||||
public void IncrementerRegles(int valeur)
|
||||
{
|
||||
if ((indiceRegles += valeur) < 0)
|
||||
indiceRegles = ClassementPage.ToutesRegles.Count() - 1;
|
||||
else if (indiceRegles >= ClassementPage.ToutesRegles.Count())
|
||||
indiceRegles = 0;
|
||||
|
||||
QuandProprieteChangee(nameof(Regles));
|
||||
QuandProprieteChangee(nameof(Enfants));
|
||||
}
|
||||
}
|
||||
|
||||
public partial class ClassementPage : ContentPage
|
||||
{
|
||||
public static IEnumerable<IRegles> ToutesRegles => typeof(IRegles).Assembly.GetTypes()
|
||||
.Where(type => typeof(IRegles).IsAssignableFrom(type) && type.IsClass)
|
||||
.Select(type => (Activator.CreateInstance(type) as IRegles)!)
|
||||
.OrderBy(regles => regles.Indice);
|
||||
|
||||
public ClassementPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
NavigationPage.SetHasNavigationBar(this, false);
|
||||
|
||||
BindingContext = new Classement();
|
||||
}
|
||||
|
||||
public void ChangerReglesPresse(object sender, EventArgs e)
|
||||
{
|
||||
((Classement)BindingContext).IncrementerRegles(sender == DiminuerRegles ? -1 : 1);
|
||||
}
|
||||
|
||||
public void StatistiquePressee(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is not Label || !Enum.IsDefined(typeof(Statistique), ((Label)sender).Text.Replace(" ", "")))
|
||||
return;
|
||||
|
||||
Statistique statistique = Enum.Parse<Statistique>(((Label)sender).Text.Replace(" ", ""));
|
||||
Classement classement = (Classement)BindingContext;
|
||||
|
||||
if (classement.Statistique == statistique)
|
||||
{
|
||||
classement.Inverser = !classement.Inverser;
|
||||
return;
|
||||
}
|
||||
|
||||
classement.Inverser = true;
|
||||
classement.Statistique = statistique;
|
||||
}
|
||||
}
|
||||
}
|
@ -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