diff --git a/Sources/CoreLibrary/Manageur/Manageur.cs b/Sources/CoreLibrary/Manageur/Manageur.cs index 1d594b1..ef9ff11 100644 --- a/Sources/CoreLibrary/Manageur/Manageur.cs +++ b/Sources/CoreLibrary/Manageur/Manageur.cs @@ -1,14 +1,20 @@ using CoreLibrary.Events; using CoreLibrary.Joueurs; using CoreLibrary.Persistance; +using System.Collections.Generic; namespace CoreLibrary.Manager { public class Manageur { - public List joueurs; - public List parties; - private IPersistance persistance; + private readonly List joueurs; + private readonly List parties; + private readonly IPersistance persistance; + private Partie? partie; + + public IReadOnlyCollection Joueurs => joueurs; + public IReadOnlyCollection Parties => parties; + public Partie? Partie => partie; public Manageur(IPersistance persistance) { @@ -19,6 +25,8 @@ namespace CoreLibrary.Manager public void NouvellePartie(Partie partie) { + this.partie = partie; + parties.Add(partie); partie.PasserMain += (object? sender, PasserMainEventArgs e) => diff --git a/Sources/MauiSpark/Convertisseurs/CouleurVersCouleurMAUI.cs b/Sources/MauiSpark/Convertisseurs/CouleurVersCouleurMAUI.cs index deaae35..1217388 100644 --- a/Sources/MauiSpark/Convertisseurs/CouleurVersCouleurMAUI.cs +++ b/Sources/MauiSpark/Convertisseurs/CouleurVersCouleurMAUI.cs @@ -15,7 +15,8 @@ namespace MauiSpark.Convertisseurs public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { - if (value is not Couleur) return Noir; + if (value is not Couleur) + return Noir; switch (value) { diff --git a/Sources/MauiSpark/Pages/PlateauPage.xaml b/Sources/MauiSpark/Pages/PlateauPage.xaml index 7491d88..382be81 100644 --- a/Sources/MauiSpark/Pages/PlateauPage.xaml +++ b/Sources/MauiSpark/Pages/PlateauPage.xaml @@ -12,123 +12,120 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - + \ No newline at end of file diff --git a/Sources/MauiSpark/Pages/PlateauPage.xaml.cs b/Sources/MauiSpark/Pages/PlateauPage.xaml.cs index 1367b3c..6c14c0c 100644 --- a/Sources/MauiSpark/Pages/PlateauPage.xaml.cs +++ b/Sources/MauiSpark/Pages/PlateauPage.xaml.cs @@ -1,10 +1,7 @@ -using CoreLibrary; using CoreLibrary.Core; using CoreLibrary.Events; using CoreLibrary.Exceptions; using CoreLibrary.Joueurs; -using MauiSpark.Convertisseurs; -using System.Globalization; namespace MauiSpark.Pages; @@ -68,22 +65,6 @@ public partial class PlateauPage : ContentPage BindingContext = new Tour(e); } - private void CouleurPresee(Object sender, EventArgs e) - { - Label label = (Label)sender; - Couleur couleur = (Couleur)new CouleurVersCouleurMAUI().ConvertBack(label.TextColor, typeof(Couleur), null, CultureInfo.InvariantCulture); - - try - { - if(code != null) - code.AjouterJeton(new Jeton(couleur)); - } - catch (CodeCompletException) - { - DisplayAlert("Attention", "La code est plein", "OK"); - } - } - private void SupprimerDernierJeton(Object sender, EventArgs e) { try diff --git a/Sources/MauiSpark/Views/CTableauScore.xaml.cs b/Sources/MauiSpark/Views/CTableauScore.xaml.cs index 05262e1..866c917 100644 --- a/Sources/MauiSpark/Views/CTableauScore.xaml.cs +++ b/Sources/MauiSpark/Views/CTableauScore.xaml.cs @@ -15,7 +15,7 @@ public class JoueurClassementNbCoupParPartie } public int Place { - get => manageur.joueurs + get => manageur.Joueurs .OrderBy(joueur => joueur.NbCoutTotal/(joueur.NbPartiePerdue+joueur.NbPartieGagnee+joueur.NbPartieEgalite)).ToList() .IndexOf(Joueur) + 1; } @@ -42,7 +42,7 @@ public class JoueurClassementPartieGagnee public int Place { - get => manageur.joueurs.OrderByDescending(joueur => joueur.NbPartieGagnee).ToList().IndexOf(Joueur) + 1; + get => manageur.Joueurs.OrderByDescending(joueur => joueur.NbPartieGagnee).ToList().IndexOf(Joueur) + 1; } public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite); @@ -67,7 +67,7 @@ public class JoueurClassementPartieEgalite public int Place { - get => manageur.joueurs.OrderByDescending(joueur => joueur.NbPartieEgalite).ToList().IndexOf(joueur)+1; + get => manageur.Joueurs.OrderByDescending(joueur => joueur.NbPartieEgalite).ToList().IndexOf(joueur)+1; } public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite); @@ -92,7 +92,7 @@ public class JoueurClassementPartiePerdue public int Place { - get => manageur.joueurs.OrderByDescending(joueur => joueur.NbPartiePerdue).ToList().IndexOf(joueur)+1; + get => manageur.Joueurs.OrderByDescending(joueur => joueur.NbPartiePerdue).ToList().IndexOf(joueur)+1; } public int NbCoutMoyen => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite); @@ -117,7 +117,7 @@ public class JoueurClassementAlphabet public int Place { - get => manageur.joueurs + get => manageur.Joueurs .OrderBy(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite)).ToList() .IndexOf(Joueur) + 1; } @@ -140,7 +140,7 @@ public partial class CTableauScore : ContentView if(NbClique % 2 == 0) { NbClique++; - return MauiProgram.Manageur.joueurs + return MauiProgram.Manageur.Joueurs .OrderBy(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite)) .Select(joueur => new JoueurClassementNbCoupParPartie(joueur, MauiProgram.Manageur)); @@ -148,7 +148,7 @@ public partial class CTableauScore : ContentView else { NbClique++; - return MauiProgram.Manageur.joueurs + return MauiProgram.Manageur.Joueurs .OrderByDescending(joueur => joueur.NbCoutTotal / (joueur.NbPartiePerdue + joueur.NbPartieGagnee + joueur.NbPartieEgalite)) .Select(joueur => new JoueurClassementNbCoupParPartie(joueur, MauiProgram.Manageur)); } @@ -159,14 +159,14 @@ public partial class CTableauScore : ContentView if(NbClique % 2 == 0) { NbClique++; - return MauiProgram.Manageur.joueurs + return MauiProgram.Manageur.Joueurs .OrderByDescending(joueur => joueur.NbPartieGagnee) .Select(joueur => new JoueurClassementPartieGagnee(joueur, MauiProgram.Manageur)); } else { NbClique++; - return MauiProgram.Manageur.joueurs + return MauiProgram.Manageur.Joueurs .OrderBy(joueur => joueur.NbPartieGagnee) .Select(joueur => new JoueurClassementPartieGagnee(joueur, MauiProgram.Manageur)); } @@ -178,14 +178,14 @@ public partial class CTableauScore : ContentView if(NbClique % 2 == 0) { NbClique++; - return MauiProgram.Manageur.joueurs + return MauiProgram.Manageur.Joueurs .OrderByDescending(joueur => joueur.NbPartieEgalite) .Select(joueur => new JoueurClassementPartieEgalite(joueur, MauiProgram.Manageur)); } else { NbClique++; - return MauiProgram.Manageur.joueurs + return MauiProgram.Manageur.Joueurs .OrderBy(joueur => joueur.NbPartieEgalite) .Select(joueur => new JoueurClassementPartieEgalite(joueur, MauiProgram.Manageur)); } @@ -197,14 +197,14 @@ public partial class CTableauScore : ContentView if(NbClique % 2 == 0) { NbClique++; - return MauiProgram.Manageur.joueurs + return MauiProgram.Manageur.Joueurs .OrderByDescending(joueur => joueur.NbPartiePerdue) .Select(joueur => new JoueurClassementPartiePerdue(joueur, MauiProgram.Manageur)); } else { NbClique++; -; return MauiProgram.Manageur.joueurs +; return MauiProgram.Manageur.Joueurs .OrderBy(joueur => joueur.NbPartiePerdue) .Select(joueur => new JoueurClassementPartiePerdue(joueur, MauiProgram.Manageur)); } @@ -216,14 +216,14 @@ public partial class CTableauScore : ContentView if(NbClique % 2 == 0) { NbClique++; - return MauiProgram.Manageur.joueurs + return MauiProgram.Manageur.Joueurs .OrderBy(joueur => joueur.Nom) .Select(joueur => new JoueurClassementAlphabet(joueur, MauiProgram.Manageur)); } else { NbClique++; - return MauiProgram.Manageur.joueurs + return MauiProgram.Manageur.Joueurs .OrderByDescending(joueur => joueur.Nom) .Select(joueur => new JoueurClassementAlphabet(joueur, MauiProgram.Manageur)); } diff --git a/Sources/MauiSpark/Vues/JetonVue.xaml b/Sources/MauiSpark/Vues/JetonVue.xaml index 84e8cc1..6f3571b 100644 --- a/Sources/MauiSpark/Vues/JetonVue.xaml +++ b/Sources/MauiSpark/Vues/JetonVue.xaml @@ -6,11 +6,19 @@ + SizeChanged="QuandTailleChangee" + VerticalOptions="FillAndExpand" + HorizontalOptions="FillAndExpand"> + Fill="{Binding Couleur, Source={x:Reference jetonVue}}"> + + + + + + diff --git a/Sources/MauiSpark/Vues/JetonVue.xaml.cs b/Sources/MauiSpark/Vues/JetonVue.xaml.cs index bc686a5..824f0c4 100644 --- a/Sources/MauiSpark/Vues/JetonVue.xaml.cs +++ b/Sources/MauiSpark/Vues/JetonVue.xaml.cs @@ -1,31 +1,66 @@ -using Microsoft.Maui.Controls.Shapes; - -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 Color Couleur - { - get => (Color)GetValue(CouleurProperty); - set => SetValue(CouleurProperty, Color.FromRgb(0, 255, 0)); - } - - public JetonVue() - { - InitializeComponent(); - BindingContext = this; - } - - private void QuandTailleChangee(object sender, EventArgs e) - { - double taille = Math.Min(Grid.Width, Grid.Height) / 2; - Cercle.WidthRequest = Cercle.HeightRequest = taille; - } - +using CoreLibrary.Core; +using CoreLibrary.Exceptions; +using MauiSpark.Convertisseurs; +using System.Globalization; + +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 Color Couleur + { + get => (Color)GetValue(CouleurProperty); + set => SetValue(CouleurProperty, value); + } + + public Code? Code + { + get => (Code?)GetValue(CodeProperty); + set => SetValue(CodeProperty, value); + } + + public JetonVue() + { + InitializeComponent(); + BindingContext = this; + } + + private void QuandTailleChangee(object sender, EventArgs e) + { + double taille = Math.Min(Grid.Width, Grid.Height) / 2; + Cercle.WidthRequest = Cercle.HeightRequest = taille; + } + private static void QuandCouleurChangee(BindableObject bindable, object ancienneValeur, object nouvelleValeur) { - ((JetonVue)bindable).Cercle.Fill = (Color) 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); + + try + { + Code.AjouterJeton(new Jeton(couleur)); + } + catch (CodeCompletException) + { + Application.Current.MainPage.DisplayAlert("Attention", "La code est plein", "OK"); + } + } } \ No newline at end of file diff --git a/Sources/MauiSpark/Vues/TitreVue.xaml.cs b/Sources/MauiSpark/Vues/TitreVue.xaml.cs index f973e6b..5d43d66 100644 --- a/Sources/MauiSpark/Vues/TitreVue.xaml.cs +++ b/Sources/MauiSpark/Vues/TitreVue.xaml.cs @@ -2,12 +2,13 @@ namespace MauiSpark.Vues; public partial class TitreVue : ContentView { - public static readonly BindableProperty TextePropriete = BindableProperty.Create(nameof(Texte), typeof(string), typeof(TitreVue), default(string)); + public static readonly BindableProperty TexteProperty = BindableProperty.Create(nameof(Texte), typeof(string), typeof(TitreVue), default(string)); + public string Texte { - get => (string)GetValue(TextePropriete); - set => SetValue(TextePropriete, value.ToUpper()); + get => (string)GetValue(TexteProperty); + set => SetValue(TexteProperty, value.ToUpper()); } public TitreVue()