master
Pauline PRADY 11 months ago
commit 6cfb2056e9

@ -1,22 +1,22 @@
namespace CoreLibrary.Events
{
namespace CoreLibrary.Events
{
/// <summary>
/// Classe contenant les arguments passées en paramètre lors de l'événement DemanderJeton.
/// </summary>
public class DemanderJetonEventArgs : EventArgs
{
/// </summary>
public class DemanderJetonEventArgs : EventArgs
{
/// <summary>
/// L'indice du code où le jeton va être ajouté.
/// </summary>
public int Indice { get; private set; }
/// </summary>
public int Indice { get; private set; }
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="DemanderJetonEventArgs"/> avec l'indice spécifié.
/// </summary>
/// <param name="joueur">L'indice du jeton qui va été ajouté.</param>
public DemanderJetonEventArgs(int indice)
/// <param name="joueur">L'indice du jeton qui va été ajouté.</param>
public DemanderJetonEventArgs(int indice)
{
Indice = indice;
}
}
}
Indice = indice;
}
}
}

@ -1,7 +1,4 @@
using CoreLibrary.Core;
using CoreLibrary.Events;
namespace CoreLibrary.Joueurs
namespace CoreLibrary.Joueurs
{
/// <summary>
/// Classe représentant un joueur.
@ -13,12 +10,13 @@ namespace CoreLibrary.Joueurs
/// </summary>
public string Nom { get; private init; }
/// <summary>
/// Le plateau du joueur.
/// </summary>
public Plateau Plateau { get; private init; }
public int NbCoutTotal { get; set; }
public int NbPartieGagnee { get; set; }
public int NbPartieEgalite { get; set; }
public int NbPartiePerdue { get; set; }
/// <summary>
/// Crée une nouvelle instance de joueur avec un nom
/// Evénement appelé pour jouer un code.
/// </summary>
public event EventHandler<JouerCodeEventArgs>? JouerCode;
@ -32,11 +30,22 @@ namespace CoreLibrary.Joueurs
/// Crée une nouvelle instance de joueur avec un nom et un plateau spécifié.
/// </summary>
/// <param name="nom">Le nom du joueur.</param>
/// <param name="plateau">Le plateau du joueur.</param>
public Joueur(string nom, Plateau plateau)
public Joueur(string nom)
{
Nom = nom;
NbCoutTotal = 0;
NbPartieGagnee = 0;
NbPartieEgalite = 0;
NbPartiePerdue = 0;
}
public Joueur(string nom, int nbCoutTotal, int nbPartieGagnee, int nbPartieEgalite, int nbPartiePerdue)
{
Nom = nom;
Plateau = plateau;
NbCoutTotal = nbCoutTotal;
NbPartieGagnee = nbPartieGagnee;
NbPartieEgalite = nbPartieEgalite;
NbPartiePerdue = nbPartiePerdue;
}
}
}

@ -0,0 +1,11 @@
namespace CoreLibrary.Manager
{
public interface IPersistanceManager
{
public void Charger();
public void Enregistrer();
}
}

@ -0,0 +1,28 @@
using CoreLibrary.Joueurs;
using CoreLibrary.Regles;
namespace CoreLibrary.Manager
{
public class Manager : IPersistanceManager
{
private Joueur[] joueurs = [];
public IReadOnlyList<Joueur> Joueurs => Array.AsReadOnly(joueurs);
public void Charger()
{
joueurs = [
new Joueur("Pauline", 50, 5, 2, 0),
new Joueur("Céleste", 40, 6, 2, 0),
new Joueur("Camille", 55, 8, 0, 1),
new Joueur("Toto", 70, 0, 0, 10),
];
}
public void Enregistrer()
{
throw new NotImplementedException();
}
}
}

@ -44,7 +44,7 @@ namespace CoreLibrary.Regles
/// Récupère le joueur courant.
/// </summary>
/// <returns>Le joueur courant.</returns>
Joueur JoueurCourant();
(Joueur, Plateau) JoueurCourant();
/// <summary>
/// Passe la main au joueur suivant.

