Correction du plateau enfin fonctionnel

master
Céleste BARBOSA 11 months ago
parent f4466b4731
commit 4ea59be589

@ -1,4 +1,5 @@
using CoreLibrary.Exceptions;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
namespace CoreLibrary.Core
@ -7,10 +8,8 @@ namespace CoreLibrary.Core
public class Code
{
[DataMember]
private readonly List<Jeton> jetons = new List<Jeton>();
public IReadOnlyList<Jeton> Jetons => jetons;
public int Taille => jetons.Count;
public ObservableCollection<Jeton> Jetons { get; private init; } = new ObservableCollection<Jeton>();
public int Taille => Jetons.Count;
[DataMember]
public int TailleMax { get; private init; }
public bool Complet => Taille == TailleMax;
@ -29,7 +28,7 @@ namespace CoreLibrary.Core
if (Complet)
throw new CodeCompletException();
jetons.Add(jeton);
Jetons.Add(jeton);
}
public Jeton RecupererJeton(int indice)
@ -37,7 +36,7 @@ namespace CoreLibrary.Core
if (indice < 0 || indice >= Taille)
throw new IndiceCodeException(indice, Taille - 1);
return jetons.ElementAt(indice);
return Jetons.ElementAt(indice);
}
public void SupprimerDernierJeton()
@ -45,7 +44,7 @@ namespace CoreLibrary.Core
if (Vide)
throw new CodeVideException();
jetons.RemoveAt(Taille - 1);
Jetons.RemoveAt(Taille - 1);
}
public IReadOnlyList<Indicateur> Comparer(Code code)
@ -60,29 +59,32 @@ namespace CoreLibrary.Core
if (code.TailleMax != TailleMax)
throw new CodeInvalideException();
List<Jeton> mesJetons = Jetons.ToList();
List<Jeton> sesJetons = code.Jetons.ToList();
List<Jeton?> mesJetons = Jetons.Select(jeton => (Jeton?)jeton).ToList();
List<Jeton?> sesJetons = code.Jetons.Select(jeton => (Jeton?)jeton).ToList();
for (int i = 0; i < mesJetons.Count; ++i)
{
if (mesJetons[i] == sesJetons[i])
{
mesJetons.RemoveAt(i);
sesJetons.RemoveAt(i);
mesJetons[i] = null;
sesJetons[i] = null;
indicateurs.Add(Indicateur.BonnePlace);
}
}
for (int i = 0; i < sesJetons.Count; ++i)
{
if (mesJetons.Remove(sesJetons[i]))
if (sesJetons[i].HasValue && mesJetons.Contains(sesJetons[i]))
{
sesJetons.RemoveAt(i);
mesJetons[mesJetons.IndexOf(sesJetons[i])] = null;
sesJetons[i] = null;
indicateurs.Add(Indicateur.BonneCouleur);
}
}
return indicateurs;
}
public override string ToString() => $"Code({Taille})";
}
}

@ -46,6 +46,8 @@ namespace CoreLibrary.Joueurs
return this;
}
public override string ToString() => Nom;
public int Statistique(IRegles regles, Statistique statistique) =>
statistiques.GetValueOrDefault((regles, statistique), 0);

