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 @@ -