@ -1,171 +1,174 @@
using CoreLibrary.Core;
using CoreLibrary.Exceptions;
using CoreLibrary.Joueurs;
namespace CoreLibrary.Regles
{
/// <summary>
/// Classe définissant les règles classiques du jeu.
/// </summary>
public class ReglesClassiques : IRegles
{
private int nbJoueurs = 0;
private int? joueurCourant;
private readonly Joueur[] joueurs;
/// <summary>
/// Le nom des règles.
/// </summary>
public string Nom { get => "Règles classiques"; }
/// <summary>
/// Le nombre maximum de tour.
/// </summary>
public int TourMaximum { get => 12; }
/// <summary>
/// La taille maximale d'un code.
/// </summary>
public int TailleCodeMaximum { get => 4; }
/// <summary>
/// Le nombre de joueurs actuels dans le jeu.
/// </summary>
using CoreLibrary.Core;
using CoreLibrary.Exceptions;
using CoreLibrary.Joueurs;
namespace CoreLibrary.Regles
{
/// <summary>
/// Classe définissant les règles classiques du jeu.
/// </summary>
public class ReglesClassiques : IRegles
{
private int nbJoueurs = 0;
private int? joueurCourant;
private readonly Joueur[] joueurs;
private readonly Plateau[] plateaux;
/// <summary>
/// Le nom des règles.
/// </summary>
public string Nom { get => "Règles classiques"; }
/// <summary>
/// Le nombre maximum de tour.
/// </summary>
public int TourMaximum { get => 12; }
/// <summary>
/// La taille maximale d'un code.
/// </summary>
public int TailleCodeMaximum { get => 4; }
/// <summary>
/// Le nombre de joueurs actuels dans le jeu.
/// </summary>
public int NbJoueurs { get => nbJoueurs; }
/// <summary>
/// Me nombre maximum de joueurs possibles pour le jeu.
/// </summary>
public int NbJoueursMaximum { get => 2; }
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="ReglesClassiques"/>
/// </summary>
public ReglesClassiques()
{
joueurs = new Joueur[NbJoueursMaximum];
}
/// <summary>
/// Ajoute un joueur avec le nom spécifié.
/// </summary>
/// <param name="nom">Le nom du joueur à ajouter.</param>
/// <returns>Le joueur ajouté.</returns>
public Joueur AjouterJoueur(string nom)
{
Joueur joueur = new Joueur(nom, new Plateau(TailleCodeMaximum, TourMaximum));
joueurs[nbJoueurs++] = joueur;
return joueur;
}
/// <summary>
/// Obtient le joueur dont c'est actuellement le tour.
/// </summary>
/// <returns>Le joueur actuel.</returns>
/// <exception cref="PartieNonCommenceeException">Levée lorsque la partie n'a pas commencée.</exception>
public Joueur JoueurCourant()
{
if (!joueurCourant.HasValue)
throw new PartieNonCommenceeException();
return joueurs[joueurCourant.Value];
}
/// <summary>
/// Passe la main au joueur suivant.
/// </summary>
/// <exception cref="PartieNonCommenceeException">Levée lorsque la partie n'a pas commmencée.</exception>
public void PasserLaMain()
{
if (!joueurCourant.HasValue)
{
throw new PartieNonCommenceeException();
}
++joueurCourant;
if (joueurCourant >= joueurs.Length)
{
joueurCourant = 0;
}
}
/// <summary>
/// Génère un nouveau code respectant les règles classiques.
/// </summary>
/// <returns>Le code généré.</returns>
public Code GenererCode()
{
return new Code(TailleCodeMaximum);
}
/// <summary>
/// Démarre la partie en décidant que le premier joueur commence.
/// </summary>
public void CommencerLaPartie()
{
joueurCourant = 0;
}
/// <summary>
/// Vérifie si la partie est terminée.
/// </summary>
/// <returns>True si la partie est terminée, sinon False.</returns>
public bool EstTerminee()
{
if (!joueurCourant.HasValue || joueurCourant != 0)
return false;
if (JoueurCourant().Plateau.Tour > TourMaximum)
return true;
for (int i = 0; i < joueurs.Length; ++i)
{
if (joueurs[i].Plateau.Victoire)
return true;
}
return false;
}
/// <summary>
/// Obtient les joueurs gagnants de la partie.
/// </summary>
/// <returns>La liste des joueurs gagnants.</returns>
public IEnumerable<Joueur> Gagnants()
{
Joueur[] gagnants = [];
for (int i = 0; i < joueurs.Length; ++i)
{
if (joueurs[i].Plateau.Victoire)
{
gagnants = gagnants.Append(joueurs[i]).ToArray();
}
}
return gagnants;
}
/// <summary>
/// Obtient les joueurs perdants de la partie.
/// </summary>
/// <returns>La liste des joueurs perdants.</returns>
public IEnumerable<Joueur> Perdants()
{
Joueur[] perdants = [];
for (int i = 0; i < joueurs.Length; ++i)
{
if (!joueurs[i].Plateau.Victoire)
{
perdants = perdants.Append(joueurs[i]).ToArray();
}
}
return perdants;
}
}
}
/// <summary>
/// Me nombre maximum de joueurs possibles pour le jeu.
/// </summary>
public int NbJoueursMaximum { get => 2; }
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="ReglesClassiques"/>
/// </summary>
public ReglesClassiques()
{
joueurs = new Joueur[NbJoueursMaximum];
plateaux = new Plateau[NbJoueursMaximum];
}
/// <summary>
/// Ajoute un joueur avec le nom spécifié.
/// </summary>
/// <param name="nom">Le nom du joueur à ajouter.</param>
/// <returns>Le joueur ajouté.</returns>
public Joueur AjouterJoueur(string nom)
{
Joueur joueur = new Joueur(nom);
joueurs[nbJoueurs] = joueur;
plateaux[nbJoueurs++] = new Plateau(TailleCodeMaximum, TourMaximum);
return joueur;
}
/// <summary>
/// Obtient le joueur dont c'est actuellement le tour.
/// </summary>
/// <returns>Le joueur actuel.</returns>
/// <exception cref="PartieNonCommenceeException">Levée lorsque la partie n'a pas commencée.</exception>
public (Joueur, Plateau) JoueurCourant()
{
if (!joueurCourant.HasValue)
throw new PartieNonCommenceeException();
return (joueurs[joueurCourant.Value], plateaux[joueurCourant.Value]);
}
/// <summary>
/// Passe la main au joueur suivant.
/// </summary>
/// <exception cref="PartieNonCommenceeException">Levée lorsque la partie n'a pas commmencée.</exception>
public void PasserLaMain()
{
if (!joueurCourant.HasValue)
{
throw new PartieNonCommenceeException();
}
++joueurCourant;
if (joueurCourant >= joueurs.Length)
{
joueurCourant = 0;
}
}
/// <summary>
/// Génère un nouveau code respectant les règles classiques.
/// </summary>
/// <returns>Le code généré.</returns>
public Code GenererCode()
{
return new Code(TailleCodeMaximum);
}
/// <summary>
/// Démarre la partie en décidant que le premier joueur commence.
/// </summary>
public void CommencerLaPartie()
{
joueurCourant = 0;
}
/// <summary>
/// Vérifie si la partie est terminée.
/// </summary>
/// <returns>True si la partie est terminée, sinon False.</returns>
public bool EstTerminee()
{
if (!joueurCourant.HasValue || joueurCourant != 0)
return false;
if (JoueurCourant().Item2.Tour > TourMaximum)
return true;
for (int i = 0; i < joueurs.Length; ++i)
{
if (plateaux[i].Victoire)
return true;
}
return false;
}
/// <summary>
/// Obtient les joueurs gagnants de la partie.
/// </summary>
/// <returns>La liste des joueurs gagnants.</returns>
public IEnumerable<Joueur> Gagnants()
{
Joueur[] gagnants = [];
for (int i = 0; i < joueurs.Length; ++i)
{
if (plateaux[i].Victoire)
{
gagnants = gagnants.Append(joueurs[i]).ToArray();
}
}
return gagnants;
}
/// <summary>
/// Obtient les joueurs perdants de la partie.
/// </summary>
/// <returns>La liste des joueurs perdants.</returns>
public IEnumerable<Joueur> Perdants()
{
Joueur[] perdants = [];
for (int i = 0; i < joueurs.Length; ++i)
{
if (!plateaux[i].Victoire)
{
perdants = perdants.Append(joueurs[i]).ToArray();
}
}
return perdants;
}
}
}