@ -11,6 +11,9 @@ namespace CoreLibrary.Manageurs
private readonly List<Joueur> joueurs;
private readonly List<Partie> parties;
public IReadOnlyList<Joueur> Joueurs => joueurs;
public IReadOnlyList<Partie> Parties => parties;
public Manageur(IPersistance persistance)
{
this.persistance = persistance;

@ -0,0 +1,50 @@
[
{
"EstConnecte": false,
"Nom": "Céleste",
"statistiques": [
{
"Key": {
"Item1": {
"__type": "ReglesClassiques:#CoreLibrary.Regles"
},
"Item2": 3
},
"Value": 10
},
{
"Key": {
"Item1": {
"__type": "ReglesClassiques:#CoreLibrary.Regles"
},
"Item2": 3
},
"Value": 11
}
]
},
{
"EstConnecte": false,
"Nom": "Pauline",
"statistiques": [
{
"Key": {
"Item1": {
"__type": "ReglesClassiques:#CoreLibrary.Regles"
},
"Item2": 3
},
"Value": 10
},
{
"Key": {
"Item1": {
"__type": "ReglesClassiques:#CoreLibrary.Regles"
},
"Item2": 3
},
"Value": 10
}
]
}
]

File diff suppressed because it is too large Load Diff

@ -20,17 +20,17 @@ namespace MauiSpark.Convertisseurs
switch (value)
{
case Couleur.BLANC:
case Couleur.Blanc:
return Blanc;
case Couleur.BLEU:
case Couleur.Bleu:
return Bleu;
case Couleur.VERT:
case Couleur.Vert:
return Vert;
case Couleur.ROUGE:
case Couleur.Rouge:
return Rouge;
case Couleur.NOIR:
case Couleur.Noir:
return Noir;
case Couleur.JAUNE:
case Couleur.Jaune:
return Jaune;
default:
return Noir;
@ -39,22 +39,22 @@ namespace MauiSpark.Convertisseurs
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not Color) return Couleur.NOIR;
if (value is not Color) return Couleur.Noir;
if (value.Equals(Rouge))
return Couleur.ROUGE;
return Couleur.Rouge;
if (value.Equals(Vert))
return Couleur.VERT;
return Couleur.Vert;
if (value.Equals(Bleu))
return Couleur.BLEU;
return Couleur.Bleu;
if (value.Equals(Jaune))
return Couleur.JAUNE;
return Couleur.Jaune;
if (value.Equals(Noir))
return Couleur.NOIR;
return Couleur.Noir;
if (value.Equals(Blanc))
return Couleur.BLANC;
return Couleur.Blanc;
return Couleur.NOIR;
return Couleur.Noir;
}
}
}

@ -11,9 +11,9 @@ namespace MauiSpark.Convertisseurs
switch (value)
{
case Indicateur.BONNEPLACE:
case Indicateur.BonnePlace:
return "black";
case Indicateur.BONNECOULEUR:
case Indicateur.BonneCouleur:
return "white";
default:
return "black";

@ -1,25 +0,0 @@
using CoreLibrary.Core;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MauiSpark.Convertisseurs
{
public class JetonVersTexte : IValueConverter
{
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not Jeton) return "";
return "O";
}
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

@ -1,4 +1,4 @@
using CoreLibrary.Manager;
using CoreLibrary.Manageurs;
using CoreLibrary.Persistance;
using Microsoft.Extensions.Logging;

@ -103,9 +103,6 @@
<MauiXaml Update="Pages\Victoire.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\CTableauScore.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Vues\BoutonClassementVue.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>

@ -1,4 +1,4 @@
using CoreLibrary.Events;
using CoreLibrary.Evenements;
using CoreLibrary.Joueurs;
namespace MauiSpark.Pages;
@ -6,8 +6,8 @@ namespace MauiSpark.Pages;
public partial class ConnexionPage : ContentPage
{
private JoueurBuilder? joueurBuilder;
private int? indice;
private Joueur? joueurDemande;
public ConnexionPage()
{
@ -16,29 +16,29 @@ public partial class ConnexionPage : ContentPage
InitializeComponent();
}
public async void QuandDemanderNom(Object? sender, DemanderNomEventArgs e)
public async void QuandDemanderNom(Object? sender, PartieDemanderJoueurEventArgs e)
{
if(Application.Current != null && Application.Current.MainPage != null && ((NavigationPage)Application.Current.MainPage).CurrentPage != this)
await Application.Current.MainPage.Navigation.PushAsync(this);
Nom.Text = "";
joueurBuilder = e.JoueurBuilder;
indice = e.Indice;
joueurDemande = e.JoueurDemande;
BindingContext = $"Joueur {e.Indice}";
}
private void QuandSeConnecterPresse(Object sender, EventArgs e)
{
if(joueurBuilder != null)
{
if(string.IsNullOrEmpty(Nom.Text))
if (joueurDemande == null || indice == null)
return;
if (string.IsNullOrEmpty(Nom.Text))
{
joueurBuilder.Joueur(new Joueur($"Joueur {indice}"));
joueurDemande.SeConnecter(new Joueur($"Joueur {indice.Value}"));
}
else
{
joueurBuilder.Joueur(MauiProgram.Manageur.DemanderJoueur(Nom.Text));
}
joueurDemande.SeConnecter(MauiProgram.Manageur.DemanderJoueur(Nom.Text));
}
}
}

@ -17,15 +17,13 @@ public partial class ModePage : ContentPage
Partie partie;
if (sender.Equals(ReglesClassiques))
partie = new Partie(new ReglesClassiques());
partie = MauiProgram.Manageur.NouvellePartie(new ReglesClassiques());
else
return;
partie.DemanderNom += new ConnexionPage().QuandDemanderNom;
partie.NouveauTour += new PlateauPage().QuandNouveauTour;
partie.PartieTerminee += new Victoire().QuandPartieTerminee;
MauiProgram.Manageur.NouvellePartie(partie);
partie.PartieDemanderJoueur += new ConnexionPage().QuandDemanderNom;
partie.PartieNouveauTour += new PlateauPage().QuandNouveauTour;
partie.PartiePartieTerminee += new Victoire().QuandPartieTerminee;
partie.Jouer();
}

