Fusion du classement

master
Céleste BARBOSA 11 months ago
commit f6f50ffd73

@ -47,8 +47,7 @@ namespace CoreLibrary.Joueurs
public override string ToString() => Nom;
public int Statistique(IRegles regles, Statistique statistique) =>
statistiques.GetValueOrDefault((regles, statistique), 0);
public int Statistique(IRegles regles, Statistique statistique) => statistiques.GetValueOrDefault((regles, statistique),0);
public void IncrementerStatistique(IRegles regles, Statistique statistique) =>
statistiques[(regles, statistique)] = Statistique(regles, statistique) + 1;

@ -79,7 +79,6 @@ namespace CoreLibrary.Manageurs
{
DemanderJoueur(perdant).IncrementerStatistique(partie.Regles, Statistique.PartiePerdue);
}
Sauvegarder();
};
}

@ -26,6 +26,7 @@ namespace CoreLibrary.Persistance
return [];
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), nomDossier));
var directory = Directory.GetCurrentDirectory();
if (!File.Exists(fichier))
return [];

@ -9,5 +9,16 @@ namespace CoreLibrary.Regles
public int NbJoueurs => 2;
public int NbTour => 12;
public int TailleCode => 4;
public override bool Equals(object? obj)
{
if (obj == null || obj is not ReglesClassiques) return false;
return true;
}
public override int GetHashCode()
{
return HashCode.Combine(Nom, NbJoueurs, NbTour, TailleCode);
}
}
}

@ -1,7 +1,6 @@
<?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:Views="clr-namespace:MauiSpark.Views"
x:Class="MauiSpark.Pages.ConnexionPage"
xmlns:vues="clr-namespace:MauiSpark.Vues"
Title="Connexion">

@ -112,7 +112,7 @@
<BoxView Grid.Row="1" Grid.ColumnSpan="6" HeightRequest="1" VerticalOptions="Center"/>
<vues:JetonVue Couleur="{x:Static conv:CouleurVersCouleurMAUI.Rouge}" Code="{Binding Source={x:Reference plateauPage}, Path=BindingContext.Code}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2"></vues:JetonVue>
<vues:JetonVue Couleur="{x:Static conv:CouleurVersCouleurMAUI.Rouge}" Code="{Binding Source={x:Reference plateauPage}, Path=BindingContext.Code}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2"/>
<vues:JetonVue Couleur="{x:Static conv:CouleurVersCouleurMAUI.Vert}" Code="{Binding Source={x:Reference plateauPage}, Path=BindingContext.Code}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="2" Grid.Row="2" Grid.ColumnSpan="2"/>
<vues:JetonVue Couleur="{x:Static conv:CouleurVersCouleurMAUI.Bleu}" Code="{Binding Source={x:Reference plateauPage}, Path=BindingContext.Code}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="4" Grid.Row="2" Grid.ColumnSpan="2"/>

@ -3,15 +3,46 @@
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"/>
<Label Text="Scoreboard" Style="{StaticResource TexteTitre}" 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>

@ -1,11 +1,140 @@
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 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;
}
}
}

@ -16,8 +16,28 @@
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource TexteSombre}, Dark={StaticResource TexteClair}}"/>
<Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource FondSecondaireClair}, Dark={StaticResource FondSecondaireSombre}}" />
<Setter Property="FontSize" Value="Large"/>
<Setter Property="HeightRequest" Value="80"/>
<Setter Property="WidthRequest" Value="500"/>
<Setter Property="HeightRequest" Value="60"/>
<Setter Property="WidthRequest" Value="250"/>
</Style>
<Style x:Key="ButtonClassement" TargetType="Button">
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource TexteSombre}, Dark={StaticResource TexteClair}}"/>
<Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource FondSecondaireClair}, Dark={StaticResource FondSecondaireSombre}}" />
<Setter Property="FontSize" Value="Large"/>
<Setter Property="HeightRequest" Value="60"/>
<Setter Property="WidthRequest" Value="150"/>
<Setter Property="FontSize" Value="20"/>
</Style>
<Style x:Key="ButtonClassementRegle" TargetType="Button">
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource TexteSombre}, Dark={StaticResource TexteClair}}"/>
<Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource FondSecondaireClair}, Dark={StaticResource FondSecondaireSombre}}" />
<Setter Property="FontSize" Value="24"/>
<Setter Property="Padding" Value="10, 5"/>
<Setter Property="HorizontalOptions" Value="Center"/>
<Setter Property="VerticalOptions" Value="Center"/>
<Setter Property="Text" Value="10"/>
</Style>
<Style TargetType="Frame">

Loading…
Cancel
Save