@ -1,11 +1,16 @@
using Microsoft.Extensions.Logging;
using CoreLibrary.Manager;
using Microsoft.Extensions.Logging;
namespace MauiSpark
{
public static class MauiProgram
{
public static Manager Manager { get; private set; } = new Manager();
public static MauiApp CreateMauiApp()
{
Manager.Charger();
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()

@ -62,6 +62,10 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CoreLibrary\CoreLibrary.csproj" />
</ItemGroup>
<ItemGroup>
<MauiXaml Update="Pages\Accueil.xaml">
<Generator>MSBuild:Compile</Generator>

@ -18,25 +18,18 @@
</Grid>
</FlexLayout>
<Frame Margin="20" >
<Grid ColumnDefinitions="auto,*,auto,auto" ColumnSpacing="10">
<Button Margin="0,5,5,5" Grid.Column="0" Text="RANK" Style="{StaticResource ButtonTableau}"></Button>
<Button Margin="5" Grid.Column="1" Text="PSEUDO" Style="{StaticResource ButtonTableau}" HorizontalOptions="Start" ></Button>
<Button Margin="5" Grid.Column="2" Text="Nombre de coût Moyen" Style="{StaticResource ButtonTableau}"></Button>
<Button Margin="5" Grid.Column="3" Text="POINT" Style="{StaticResource ButtonTableau}"></Button>
<Grid ColumnDefinitions="auto,auto,*,auto,auto,auto,auto" RowDefinitions="1,*,1" RowSpacing="0" ColumnSpacing="10" >
<Label Margin="5" Grid.Column="0" Grid.Row="1" Text="RANK" Style="{StaticResource ButtonTableau}" VerticalOptions="Center"></Label>
<Label Margin="5" Grid.Column="1" Grid.Row="1" Text="PSEUDO" Style="{StaticResource ButtonTableau}" VerticalOptions="Center"></Label>
<Button Margin="0" Grid.Column="2" Grid.Row="0" Text="+" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" HorizontalOptions="Start" Clicked="QuandAlphabetHautButtonClicked" ></Button>
<Button Margin="0" Grid.Column="2" Grid.Row="2" Text="-" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" HorizontalOptions="Start" Clicked="QuandAlphabetBasButtonClicked" ></Button>
<Button Margin="5" Grid.Column="3" Grid.Row="1" Text="Nombre de coût Moyen" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandNbCoutMoyenButtonClicked"></Button>
<Button Margin="5" Grid.Column="4" Grid.Row="1" Text="Partie Gagnee" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandGagneeButtonClicked"></Button>
<Button Margin="5" Grid.Column="5" Grid.Row="1" Text="Partie Perdue" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandPerduButtonClicked"></Button>
<Button Margin="5" Grid.Column="6" Grid.Row="1" Text="Partie Egalite" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" Clicked="QuandEgaliteButtonClicked"></Button>
</Grid>
</Frame>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore x:Name="CTableauScore"/>
</VerticalStackLayout>
</ScrollView>

@ -1,9 +1,48 @@
using CoreLibrary.Joueurs;
using MauiSpark.Views;
using System.Collections.ObjectModel;
namespace MauiSpark.Pages;
public partial class TableauScore : ContentPage
{
public TableauScore()
{
InitializeComponent();
}
public TableauScore()
{
InitializeComponent();
SetDefaultClassement();
}
private void SetDefaultClassement()
{
CTableauScore.UpdateClassement(CTableauScore.GetClassementNbCoupParPartie);
}
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 QuandAlphabetHautButtonClicked(object sender, EventArgs e)
{
CTableauScore.UpdateClassement(CTableauScore.GetClassementAlphabetHaut);
}
private void QuandAlphabetBasButtonClicked(object sender, EventArgs e)
{
CTableauScore.UpdateClassement(CTableauScore.GetClassementAlphabetBas);
}
}

@ -1,14 +1,23 @@
<?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">
<Frame CornerRadius="5" Padding="0" VerticalOptions="Start" Margin="20,0,20,10" >
<Grid ColumnDefinitions="auto,*,auto,auto" ColumnSpacing="10">
<Label Grid.Column="0" Text="N°1" Margin="20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="1" Text="Joueur 1" Margin="20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="2" Text="5" Margin="20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="3" Text="10000" Margin="20" Style="{StaticResource TexteFrame}"/>
</Grid>
</Frame>
</ContentView>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiSpark.Views.CTableauScore">
<Frame CornerRadius="5" Padding="0" VerticalOptions="Start" Margin="20,0,20,10" >
<ListView ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<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="20,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="75,20,100,20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="4" Text="{Binding Joueur.NbPartiePerdue}" Margin="75,20,100,20" Style="{StaticResource TexteFrame}" />
<Label Grid.Column="5" Text="{Binding Joueur.NbPartieEgalite}" Margin="75,20,100,20" Style="{StaticResource TexteFrame}" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Frame>
</ContentView>

@ -1,9 +1,191 @@
using CoreLibrary.Events;
using CoreLibrary.Joueurs;
using CoreLibrary.Manager;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace MauiSpark.Views;
public partial class CTableauScore : ContentView
{
public CTableauScore()
public class JoueurClassementNbCoupParPartie
{
private Manager manager;
private Joueur joueur;
public Joueur Joueur
{
get => joueur;
private set => joueur = value;
}
public int Place
{
get => manager.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, Manager manager)
{
this.manager = manager;
this.joueur = joueur;
}
}
public class JoueurClassementPartieGagnee
{
private Manager manager;
private Joueur joueur;
public Joueur Joueur
{
get => joueur;
private set => joueur = value;
}
public int Place
{
get => manager.Joueurs.OrderByDescending(joueur => joueur.NbPartieGagnee).ToList().IndexOf(Joueur) + 1;
}
public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite);
public JoueurClassementPartieGagnee(Joueur joueur, Manager manager)
{
this.manager = manager;
this.joueur = joueur;
}
}
public class JoueurClassementPartieEgalite
{
private Manager manager;
private Joueur joueur;
public Joueur Joueur
{
get => joueur;
private set => joueur = value;
}
public int Place
{
get => manager.Joueurs.OrderByDescending(joueur => joueur.NbPartieEgalite).ToList().IndexOf(joueur)+1;
}
public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite);
public JoueurClassementPartieEgalite(Joueur joueur, Manager manager)
{
this.manager = manager;
this.joueur = joueur;
}
}
public class JoueurClassementPartiePerdue
{
private Manager manager;
private Joueur joueur;
public Joueur Joueur
{
get => joueur;
private set => joueur = value;
}
public int Place
{
get => manager.Joueurs.OrderByDescending(joueur => joueur.NbPartiePerdue).ToList().IndexOf(joueur)+1;
}
public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite);
public JoueurClassementPartiePerdue(Joueur joueur, Manager manager)
{
this.manager = manager;
this.joueur = joueur;
}
}
public class JoueurClassementAlphabet
{
private Manager manager;
private Joueur joueur;
public Joueur Joueur
{
get => joueur;
private set => joueur = value;
}
public int Place
{
get => manager.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, Manager manager)
{
this.manager = manager;
this.joueur = joueur;
}
}
public partial class CTableauScore : ContentView
{
public IEnumerable<JoueurClassementNbCoupParPartie> GetClassementNbCoupParPartie()
{
return MauiProgram.Manager.Joueurs
.OrderBy(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite))
.Select(joueur => new JoueurClassementNbCoupParPartie(joueur, MauiProgram.Manager));
}
public IEnumerable<JoueurClassementPartieGagnee> GetClassementPartieGagnee()
{
return MauiProgram.Manager.Joueurs
.OrderByDescending(joueur => joueur.NbPartieGagnee)
.Select(joueur => new JoueurClassementPartieGagnee(joueur, MauiProgram.Manager));
}
public IEnumerable<JoueurClassementPartieEgalite> GetClassementPartieEgalite()
{
return MauiProgram.Manager.Joueurs
.OrderByDescending(joueur => joueur.NbPartieEgalite)
.Select(joueur => new JoueurClassementPartieEgalite(joueur, MauiProgram.Manager));
}
public IEnumerable<JoueurClassementPartiePerdue> GetClassementPartiePerdue()
{
return MauiProgram.Manager.Joueurs
.OrderByDescending(joueur => joueur.NbPartiePerdue)
.Select(joueur => new JoueurClassementPartiePerdue(joueur, MauiProgram.Manager));
}
public IEnumerable<JoueurClassementAlphabet> GetClassementAlphabetHaut()
{
return MauiProgram.Manager.Joueurs
.OrderBy(joueur => joueur.Nom)
.Select(joueur => new JoueurClassementAlphabet(joueur, MauiProgram.Manager));
}
public IEnumerable<JoueurClassementAlphabet> GetClassementAlphabetBas()
{
return MauiProgram.Manager.Joueurs
.OrderByDescending(joueur => joueur.Nom)
.Select(joueur => new JoueurClassementAlphabet(joueur, MauiProgram.Manager));
}
public CTableauScore()
{
InitializeComponent();
}
}
public void UpdateClassement(Func<IEnumerable<object>> getClassement)
{
BindingContext = getClassement();
}
}

