Correction du classement
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
f6f50ffd73
commit
b9dbd266bf
@ -1,22 +1,22 @@
|
||||
namespace MauiSpark.Pages;
|
||||
|
||||
public partial class AccueilPage : ContentPage
|
||||
{
|
||||
public AccueilPage()
|
||||
{
|
||||
NavigationPage.SetHasBackButton(this, false);
|
||||
NavigationPage.SetHasNavigationBar(this, false);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void QuandJouerClique(Object? sender, EventArgs e)
|
||||
{
|
||||
Navigation.PushAsync(new ModePage());
|
||||
namespace MauiSpark.Pages;
|
||||
|
||||
public partial class AccueilPage : ContentPage
|
||||
{
|
||||
public AccueilPage()
|
||||
{
|
||||
NavigationPage.SetHasBackButton(this, false);
|
||||
NavigationPage.SetHasNavigationBar(this, false);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void QuandJouerClique(Object? sender, EventArgs e)
|
||||
{
|
||||
Navigation.PushAsync(new ModePage());
|
||||
}
|
||||
|
||||
private void QuandReprendreClique(Object? sender, EventArgs e)
|
||||
{
|
||||
Navigation.PushAsync(new ReprendrePage());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:pages="clr-namespace:MauiSpark.Pages"
|
||||
x:Class="MauiSpark.Pages.ClassementPage"
|
||||
xmlns:vues="clr-namespace:MauiSpark.Vues"
|
||||
Title="ClassementPage">
|
||||
|
||||
<ScrollView>
|
||||
<VerticalStackLayout>
|
||||
<FlexLayout Direction="Row" JustifyContent="SpaceAround" AlignContent="Center" VerticalOptions="Center" Margin="10, 50" >
|
||||
<Image Source="star.png" WidthRequest="100" HorizontalOptions="End" VerticalOptions="Center" Margin="0"/>
|
||||
<vues:TitreVue Texte="classement"/>
|
||||
<Image Grid.Row="1" Source="star.png" WidthRequest="100" HorizontalOptions="Start" VerticalOptions="Center" Margin="0"/>
|
||||
</FlexLayout>
|
||||
|
||||
<Grid RowDefinitions="*" ColumnDefinitions="*">
|
||||
<Button x:Name="ReglesClassiques" Text="ReglesClassiques" Style="{StaticResource ButtonClassementRegle}" Clicked="QuandBoutonPresse"/>
|
||||
</Grid>
|
||||
|
||||
<Border Margin="20" StrokeThickness="2" StrokeShape="RoundRectangle 10">
|
||||
<Grid ColumnDefinitions="*, *, *, *, *, *, *" ColumnSpacing="10" >
|
||||
<Button Margin="5" Grid.Column="0" Text="Place" Style="{StaticResource ButtonClassement}" VerticalOptions="Center" HorizontalOptions="Center" Clicked="QuandBoutonPresse"/>
|
||||
<Button x:Name="Nom" Margin="5" Grid.Column="1" Text="Nom" Style="{StaticResource ButtonClassement}" VerticalOptions="Center" HorizontalOptions="Center" Clicked="QuandBoutonPresse"/>
|
||||
<Button x:Name="CoupMoyen" Margin="5" Grid.Column="3" Text="Coup moyen" Style="{StaticResource ButtonClassement}" VerticalOptions="Center" HorizontalOptions="Center" Clicked="QuandBoutonPresse"/>
|
||||
<Button x:Name="Gagnee" Margin="5" Grid.Column="4" Text="Partie gagnée" Style="{StaticResource ButtonClassement}" VerticalOptions="Center" HorizontalOptions="Center" Clicked="QuandBoutonPresse"/>
|
||||
<Button x:Name="Perdue" Margin="5" Grid.Column="5" Text="Partie perdue" Style="{StaticResource ButtonClassement}" VerticalOptions="Center" HorizontalOptions="Center" Clicked="QuandBoutonPresse"/>
|
||||
<Button x:Name="Egalite" Margin="5" Grid.Column="6" Text="Partie égalité" Style="{StaticResource ButtonClassement}" VerticalOptions="Center" HorizontalOptions="Center" Clicked="QuandBoutonPresse"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<StackLayout BindableLayout.ItemsSource="{Binding Enfants}">
|
||||
<BindableLayout.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border Margin="20, 0" StrokeThickness="2" StrokeShape="RoundRectangle 10" Padding="0,20">
|
||||
<Grid ColumnDefinitions="*, *, *, *, *, *, *">
|
||||
<Label Grid.Column="0" Text="{Binding Place}" VerticalOptions="Center" HorizontalOptions="Center" Style="{StaticResource TexteFrame}" />
|
||||
<Label Grid.Column="1" Text="{Binding Joueur}" VerticalOptions="Center" HorizontalOptions="Center" Style="{StaticResource TexteFrame}" />
|
||||
<Label Grid.Column="3" Text="{Binding NbCoupMoyen}" VerticalOptions="Center" HorizontalOptions="Center" Style="{StaticResource TexteFrame}" />
|
||||
<Label Grid.Column="4" Text="{Binding PartieGagnee}" VerticalOptions="Center" HorizontalOptions="Center" Style="{StaticResource TexteFrame}" />
|
||||
<Label Grid.Column="5" Text="{Binding PartiePerdue}" VerticalOptions="Center" HorizontalOptions="Center" Style="{StaticResource TexteFrame}" />
|
||||
<Label Grid.Column="6" Text="{Binding PartieEgalite}" VerticalOptions="Center" HorizontalOptions="Center" Style="{StaticResource TexteFrame}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</BindableLayout.ItemTemplate>
|
||||
</StackLayout>
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
|
||||
</ContentPage>
|
@ -0,0 +1,128 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
partial class Classement : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public void QuandProprieteChangee([CallerMemberName] string? nomPropriete = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nomPropriete));
|
||||
}
|
||||
|
||||
private 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 (classement.TypeTri == nameof(sender)) {
|
||||
classement.Inverser = !classement.Inverser;
|
||||
return;
|
||||
}
|
||||
|
||||
classement.Inverser = false;
|
||||
classement.TypeTri = nameof(sender);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:pages="clr-namespace:MauiSpark.Pages"
|
||||
x:Class="MauiSpark.Pages.TableauScore"
|
||||
xmlns:vues="clr-namespace:MauiSpark.Vues"
|
||||
Title="TableauScore">
|
||||
|
||||
<ScrollView>
|
||||
<VerticalStackLayout>
|
||||
<FlexLayout Direction="Row" JustifyContent="SpaceAround" AlignContent="Center" VerticalOptions="Center" Margin="10, 50" >
|
||||
<Image Source="star.png" WidthRequest="100" HorizontalOptions="End" VerticalOptions="Center" Margin="0"/>
|
||||
<vues:TitreVue Texte="classement"/>
|
||||
<Image Grid.Row="1" Source="star.png" WidthRequest="100" HorizontalOptions="Start" VerticalOptions="Center" Margin="0"/>
|
||||
</FlexLayout>
|
||||
<Button Text="Régles Classique" Clicked="QuandButtonRegleClassiqueClique" Style="{StaticResource ButtonClassementRegle}" ></Button>
|
||||
<Frame Margin="20" >
|
||||
<Grid ColumnDefinitions="auto,*,auto,auto,auto,auto" ColumnSpacing="10" >
|
||||
<Button Margin="5" Grid.Column="0" Text="RANK" Style="{StaticResource ButtonClassement}" VerticalOptions="Center"></Button>
|
||||
<Button Margin="5" Grid.Column="1" Text="PSEUDO" Style="{StaticResource ButtonClassement}" VerticalOptions="Center" HorizontalOptions="Start" Clicked="QuandButtonClassementClique" ></Button>
|
||||
<Button Margin="5" Grid.Column="2" Text="Coût Moyen" Style="{StaticResource ButtonClassement}" VerticalOptions="Center" Clicked="QuandButtonClassementClique" ></Button>
|
||||
<Button Margin="5" Grid.Column="3" Text="Partie Gagnée" Style="{StaticResource ButtonClassement}" VerticalOptions="Center" Clicked="QuandButtonClassementClique" ></Button>
|
||||
<Button Margin="5" Grid.Column="4" Text="Partie Perdue" Style="{StaticResource ButtonClassement}" VerticalOptions="Center" Clicked="QuandButtonClassementClique" ></Button>
|
||||
<Button Margin="5" Grid.Column="5" Text="Partie Egalité" Style="{StaticResource ButtonClassement}" VerticalOptions="Center" Clicked="QuandButtonClassementClique" ></Button>
|
||||
</Grid>
|
||||
</Frame>
|
||||
<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,160,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 NbCoupMoyen}" Margin="55,20,120,20" Style="{StaticResource TexteFrame}" />
|
||||
<Label Grid.Column="3" Text="{Binding PartieGagnee}" Margin="55,20,100,20" Style="{StaticResource TexteFrame}" />
|
||||
<Label Grid.Column="4" Text="{Binding PartiePerdue}" Margin="55,20,100,20" Style="{StaticResource TexteFrame}" />
|
||||
<Label Grid.Column="5" Text="{Binding PartieEgalite}" Margin="55,20,100,20" Style="{StaticResource TexteFrame}" />
|
||||
|
||||
</Grid>
|
||||
</Frame>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</VerticalStackLayout>
|
||||
</ScrollView>
|
||||
|
||||
</ContentPage>
|
@ -1,140 +0,0 @@
|
||||
using CoreLibrary.Joueurs;
|
||||
using CoreLibrary.Manageurs;
|
||||
using CoreLibrary.Statistiques;
|
||||
using System.Linq;
|
||||
using CoreLibrary.Regles;
|
||||
|
||||
namespace MauiSpark.Pages
|
||||
{
|
||||
public partial class TableauScore : ContentPage
|
||||
{
|
||||
private IRegles regles = new ReglesClassiques();
|
||||
public TableauScore()
|
||||
{
|
||||
NavigationPage.SetHasNavigationBar(this, false);
|
||||
InitializeComponent();
|
||||
QuandButtonClassementClique(null, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void QuandButtonRegleClassiqueClique(object sender, EventArgs e)
|
||||
{
|
||||
regles = new ReglesClassiques();
|
||||
QuandButtonClassementClique(null, EventArgs.Empty);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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 double NbCoupMoyen
|
||||
{
|
||||
get
|
||||
{
|
||||
int totalParties = PartieEgalite + PartiePerdue + PartieGagnee;
|
||||
return totalParties == 0 ? 0 : joueur.Statistique(regles, Statistique.CoupJoue) / totalParties;
|
||||
}
|
||||
}
|
||||
|
||||
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 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