@ -4,12 +4,12 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiSpark.Pages.PlateauPage"
xmlns:vues="clr-namespace:MauiSpark.Vues"
x:Name="plateauPage"
Title="PlateauPage">
<ContentPage.Resources>
<conv:CouleurVersCouleurMAUI x:Key="CouleurVersCouleurMAUI"/>
<conv:IndicateurVersCouleurMAUI x:Key="IndicateurVersCouleurMAUI"/>
<conv:JetonVersTexte x:Key="JetonVersTexte"/>
</ContentPage.Resources>
<ContentPage.Content>
@ -112,13 +112,13 @@
<BoxView Grid.Row="1" Grid.ColumnSpan="6" HeightRequest="1" VerticalOptions="Center"/>
<vues:JetonVue Couleur="{x:Static conv:CouleurVersCouleurMAUI.Rouge}" Code="{Binding Code}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2"></vues:JetonVue>
<vues:JetonVue Couleur="{x:Static conv:CouleurVersCouleurMAUI.Vert}" Code="{Binding Code}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="2" Grid.Row="2" Grid.ColumnSpan="2"/>
<vues:JetonVue Couleur="{x:Static conv:CouleurVersCouleurMAUI.Bleu}" Code="{Binding Code}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="4" Grid.Row="2" Grid.ColumnSpan="2"/>
<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.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"/>
<vues:JetonVue Couleur="{x:Static conv:CouleurVersCouleurMAUI.Jaune}" Code="{Binding Code}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="2"/>
<vues:JetonVue Couleur="{x:Static conv:CouleurVersCouleurMAUI.Noir}" Code="{Binding Code}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="2" Grid.Row="3" Grid.ColumnSpan="2"/>
<vues:JetonVue Couleur="{x:Static conv:CouleurVersCouleurMAUI.Blanc}" Code="{Binding Code}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="4" Grid.Row="3" Grid.ColumnSpan="2"/>
<vues:JetonVue Couleur="{x:Static conv:CouleurVersCouleurMAUI.Jaune}" Code="{Binding Source={x:Reference plateauPage}, Path=BindingContext.Code}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="2"/>
<vues:JetonVue Couleur="{x:Static conv:CouleurVersCouleurMAUI.Noir}" Code="{Binding Source={x:Reference plateauPage}, Path=BindingContext.Code}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="2" Grid.Row="3" Grid.ColumnSpan="2"/>
<vues:JetonVue Couleur="{x:Static conv:CouleurVersCouleurMAUI.Blanc}" Code="{Binding Source={x:Reference plateauPage}, Path=BindingContext.Code}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="4" Grid.Row="3" Grid.ColumnSpan="2"/>
</Grid>
</Border>