@ -10,7 +10,7 @@ namespace UnitTesting
[Fact]
public void TestConstructeurValide()
{
Joueur monJoueur = new Joueur("Céleste", new Plateau(4, 12));
Joueur monJoueur = new Joueur("Céleste");
AjouterJoueursEventArgs evenement = new AjouterJoueursEventArgs(monJoueur);

@ -7,13 +7,38 @@ namespace UnitTesting
public class JoueurUT
{
[Fact]
public void TestConstructeurValide()
public void TestConstructeur1Valide()
{
Plateau plateau = new Plateau(4, 10);
Joueur joueur = new Joueur("MonJoueur", plateau);
string nom = "toto";
Assert.Equal("MonJoueur", joueur.Nom);
Assert.Equal(plateau, joueur.Plateau);
Joueur joueur = new Joueur(nom);
Assert.Equal(nom, joueur.Nom);
Assert.Equal(0, joueur.NbCoutTotal);
Assert.Equal(0, joueur.NbPartieGagnee);
Assert.Equal(0, joueur.NbPartieEgalite);
Assert.Equal(0, joueur.NbPartiePerdue);
}
[Fact]
public void TestConstructeur2Valide()
{
string nom = "Bob";
int nbCoutTotal = 10;
int nbPartieGagnee = 5;
int nbPartieEgalite = 2;
int nbPartiePerdue = 3;
Joueur joueur = new Joueur(nom, nbCoutTotal, nbPartieGagnee, nbPartieEgalite, nbPartiePerdue);
Assert.Equal(nom, joueur.Nom);
Assert.Equal(nbCoutTotal, joueur.NbCoutTotal);
Assert.Equal(nbPartieGagnee, joueur.NbPartieGagnee);
Assert.Equal(nbPartieEgalite, joueur.NbPartieEgalite);
Assert.Equal(nbPartiePerdue, joueur.NbPartiePerdue);
}
}
}

