master
Pauline PRADY 11 months ago
commit 6cfb2056e9

@ -1,7 +1,4 @@
using CoreLibrary.Core; namespace CoreLibrary.Joueurs
using CoreLibrary.Events;
namespace CoreLibrary.Joueurs
{ {
/// <summary> /// <summary>
/// Classe représentant un joueur. /// Classe représentant un joueur.
@ -13,12 +10,13 @@ namespace CoreLibrary.Joueurs
/// </summary> /// </summary>
public string Nom { get; private init; } public string Nom { get; private init; }
/// <summary> public int NbCoutTotal { get; set; }
/// Le plateau du joueur. public int NbPartieGagnee { get; set; }
/// </summary> public int NbPartieEgalite { get; set; }
public Plateau Plateau { get; private init; } public int NbPartiePerdue { get; set; }
/// <summary> /// <summary>
/// Crée une nouvelle instance de joueur avec un nom
/// Evénement appelé pour jouer un code. /// Evénement appelé pour jouer un code.
/// </summary> /// </summary>
public event EventHandler<JouerCodeEventArgs>? JouerCode; 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é. /// Crée une nouvelle instance de joueur avec un nom et un plateau spécifié.
/// </summary> /// </summary>
/// <param name="nom">Le nom du joueur.</param> /// <param name="nom">Le nom du joueur.</param>
/// <param name="plateau">Le plateau du joueur.</param> public Joueur(string nom)
public Joueur(string nom, Plateau plateau) {
Nom = nom;
NbCoutTotal = 0;
NbPartieGagnee = 0;
NbPartieEgalite = 0;
NbPartiePerdue = 0;
}
public Joueur(string nom, int nbCoutTotal, int nbPartieGagnee, int nbPartieEgalite, int nbPartiePerdue)
{ {
Nom = nom; 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. /// Récupère le joueur courant.
/// </summary> /// </summary>
/// <returns>Le joueur courant.</returns> /// <returns>Le joueur courant.</returns>
Joueur JoueurCourant(); (Joueur, Plateau) JoueurCourant();
/// <summary> /// <summary>
/// Passe la main au joueur suivant. /// Passe la main au joueur suivant.

@ -12,6 +12,7 @@ namespace CoreLibrary.Regles
private int nbJoueurs = 0; private int nbJoueurs = 0;
private int? joueurCourant; private int? joueurCourant;
private readonly Joueur[] joueurs; private readonly Joueur[] joueurs;
private readonly Plateau[] plateaux;
/// <summary> /// <summary>
/// Le nom des règles. /// Le nom des règles.
@ -46,6 +47,7 @@ namespace CoreLibrary.Regles
public ReglesClassiques() public ReglesClassiques()
{ {
joueurs = new Joueur[NbJoueursMaximum]; joueurs = new Joueur[NbJoueursMaximum];
plateaux = new Plateau[NbJoueursMaximum];
} }
/// <summary> /// <summary>
@ -55,8 +57,9 @@ namespace CoreLibrary.Regles
/// <returns>Le joueur ajouté.</returns> /// <returns>Le joueur ajouté.</returns>
public Joueur AjouterJoueur(string nom) public Joueur AjouterJoueur(string nom)
{ {
Joueur joueur = new Joueur(nom, new Plateau(TailleCodeMaximum, TourMaximum)); Joueur joueur = new Joueur(nom);
joueurs[nbJoueurs++] = joueur; joueurs[nbJoueurs] = joueur;
plateaux[nbJoueurs++] = new Plateau(TailleCodeMaximum, TourMaximum);
return joueur; return joueur;
} }
@ -66,12 +69,12 @@ namespace CoreLibrary.Regles
/// <returns>Le joueur actuel.</returns> /// <returns>Le joueur actuel.</returns>
/// <exception cref="PartieNonCommenceeException">Levée lorsque la partie n'a pas commencée.</exception> /// <exception cref="PartieNonCommenceeException">Levée lorsque la partie n'a pas commencée.</exception>
public Joueur JoueurCourant() public (Joueur, Plateau) JoueurCourant()
{ {
if (!joueurCourant.HasValue) if (!joueurCourant.HasValue)
throw new PartieNonCommenceeException(); throw new PartieNonCommenceeException();
return joueurs[joueurCourant.Value]; return (joueurs[joueurCourant.Value], plateaux[joueurCourant.Value]);
} }
/// <summary> /// <summary>
@ -120,12 +123,12 @@ namespace CoreLibrary.Regles
if (!joueurCourant.HasValue || joueurCourant != 0) if (!joueurCourant.HasValue || joueurCourant != 0)
return false; return false;
if (JoueurCourant().Plateau.Tour > TourMaximum) if (JoueurCourant().Item2.Tour > TourMaximum)
return true; return true;
for (int i = 0; i < joueurs.Length; ++i) for (int i = 0; i < joueurs.Length; ++i)
{ {
if (joueurs[i].Plateau.Victoire) if (plateaux[i].Victoire)
return true; return true;
} }
@ -141,7 +144,7 @@ namespace CoreLibrary.Regles
Joueur[] gagnants = []; Joueur[] gagnants = [];
for (int i = 0; i < joueurs.Length; ++i) for (int i = 0; i < joueurs.Length; ++i)
{ {
if (joueurs[i].Plateau.Victoire) if (plateaux[i].Victoire)
{ {
gagnants = gagnants.Append(joueurs[i]).ToArray(); gagnants = gagnants.Append(joueurs[i]).ToArray();
} }
@ -159,7 +162,7 @@ namespace CoreLibrary.Regles
Joueur[] perdants = []; Joueur[] perdants = [];
for (int i = 0; i < joueurs.Length; ++i) for (int i = 0; i < joueurs.Length; ++i)
{ {
if (!joueurs[i].Plateau.Victoire) if (!plateaux[i].Victoire)
{ {
perdants = perdants.Append(joueurs[i]).ToArray(); perdants = perdants.Append(joueurs[i]).ToArray();
} }

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

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

@ -18,25 +18,18 @@
</Grid> </Grid>
</FlexLayout> </FlexLayout>
<Frame Margin="20" > <Frame Margin="20" >
<Grid ColumnDefinitions="auto,*,auto,auto" ColumnSpacing="10"> <Grid ColumnDefinitions="auto,auto,*,auto,auto,auto,auto" RowDefinitions="1,*,1" RowSpacing="0" ColumnSpacing="10" >
<Button Margin="0,5,5,5" Grid.Column="0" Text="RANK" Style="{StaticResource ButtonTableau}"></Button> <Label Margin="5" Grid.Column="0" Grid.Row="1" Text="RANK" Style="{StaticResource ButtonTableau}" VerticalOptions="Center"></Label>
<Button Margin="5" Grid.Column="1" Text="PSEUDO" Style="{StaticResource ButtonTableau}" HorizontalOptions="Start" ></Button> <Label Margin="5" Grid.Column="1" Grid.Row="1" Text="PSEUDO" Style="{StaticResource ButtonTableau}" VerticalOptions="Center"></Label>
<Button Margin="5" Grid.Column="2" Text="Nombre de coût Moyen" Style="{StaticResource ButtonTableau}"></Button> <Button Margin="0" Grid.Column="2" Grid.Row="0" Text="+" Style="{StaticResource ButtonTableau}" VerticalOptions="Center" HorizontalOptions="Start" Clicked="QuandAlphabetHautButtonClicked" ></Button>
<Button Margin="5" Grid.Column="3" Text="POINT" Style="{StaticResource ButtonTableau}"></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> </Grid>
</Frame> </Frame>
<views:CTableauScore/> <views:CTableauScore x:Name="CTableauScore"/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
<views:CTableauScore/>
</VerticalStackLayout> </VerticalStackLayout>
</ScrollView> </ScrollView>

@ -1,9 +1,48 @@
using CoreLibrary.Joueurs;
using MauiSpark.Views;
using System.Collections.ObjectModel;
namespace MauiSpark.Pages; namespace MauiSpark.Pages;
public partial class TableauScore : ContentPage public partial class TableauScore : ContentPage
{ {
public TableauScore() public TableauScore()
{ {
InitializeComponent(); 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);
}
} }

@ -2,13 +2,22 @@
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiSpark.Views.CTableauScore"> x:Class="MauiSpark.Views.CTableauScore">
<Frame CornerRadius="5" Padding="0" VerticalOptions="Start" Margin="20,0,20,10" > <Frame CornerRadius="5" Padding="0" VerticalOptions="Start" Margin="20,0,20,10" >
<Grid ColumnDefinitions="auto,*,auto,auto" ColumnSpacing="10"> <ListView ItemsSource="{Binding}">
<Label Grid.Column="0" Text="N°1" Margin="20" Style="{StaticResource TexteFrame}" /> <ListView.ItemTemplate>
<Label Grid.Column="1" Text="Joueur 1" Margin="20" Style="{StaticResource TexteFrame}" /> <DataTemplate>
<Label Grid.Column="2" Text="5" Margin="20" Style="{StaticResource TexteFrame}" /> <ViewCell>
<Label Grid.Column="3" Text="10000" Margin="20" Style="{StaticResource TexteFrame}"/> <Grid ColumnDefinitions="auto,*,auto,auto,auto,auto">
</Grid> <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> </Frame>
</ContentView> </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; namespace MauiSpark.Views;
public partial class CTableauScore : ContentView 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
{ {
public CTableauScore() 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(); InitializeComponent();
} }
public void UpdateClassement(Func<IEnumerable<object>> getClassement)
{
BindingContext = getClassement();
}
} }

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

@ -7,13 +7,38 @@ namespace UnitTesting
public class JoueurUT public class JoueurUT
{ {
[Fact] [Fact]
public void TestConstructeurValide() public void TestConstructeur1Valide()
{ {
Plateau plateau = new Plateau(4, 10); string nom = "toto";
Joueur joueur = new Joueur("MonJoueur", plateau);
Assert.Equal("MonJoueur", joueur.Nom); Joueur joueur = new Joueur(nom);
Assert.Equal(plateau, joueur.Plateau);
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() public void TestConstructeurValide()
{ {
Plateau monPlateau = new Plateau(4, 12); Plateau monPlateau = new Plateau(4, 12);
Joueur monJoueur = new Joueur("Céleste", monPlateau); Joueur monJoueur = new Joueur("Céleste");
NouveauTourEventArgs evenement = NouveauTourEventArgs evenement =
new NouveauTourEventArgs(monJoueur, 5, monPlateau.Grille(), monPlateau.Indicateurs()); new NouveauTourEventArgs(monJoueur, 5, monPlateau.Grille(), monPlateau.Indicateurs());

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

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

Loading…
Cancel
Save