@ -1,5 +1,5 @@
using CoreLibrary.Core;
using CoreLibrary.Events;
using CoreLibrary.Evenements;
using CoreLibrary.Exceptions;
using CoreLibrary.Joueurs;
@ -12,27 +12,36 @@ internal class Tour
public string Numero { get; private init; }
public Code Code { get; private init; }
public Tour(NouveauTourEventArgs e)
public Tour(PartieNouveauTourEventArgs e)
{
Numero = $"Tour {e.Tour}";
Joueur = e.Joueur;
Code = e.Code;
(IEnumerable<Jeton>, IEnumerable<Indicateur>)[] plateau = new (IEnumerable<Jeton>, IEnumerable<Indicateur>)[e.Grille.Count()];
for (int i = 0; i < e.Grille.Count(); ++i)
(IReadOnlyList<IReadOnlyList<Jeton>> jetons, IReadOnlyList < IReadOnlyList < Indicateur >> indicateurs) = e.Plateau.Grille;
List<(IEnumerable<Jeton>, IEnumerable<Indicateur>)> plateau = new List<(IEnumerable<Jeton>, IEnumerable<Indicateur>)>();
for (int i = 0; i < e.Plateau.TailleMax; ++i)
{
if(i >= jetons.Count)
{
plateau[i] = ([new Jeton(Couleur.ROUGE), new Jeton(Couleur.VERT), new Jeton(Couleur.BLEU), new Jeton(Couleur.JAUNE)], e.Indicateurs.ElementAt(i));
plateau.Add(([], []));
continue;
}
plateau.Add((jetons.ElementAt(i), indicateurs.ElementAt(i)));
}
Plateau = plateau;
}
}
public partial class PlateauPage : ContentPage
{
private Code? code;
private Joueur? joueur;
private Plateau? plateau;
public PlateauPage()
{
@ -41,7 +50,7 @@ public partial class PlateauPage : ContentPage
InitializeComponent();
}
public async void QuandNouveauTour(object? sender, NouveauTourEventArgs e)
public async void QuandNouveauTour(object? sender, PartieNouveauTourEventArgs e)
{
if (Application.Current == null || Application.Current.MainPage == null)
return;
@ -60,7 +69,7 @@ public partial class PlateauPage : ContentPage
}
code = e.Code;
joueur = e.Joueur;
plateau = e.Plateau;
BindingContext = new Tour(e);
}
@ -82,8 +91,8 @@ public partial class PlateauPage : ContentPage
{
try
{
if(joueur != null && code != null)
joueur.Code(code);
if (plateau != null && code != null)
plateau.AjouterCode(code);
}
catch (CodeIncompletException)
{

@ -2,7 +2,6 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:MauiSpark.Pages"
xmlns:views="clr-namespace:MauiSpark.Views"
x:Class="MauiSpark.Pages.TableauScore"
Title="TableauScore">
<ScrollView>
@ -12,17 +11,6 @@
<Label Text="Scoreboard" Style="{StaticResource TexteTitre}" Margin="0" />
<Image Grid.Row="1" Source="star.png" WidthRequest="100" HorizontalOptions="Start" VerticalOptions="Center" Margin="0"/>
</FlexLayout>
<Frame Margin="20" >
<Grid ColumnDefinitions="auto,*,auto,auto,auto,auto" ColumnSpacing="10" >
<Button Margin="5" Grid.Column="0" Text="RANK" Style="{StaticResource ButtonTableau}" VerticalOptions="Center"></Button>
<Button Margin="5" Grid.Column="1" Text="PSEUDO" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" HorizontalOptions="Start" Clicked="QuandAlphabetButtonClicked" ></Button>
<Button Margin="5" Grid.Column="2" Text="Coût Moyen" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandNbCoutMoyenButtonClicked"></Button>
<Button Margin="5" Grid.Column="3" Text="Partie Gagnée" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandGagneeButtonClicked"></Button>
<Button Margin="5" Grid.Column="4" Text="Partie Perdue" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandPerduButtonClicked"></Button>
<Button Margin="5" Grid.Column="5" Text="Partie Egalité" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandEgaliteButtonClicked"></Button>
</Grid>
</Frame>
<views:CTableauScore x:Name="CTableauScore"/>
</VerticalStackLayout>
</ScrollView>

@ -1,4 +1,3 @@
using MauiSpark.Views;
namespace MauiSpark.Pages;
public partial class TableauScore : ContentPage
@ -8,32 +7,5 @@ public partial class TableauScore : ContentPage
NavigationPage.SetHasNavigationBar(this, false);
InitializeComponent();
QuandNbCoutMoyenButtonClicked(this, EventArgs.Empty);
}
private void QuandNbCoutMoyenButtonClicked(object sender, EventArgs e)
{
CTableauScore.UpdateClassement(CTableauScore.GetClassementNbCoupParPartie);
}
private void QuandGagneeButtonClicked(object sender, EventArgs e)
{
CTableauScore.UpdateClassement(CTableauScore.GetClassementPartieGagnee);
}
private void QuandPerduButtonClicked(object sender, EventArgs e)
{
CTableauScore.UpdateClassement(CTableauScore.GetClassementPartiePerdue);
}
private void QuandEgaliteButtonClicked(object sender, EventArgs e)
{
CTableauScore.UpdateClassement(CTableauScore.GetClassementPartieEgalite);
}
private void QuandAlphabetButtonClicked(object sender, EventArgs e)
{
CTableauScore.UpdateClassement(CTableauScore.GetClassementAlphabet);
}
}