@ -11,7 +11,7 @@ namespace UnitTesting
public void TestConstructeurValide()
{
Plateau monPlateau = new Plateau(4, 12);
Joueur monJoueur = new Joueur("Céleste", monPlateau);
Joueur monJoueur = new Joueur("Céleste");
NouveauTourEventArgs evenement =
new NouveauTourEventArgs(monJoueur, 5, monPlateau.Grille(), monPlateau.Indicateurs());

@ -11,8 +11,8 @@ namespace UnitTesting
public void TestConstructeurValide()
{
Plateau plateau = new Plateau(4, 12);
Joueur[] gagnants = [new Joueur("Pauline", plateau), new Joueur("Camille", plateau)];
Joueur[] perdants = [new Joueur("Céleste", plateau)];
Joueur[] gagnants = [new Joueur("Pauline"), new Joueur("Camille")];
Joueur[] perdants = [new Joueur("Céleste")];
PartieTermineeEventArgs evenement = new PartieTermineeEventArgs(gagnants, perdants);

@ -52,14 +52,14 @@ namespace UnitTesting
regles.CommencerLaPartie();
int? joueurCourantAvant = (int?) fieldInfo.GetValue(regles);
Joueur courantAvant = regles.JoueurCourant();
Joueur courantAvant = regles.JoueurCourant().Item1;
Assert.NotNull(joueurCourantAvant);
Assert.Equal(0, joueurCourantAvant);
regles.PasserLaMain();
int? joueurCourantApres = (int?)fieldInfo.GetValue(regles);
Joueur courantApres = regles.JoueurCourant();
Joueur courantApres = regles.JoueurCourant().Item1;
Assert.NotNull(joueurCourantApres);
Assert.Equal(1, joueurCourantApres);
Assert.NotEqual(joueurCourantAvant, joueurCourantApres);
@ -68,7 +68,7 @@ namespace UnitTesting
regles.PasserLaMain();
int? joueurCourantBoucle = (int?)fieldInfo.GetValue(regles);
Joueur courantBoucle = regles.JoueurCourant();
Joueur courantBoucle = regles.JoueurCourant().Item1;
Assert.NotNull(joueurCourantBoucle);
Assert.Equal(0, joueurCourantBoucle);
Assert.NotEqual(joueurCourantApres, joueurCourantBoucle);
@ -103,7 +103,7 @@ namespace UnitTesting
regles.PasserLaMain();
Plateau plateauj1 = regles.JoueurCourant().Plateau;
Plateau plateauj1 = regles.JoueurCourant().Item2;
type = typeof(Plateau);
fieldInfo = type.GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
@ -112,7 +112,7 @@ namespace UnitTesting
Code? codeSecret = (Code?)fieldInfo.GetValue(plateauj1);
Assert.NotNull(codeSecret);
regles.JoueurCourant().Plateau.AjouterCode(codeSecret);
regles.JoueurCourant().Item2.AjouterCode(codeSecret);
bool estTerminee = regles.EstTerminee();
@ -132,7 +132,7 @@ namespace UnitTesting
regles.CommencerLaPartie();
Plateau plateauj1 = regles.JoueurCourant().Plateau;
Plateau plateauj1 = regles.JoueurCourant().Item2;
Type type = typeof(Plateau);
FieldInfo? fieldInfo = type.GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
@ -140,10 +140,10 @@ namespace UnitTesting
Code? codeSecret = (Code?)fieldInfo.GetValue(plateauj1);
Assert.NotNull(codeSecret);
regles.JoueurCourant().Plateau.AjouterCode(codeSecret);
regles.JoueurCourant().Item2.AjouterCode(codeSecret);
IEnumerable<Joueur> gagnants = regles.Gagnants();
Assert.Single(gagnants);
Assert.Contains(regles.JoueurCourant(), gagnants);
Assert.Contains(regles.JoueurCourant().Item1, gagnants);
}
}
}

Loading…
Cancel
Save