diff --git a/Sources/CoreLibrary/Core/Code.cs b/Sources/CoreLibrary/Core/Code.cs
index 6779602..33b2ea2 100644
--- a/Sources/CoreLibrary/Core/Code.cs
+++ b/Sources/CoreLibrary/Core/Code.cs
@@ -1,12 +1,23 @@
using CoreLibrary.Exceptions;
+using System.ComponentModel;
namespace CoreLibrary.Core
{
///
/// Classe représentant un code composé de jetons et ses différentes méthodes.
///
- public class Code
+ public class Code : INotifyPropertyChanged
{
+ public event PropertyChangedEventHandler? PropertyChanged;
+
+ void OnPropertyChanged(string propertyName)
+ {
+ if (PropertyChanged != null)
+ {
+ PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+
private readonly Jeton?[] lesJetons;
///
@@ -14,6 +25,8 @@ namespace CoreLibrary.Core
///
public int NbJetons { get; private set; } = 0;
+ public IEnumerable Jetons => lesJetons;
+
///
/// Initialise une nouvelle instance de la classe avec la longueur de code spécifiée.
///
@@ -61,6 +74,7 @@ namespace CoreLibrary.Core
}
lesJetons[NbJetons++] = jeton;
+ OnPropertyChanged(nameof(Jetons));
}
///
@@ -75,6 +89,7 @@ namespace CoreLibrary.Core
}
lesJetons[--NbJetons] = null;
+ OnPropertyChanged(nameof(Jetons));
}
///
@@ -96,16 +111,6 @@ namespace CoreLibrary.Core
return jeton.Value;
}
- ///
- /// Récupère une liste des jetons dans le code.
- ///
- /// Les jetons du code.
- public IEnumerable Jetons()
- {
- return lesJetons;
- }
-
-
///
/// Vérifie si le code est complet.
///
@@ -138,8 +143,8 @@ namespace CoreLibrary.Core
if (!autreCode.EstComplet())
return indicateurs;
- List mesJetons = new List(Jetons());
- List sesJetons = new List(autreCode.Jetons());
+ List mesJetons = new List(Jetons);
+ List sesJetons = new List(autreCode.Jetons);
for (int i = 0; i < mesJetons.Count; ++i)
{
diff --git a/Sources/CoreLibrary/Core/Plateau.cs b/Sources/CoreLibrary/Core/Plateau.cs
index be3e9c5..394b12f 100644
--- a/Sources/CoreLibrary/Core/Plateau.cs
+++ b/Sources/CoreLibrary/Core/Plateau.cs
@@ -149,7 +149,7 @@ namespace CoreLibrary.Core
for (int i = 0; i < grille.Length; ++i)
{
- grilleJetons[i] = grille[i]?.Jetons() ?? new Code(tailleCode).Jetons();
+ grilleJetons[i] = grille[i]?.Jetons ?? new Code(tailleCode).Jetons;
}
return grilleJetons;
}
diff --git a/Sources/CoreLibrary/Joueurs/Joueur.cs b/Sources/CoreLibrary/Joueurs/Joueur.cs
index 201b9f8..ba6ffb4 100644
--- a/Sources/CoreLibrary/Joueurs/Joueur.cs
+++ b/Sources/CoreLibrary/Joueurs/Joueur.cs
@@ -55,5 +55,10 @@ namespace CoreLibrary.Joueurs
{
QuandJouerCode(code);
}
+
+ public override String ToString()
+ {
+ return Nom;
+ }
}
}
diff --git a/Sources/CoreLibrary/Partie.cs b/Sources/CoreLibrary/Partie.cs
index bf7c2e9..b892ee9 100644
--- a/Sources/CoreLibrary/Partie.cs
+++ b/Sources/CoreLibrary/Partie.cs
@@ -157,15 +157,15 @@ namespace CoreLibrary
plateauCourant.AjouterCode(e.Code);
QuandAjouterCode(e.Code);
- if(Regles.EstTerminee())
+ Regles.PasserLaMain();
+ QuandPasserMain();
+
+ if (Regles.EstTerminee())
{
Terminee();
}
else
{
- Regles.PasserLaMain();
- QuandPasserMain();
-
(joueurCourant, plateauCourant) = Regles.JoueurCourant();
QuandNouveauTour(joueurCourant, plateauCourant.Tour, Regles.GenererCode(), plateauCourant.Grille(), plateauCourant.Indicateurs());
}
diff --git a/Sources/MauiSpark/Convertisseurs/CouleurVersCouleurMAUI.cs b/Sources/MauiSpark/Convertisseurs/CouleurVersCouleurMAUI.cs
new file mode 100644
index 0000000..13b47b1
--- /dev/null
+++ b/Sources/MauiSpark/Convertisseurs/CouleurVersCouleurMAUI.cs
@@ -0,0 +1,59 @@
+using CoreLibrary.Core;
+using System.Globalization;
+
+namespace MauiSpark.Convertisseurs
+{
+ public class CouleurVersCouleurMAUI : IValueConverter
+ {
+ public static Color Rouge { get; private set; } = Color.FromRgb(255, 0, 0);
+ public static Color Vert { get; private set; } = Color.FromRgb(0, 255, 0);
+ public static Color Bleu { get; private set; } = Color.FromRgb(0, 0, 255);
+ public static Color Jaune { get; private set; } = Color.FromRgb(255, 255, 0);
+ public static Color Noir { get; private set; } = Color.FromRgb(0, 0, 0);
+ public static Color Blanc { get; private set; } = Color.FromRgb(255, 255, 255);
+
+
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is not Couleur) return Noir;
+
+ switch (value)
+ {
+ case Couleur.BLANC:
+ return Blanc;
+ case Couleur.BLEU:
+ return Bleu;
+ case Couleur.VERT:
+ return Vert;
+ case Couleur.ROUGE:
+ return Rouge;
+ case Couleur.NOIR:
+ return Noir;
+ case Couleur.JAUNE:
+ return Jaune;
+ default:
+ return Noir;
+ }
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is not Color) return Couleur.NOIR;
+
+ if (value.Equals(Rouge))
+ return Couleur.ROUGE;
+ if (value.Equals(Vert))
+ return Couleur.VERT;
+ if (value.Equals(Bleu))
+ return Couleur.BLEU;
+ if (value.Equals(Jaune))
+ return Couleur.JAUNE;
+ if (value.Equals(Noir))
+ return Couleur.NOIR;
+ if (value.Equals(Blanc))
+ return Couleur.BLANC;
+
+ return Couleur.NOIR;
+ }
+ }
+}
diff --git a/Sources/MauiSpark/Convertisseurs/IndicateurVersCouleurMAUI.cs b/Sources/MauiSpark/Convertisseurs/IndicateurVersCouleurMAUI.cs
new file mode 100644
index 0000000..834e793
--- /dev/null
+++ b/Sources/MauiSpark/Convertisseurs/IndicateurVersCouleurMAUI.cs
@@ -0,0 +1,29 @@
+using CoreLibrary.Core;
+using System.Globalization;
+
+namespace MauiSpark.Convertisseurs
+{
+ public class IndicateurVersCouleurMAUI : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is not Indicateur) return "black";
+
+ switch (value)
+ {
+ case Indicateur.BONNEPLACE:
+ return "black";
+ case Indicateur.BONNECOULEUR:
+ return "white";
+ default:
+ return "black";
+ }
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+}
diff --git a/Sources/MauiSpark/Convertisseurs/JetonVersTexte.cs b/Sources/MauiSpark/Convertisseurs/JetonVersTexte.cs
new file mode 100644
index 0000000..1bbf8b7
--- /dev/null
+++ b/Sources/MauiSpark/Convertisseurs/JetonVersTexte.cs
@@ -0,0 +1,25 @@
+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();
+ }
+ }
+}
diff --git a/Sources/MauiSpark/Pages/Accueil.xaml.cs b/Sources/MauiSpark/Pages/Accueil.xaml.cs
index 827689f..dec0cd7 100644
--- a/Sources/MauiSpark/Pages/Accueil.xaml.cs
+++ b/Sources/MauiSpark/Pages/Accueil.xaml.cs
@@ -1,16 +1,17 @@
-using CoreLibrary;
-
-namespace MauiSpark.Pages;
-
-public partial class Accueil : ContentPage
-{
- public Accueil()
- {
- InitializeComponent();
- }
-
+namespace MauiSpark.Pages;
+
+public partial class Accueil : ContentPage
+{
+ public Accueil()
+ {
+ NavigationPage.SetHasBackButton(this, false);
+ NavigationPage.SetHasNavigationBar(this, false);
+
+ InitializeComponent();
+ }
+
private void QuandJouerClique(Object? sender, EventArgs e)
{
Navigation.PushAsync(new Mode());
- }
+ }
}
\ No newline at end of file
diff --git a/Sources/MauiSpark/Pages/ConnexionPage.xaml.cs b/Sources/MauiSpark/Pages/ConnexionPage.xaml.cs
index 3a47341..a0cafeb 100644
--- a/Sources/MauiSpark/Pages/ConnexionPage.xaml.cs
+++ b/Sources/MauiSpark/Pages/ConnexionPage.xaml.cs
@@ -1,34 +1,56 @@
-using CoreLibrary;
-using CoreLibrary.Events;
-using CoreLibrary.Joueurs;
-
-namespace MauiSpark.Pages;
-
-
-public partial class ConnexionPage : ContentPage
-{
- private readonly JoueurBuilder joueurBuilder;
-
- public ConnexionPage(Partie partie, DemanderNomEventArgs e)
- {
- InitializeComponent();
+using CoreLibrary;
+using CoreLibrary.Events;
+using CoreLibrary.Joueurs;
+
+namespace MauiSpark.Pages;
+
+
+public partial class ConnexionPage : ContentPage
+{
+ private readonly JoueurBuilder joueurBuilder;
+
+ public ConnexionPage(Partie partie, DemanderNomEventArgs e)
+ {
+ NavigationPage.SetHasBackButton(this, false);
+ NavigationPage.SetHasNavigationBar(this, false);
+
+ InitializeComponent();
joueurBuilder = e.JoueurBuilder;
- if(partie.Regles.NbJoueurs + 1 == partie.Regles.NbJoueursMaximum)
+ if (partie.Regles.NbJoueurs + 1 == partie.Regles.NbJoueursMaximum)
+ {
partie.NouveauTour += QuandNouveauTour;
+ partie.PartieTerminee += PartieTerminee;
+ }
BindingContext = $"Joueur {e.Indice}";
- }
-
- private void QuandNouveauTour(object sender, NouveauTourEventArgs e)
+ }
+
+ private void QuandNouveauTour(object? sender, NouveauTourEventArgs e)
{
if (sender != null && sender is Partie)
Navigation.PushAsync(new Plateau(sender as Partie, e));
- }
-
+ }
+
private void QuandSeConnecterPresse(Object sender, EventArgs e)
{
joueurBuilder.Joueur(new Joueur(Nom.Text));
- }
+ }
+
+ private void PartieTerminee(Object? sender, PartieTermineeEventArgs e)
+ {
+ if(e.Gagnants.Count() == 0)
+ {
+ Navigation.PushAsync(new Defaite((Partie) sender, e));
+ }
+ else if (e.Gagnants.Count() == 2)
+ {
+ Navigation.PushAsync(new Egalite());
+ }
+ else
+ {
+ Navigation.PushAsync(new Victoire((Partie)sender, e));
+ }
+ }
}
\ No newline at end of file
diff --git a/Sources/MauiSpark/Pages/Defaite.xaml b/Sources/MauiSpark/Pages/Defaite.xaml
index ce82fa5..831c89a 100644
--- a/Sources/MauiSpark/Pages/Defaite.xaml
+++ b/Sources/MauiSpark/Pages/Defaite.xaml
@@ -13,7 +13,7 @@
-
+
diff --git a/Sources/MauiSpark/Pages/Defaite.xaml.cs b/Sources/MauiSpark/Pages/Defaite.xaml.cs
index f7bea5f..cee0d7b 100644
--- a/Sources/MauiSpark/Pages/Defaite.xaml.cs
+++ b/Sources/MauiSpark/Pages/Defaite.xaml.cs
@@ -1,9 +1,14 @@
+using CoreLibrary;
+using CoreLibrary.Events;
+
namespace MauiSpark.Pages;
public partial class Defaite : ContentPage
{
- public Defaite()
+ public Defaite(Partie p, PartieTermineeEventArgs e)
{
InitializeComponent();
+
+ BindingContext = $"Aucun des deux joueurs, {e.Perdants.First().Nom} et {e.Perdants.Last().Nom} n'a trouvé le code secret";
}
}
\ No newline at end of file
diff --git a/Sources/MauiSpark/Pages/Mode.xaml.cs b/Sources/MauiSpark/Pages/Mode.xaml.cs
index 721e910..bc58cf3 100644
--- a/Sources/MauiSpark/Pages/Mode.xaml.cs
+++ b/Sources/MauiSpark/Pages/Mode.xaml.cs
@@ -8,7 +8,10 @@ public partial class Mode : ContentPage
{
public Mode()
{
- InitializeComponent();
+ NavigationPage.SetHasBackButton(this, false);
+ NavigationPage.SetHasNavigationBar(this, false);
+
+ InitializeComponent();
}
private void QuandReglesClassiques(Object? sender, EventArgs e)
diff --git a/Sources/MauiSpark/Pages/Plateau.xaml b/Sources/MauiSpark/Pages/Plateau.xaml
index 9471507..60e72d8 100644
--- a/Sources/MauiSpark/Pages/Plateau.xaml
+++ b/Sources/MauiSpark/Pages/Plateau.xaml
@@ -1,8 +1,151 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Sources/MauiSpark/Pages/Plateau.xaml.cs b/Sources/MauiSpark/Pages/Plateau.xaml.cs
index 7a25c39..8dcf8c6 100644
--- a/Sources/MauiSpark/Pages/Plateau.xaml.cs
+++ b/Sources/MauiSpark/Pages/Plateau.xaml.cs
@@ -1,15 +1,90 @@
using CoreLibrary;
+using CoreLibrary.Core;
using CoreLibrary.Events;
+using CoreLibrary.Exceptions;
+using CoreLibrary.Joueurs;
+using MauiSpark.Convertisseurs;
namespace MauiSpark.Pages;
+internal class Tour
+{
+ public IEnumerable<(IEnumerable, IEnumerable)> Plateau { get; private init; }
+ public Joueur Joueur { get; private init; }
+ public string Numero { get; private init; }
+ public Code Code { get; private init; }
+
+ public Tour(NouveauTourEventArgs e)
+ {
+ Numero = $"Tour {e.Tour}";
+ Joueur = e.Joueur;
+ Code = e.Code;
+
+ (IEnumerable, IEnumerable)[] plateau = new (IEnumerable, IEnumerable)[e.Grille.Count()];
+ for (int i = 0; i < e.Grille.Count(); ++i)
+ {
+ plateau[i] = (e.Grille.ElementAt(i).Where(x => x.HasValue).Select(x => x!.Value), e.Indicateurs.ElementAt(i));
+ }
+ Plateau = plateau;
+ }
+}
+
+
public partial class Plateau : ContentPage
{
+ private readonly Code code;
+ private readonly Joueur joueur;
+
public Plateau(Partie p, NouveauTourEventArgs e)
{
+ NavigationPage.SetHasBackButton(this, false);
+ NavigationPage.SetHasNavigationBar(this, false);
+
InitializeComponent();
- BindingContext = e;
+ code = e.Code;
+ joueur = e.Joueur;
+
+ BindingContext = new Tour(e);
+ }
+
+ private void CouleurPresee(Object sender, EventArgs e)
+ {
+ Label label = (Label)sender;
+ Couleur couleur = (Couleur)new CouleurVersCouleurMAUI().ConvertBack(label.TextColor, null, null, null);
+
+ try
+ {
+ code.AjouterJeton(new Jeton(couleur));
+ }
+ catch (CodeCompletException ignored)
+ {
+ DisplayAlert("Attention", "La code est plein", "OK");
+ }
+ }
+
+ private void SupprimerDernierJeton(Object sender, EventArgs e)
+ {
+ try
+ {
+ code.SupprimerDernierJeton();
+ }
+ catch(CodeVideException ignored)
+ {
+ DisplayAlert("Attention", "La code est vide", "OK");
+ }
+ }
+
+ private void ValiderCode(Object sender, EventArgs e)
+ {
+ try
+ {
+ joueur.Code(code);
+ }
+ catch (CodeIncompletException ignored)
+ {
+ DisplayAlert("Attention", "La code n'est pas complet", "OK");
+ }
}
}
\ No newline at end of file
diff --git a/Sources/MauiSpark/Pages/Victoire.xaml b/Sources/MauiSpark/Pages/Victoire.xaml
index f8425d8..11d5aa2 100644
--- a/Sources/MauiSpark/Pages/Victoire.xaml
+++ b/Sources/MauiSpark/Pages/Victoire.xaml
@@ -13,7 +13,7 @@
-
+
diff --git a/Sources/MauiSpark/Pages/Victoire.xaml.cs b/Sources/MauiSpark/Pages/Victoire.xaml.cs
index c36b984..c964b14 100644
--- a/Sources/MauiSpark/Pages/Victoire.xaml.cs
+++ b/Sources/MauiSpark/Pages/Victoire.xaml.cs
@@ -1,9 +1,14 @@
+using CoreLibrary;
+using CoreLibrary.Events;
+
namespace MauiSpark.Pages;
public partial class Victoire : ContentPage
{
- public Victoire()
+ public Victoire(Partie partie, PartieTermineeEventArgs e)
{
InitializeComponent();
- }
+
+ BindingContext = $"Le joueur {e.Gagnants.First().Nom} a gagné";
+ }
}
\ No newline at end of file