@ -1,4 +1,4 @@
using CoreLibrary.Events;
using CoreLibrary.Evenements;
using CoreLibrary.Joueurs;
namespace MauiSpark.Pages;
@ -12,7 +12,7 @@ public partial class Victoire : ContentPage
InitializeComponent();
}
public async void QuandPartieTerminee(object? sender, PartieTermineeEventArgs e)
public async void QuandPartieTerminee(object? sender, PartiePartieTermineeEventArgs e)
{
if (Application.Current == null || Application.Current.MainPage == null)
return;
@ -30,26 +30,15 @@ public partial class Victoire : ContentPage
Application.Current.MainPage.Navigation.RemovePage(page);
}
Joueur[] gagnants = e.Gagnants;
Joueur[] perdants = e.Perdants;
IReadOnlyList<Joueur> gagnants = e.Gagnants;
IReadOnlyList<Joueur> perdants = e.Perdants;
if (gagnants.Length == 1)
BindingContext = ("Victoire", $"Le joueur {gagnants.First().Nom} a gagné");
else if (gagnants.Length > 1)
if (gagnants.Count == 1)
BindingContext = ("Victoire", $"Le joueur {gagnants[0].Nom} a gagné");
else if (gagnants.Count > 1)
BindingContext = ("Egalité", $"Les joueurs {string.Join(' ', gagnants.Select(joueur => joueur.Nom))} ont gagné");
else
BindingContext = ("Défaite", "Personne n'a trouvé le code...");
if (gagnants.Length == 1)
gagnants.First().AGagne();
else
foreach (Joueur gagnant in gagnants)
gagnant.AEgalite();
foreach (Joueur perdant in perdants)
perdant.APerdu();
}
public async void QuandMenuPresse(object sender, EventArgs e)

@ -1,23 +0,0 @@
<?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.Views.CTableauScore">
<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,20,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 NbCoutMoyen}" Margin="20,20,100,20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="3" Text="{Binding Joueur.NbPartieGagnee}" Margin="55,20,100,20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="4" Text="{Binding Joueur.NbPartiePerdue}" Margin="55,20,100,20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="5" Text="{Binding Joueur.NbPartieEgalite}" Margin="55,20,100,20" Style="{StaticResource TexteFrame}" />
</Grid>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentView>

