using CoreLibrary; using CoreLibrary.Joueurs; using MauiSpark.Pages; using System.ComponentModel; using System.Runtime.CompilerServices; namespace MauiSpark.Vues; public partial class PartieCommenceeVue : ContentView, INotifyPropertyChanged { public static readonly BindableProperty PartieProperty = BindableProperty.Create(nameof(Partie), typeof(Partie), typeof(PartieCommenceeVue), null, propertyChanged: QuandPartieChangee); public Partie Partie { get => (Partie)GetValue(PartieProperty); set => SetValue(PartieProperty, value); } public string NomRegles { get => Partie != null ? Partie.Regles.Nom : ""; } public string TourActuel { get => $"Tour : {(Partie != null ? Partie.Tour : 0)} / {(Partie != null ? Partie.Regles.NbTour : 0)}"; } public Joueur[] Joueurs { get => Partie != null ? Partie.Joueurs.ToArray() : []; } public string NombreJoueurs => $"Joueurs : {Joueurs.Length} / {(Partie != null ? Partie.Regles.NbJoueurs : 0)}"; private static void QuandPartieChangee(BindableObject bindable, object ancienneValeur, object nouvelleValeur) { ((PartieCommenceeVue)bindable).OnPropertyChanged(nameof(NomRegles)); ((PartieCommenceeVue)bindable).OnPropertyChanged(nameof(TourActuel)); ((PartieCommenceeVue)bindable).OnPropertyChanged(nameof(Joueurs)); ((PartieCommenceeVue)bindable).OnPropertyChanged(nameof(NombreJoueurs)); } private void PartiePressee(object? sender, EventArgs e) { if (Partie == null) return; Partie.PartieDemanderJoueur += new ConnexionPage().QuandDemanderNom; Partie.PartieNouveauTour += new PlateauPage().QuandNouveauTour; Partie.PartiePartieTerminee += new VictoirePage().QuandPartieTerminee; Partie.Jouer(); } public PartieCommenceeVue() { InitializeComponent(); } }