@ -1,241 +0,0 @@
using CoreLibrary.Joueurs;
using CoreLibrary.Manager;
namespace MauiSpark.Views;
public class JoueurClassementNbCoupParPartie
{
private Manageur manageur;
private Joueur joueur;
public Joueur Joueur
{
get => joueur;
private set => joueur = value;
}
public int Place
{
get => manageur.Joueurs
.OrderBy(joueur => joueur.NbCoutTotal/(joueur.NbPartiePerdue+joueur.NbPartieGagnee+joueur.NbPartieEgalite)).ToList()
.IndexOf(Joueur) + 1;
}
public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite);
public JoueurClassementNbCoupParPartie(Joueur joueur, Manageur manageur)
{
this.manageur = manageur;
this.joueur = joueur;
}
}
public class JoueurClassementPartieGagnee
{
private Manageur manageur;
private Joueur joueur;
public Joueur Joueur
{
get => joueur;
private set => joueur = value;
}
public int Place
{
get => manageur.Joueurs.OrderByDescending(joueur => joueur.NbPartieGagnee).ToList().IndexOf(Joueur) + 1;
}
public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite);
public JoueurClassementPartieGagnee(Joueur joueur, Manageur manageur)
{
this.manageur = manageur;
this.joueur = joueur;
}
}
public class JoueurClassementPartieEgalite
{
private Manageur manageur;
private Joueur joueur;
public Joueur Joueur
{
get => joueur;
private set => joueur = value;
}
public int Place
{
get => manageur.Joueurs.OrderByDescending(joueur => joueur.NbPartieEgalite).ToList().IndexOf(joueur)+1;
}
public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite);
public JoueurClassementPartieEgalite(Joueur joueur, Manageur manageur)
{
this.manageur = manageur;
this.joueur = joueur;
}
}
public class JoueurClassementPartiePerdue
{
private Manageur manageur;
private Joueur joueur;
public Joueur Joueur
{
get => joueur;
private set => joueur = value;
}
public int Place
{
get => manageur.Joueurs.OrderByDescending(joueur => joueur.NbPartiePerdue).ToList().IndexOf(joueur)+1;
}
public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite);
public JoueurClassementPartiePerdue(Joueur joueur, Manageur manageur)
{
this.manageur = manageur;
this.joueur = joueur;
}
}
public class JoueurClassementAlphabet
{
private Manageur manageur;
private Joueur joueur;
public Joueur Joueur
{
get => joueur;
private set => joueur = value;
}
public int Place
{
get => manageur.Joueurs
.OrderBy(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite)).ToList()
.IndexOf(Joueur) + 1;
}
public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite);
public JoueurClassementAlphabet(Joueur joueur, Manageur manager)
{
this.manageur = manager;
this.joueur = joueur;
}
}
public partial class CTableauScore : ContentView
{
public int NbClique { get; set; } = 0;
public IEnumerable<JoueurClassementNbCoupParPartie> GetClassementNbCoupParPartie()
{
if(NbClique % 2 == 0)
{
NbClique++;
return MauiProgram.Manageur.Joueurs
.OrderBy(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite))
.Select(joueur => new JoueurClassementNbCoupParPartie(joueur, MauiProgram.Manageur));
}
else
{
NbClique++;
return MauiProgram.Manageur.Joueurs
.OrderByDescending(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite))
.Select(joueur => new JoueurClassementNbCoupParPartie(joueur, MauiProgram.Manageur));
}
}
public IEnumerable<JoueurClassementPartieGagnee> GetClassementPartieGagnee()
{
if(NbClique % 2 == 0)
{
NbClique++;
return MauiProgram.Manageur.Joueurs
.OrderByDescending(joueur => joueur.NbPartieGagnee)
.Select(joueur => new JoueurClassementPartieGagnee(joueur, MauiProgram.Manageur));
}
else
{
NbClique++;
return MauiProgram.Manageur.Joueurs
.OrderBy(joueur => joueur.NbPartieGagnee)
.Select(joueur => new JoueurClassementPartieGagnee(joueur, MauiProgram.Manageur));
}
}
public IEnumerable<JoueurClassementPartieEgalite> GetClassementPartieEgalite()
{
if(NbClique % 2 == 0)
{
NbClique++;
return MauiProgram.Manageur.Joueurs
.OrderByDescending(joueur => joueur.NbPartieEgalite)
.Select(joueur => new JoueurClassementPartieEgalite(joueur, MauiProgram.Manageur));
}
else
{
NbClique++;
return MauiProgram.Manageur.Joueurs
.OrderBy(joueur => joueur.NbPartieEgalite)
.Select(joueur => new JoueurClassementPartieEgalite(joueur, MauiProgram.Manageur));
}
}
public IEnumerable<JoueurClassementPartiePerdue> GetClassementPartiePerdue()
{
if(NbClique % 2 == 0)
{
NbClique++;
return MauiProgram.Manageur.Joueurs
.OrderByDescending(joueur => joueur.NbPartiePerdue)
.Select(joueur => new JoueurClassementPartiePerdue(joueur, MauiProgram.Manageur));
}
else
{
NbClique++;
; return MauiProgram.Manageur.Joueurs
.OrderBy(joueur => joueur.NbPartiePerdue)
.Select(joueur => new JoueurClassementPartiePerdue(joueur, MauiProgram.Manageur));
}
}
public IEnumerable<JoueurClassementAlphabet> GetClassementAlphabet()
{
if(NbClique % 2 == 0)
{
NbClique++;
return MauiProgram.Manageur.Joueurs
.OrderBy(joueur => joueur.Nom)
.Select(joueur => new JoueurClassementAlphabet(joueur, MauiProgram.Manageur));
}
else
{
NbClique++;
return MauiProgram.Manageur.Joueurs
.OrderByDescending(joueur => joueur.Nom)
.Select(joueur => new JoueurClassementAlphabet(joueur, MauiProgram.Manageur));
}
}
public CTableauScore()
{
InitializeComponent();
}
public void UpdateClassement(Func<IEnumerable<object>> getClassement)
{
BindingContext = getClassement();
}
}

@ -7,8 +7,8 @@ namespace MauiSpark.Vues;
public partial class JetonVue : ContentView
{
public static readonly BindableProperty CouleurProperty = BindableProperty.Create(nameof(Couleur), typeof(Color), typeof(JetonVue), default(Color), propertyChanged: QuandCouleurChangee);
public static readonly BindableProperty CodeProperty = BindableProperty.Create(nameof(Code), typeof(Code), typeof(JetonVue), null, propertyChanged: QuandCodeChange);
public static readonly BindableProperty CouleurProperty = BindableProperty.Create(nameof(Couleur), typeof(Color), typeof(JetonVue), default(Color));
public static readonly BindableProperty CodeProperty = BindableProperty.Create(nameof(Code), typeof(Code), typeof(JetonVue), null);
public Color Couleur
{
@ -34,25 +34,12 @@ public partial class JetonVue : ContentView
Cercle.WidthRequest = Cercle.HeightRequest = taille;
}
private static void QuandCouleurChangee(BindableObject bindable, object ancienneValeur, object nouvelleValeur)
{
if (((Color)nouvelleValeur).Red != 0 || ((Color)nouvelleValeur).Green != 0 || ((Color)nouvelleValeur).Blue != 0)
{
((JetonVue)bindable).Cercle.Fill = (Color)nouvelleValeur;
}
}
private static void QuandCodeChange(BindableObject bindable, object ancienneValeur, object nouvelleValeur)
{
}
private void JetonPresse(object sender, EventArgs e)
{
if (Cercle == null || !sender.Equals(Cercle) || Code == null || Application.Current == null || Application.Current.MainPage == null)
return;
Couleur couleur = (Couleur)new CouleurVersCouleurMAUI().ConvertBack(Cercle.Fill, typeof(Couleur), null, CultureInfo.InvariantCulture);
Couleur couleur = (Couleur)new CouleurVersCouleurMAUI().ConvertBack(((SolidColorBrush)Cercle.Fill).Color, typeof(Couleur), null, CultureInfo.InvariantCulture);
try
{

@ -1,5 +1,5 @@
using CoreLibrary.Core;
using CoreLibrary.Events;
using CoreLibrary.Evenements;
using Xunit;
namespace UnitTesting

@ -1,5 +1,5 @@
using CoreLibrary.Core;
using CoreLibrary.Events;
using CoreLibrary.Evenements;
using CoreLibrary.Joueurs;
using Xunit;

@ -1,5 +1,5 @@
using CoreLibrary.Core;
using CoreLibrary.Events;
using CoreLibrary.Evenements;
using Xunit;
namespace UnitTesting

@ -1,4 +1,4 @@
using CoreLibrary.Events;
using CoreLibrary.Evenements;
using CoreLibrary.Joueurs;
using Xunit;

@ -1,5 +1,5 @@
using CoreLibrary.Core;
using CoreLibrary.Events;
using CoreLibrary.Evenements;
using Xunit;
namespace UnitTesting

@ -1,5 +1,5 @@
using CoreLibrary.Core;
using CoreLibrary.Events;
using CoreLibrary.Evenements;
using CoreLibrary.Joueurs;
using System.Reflection;
using Xunit;

@ -1,5 +1,5 @@
using CoreLibrary.Core;
using CoreLibrary.Events;
using CoreLibrary.Evenements;
using CoreLibrary.Joueurs;
using System.Reflection;
using Xunit;
@ -61,10 +61,10 @@ namespace UnitTesting
public void JoueurQuandJouerCode()
{
Code code = new Code(4);
code.AjouterJeton(new Jeton(Couleur.ROUGE));
code.AjouterJeton(new Jeton(Couleur.BLANC));
code.AjouterJeton(new Jeton(Couleur.BLEU));
code.AjouterJeton(new Jeton(Couleur.NOIR));
code.AjouterJeton(new Jeton(Couleur.Rouge));
code.AjouterJeton(new Jeton(Couleur.Blanc));
code.AjouterJeton(new Jeton(Couleur.Blanc));
code.AjouterJeton(new Jeton(Couleur.Noir));
Code? codeEvenement = null;

@ -1,4 +1,4 @@
using CoreLibrary.Events;
using CoreLibrary.Evenements;
using Xunit;
namespace UnitTesting

Loading…
Cancel
Save