You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mastermind/Sources/MauiSpark/Pages/PlateauPage.xaml.cs

98 lines
2.6 KiB

using CoreLibrary.Core;
using CoreLibrary.Events;
using CoreLibrary.Exceptions;
using CoreLibrary.Joueurs;
namespace MauiSpark.Pages;
internal class Tour
{
public IEnumerable<(IEnumerable<Jeton>, IEnumerable<Indicateur>)> 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<Jeton>, IEnumerable<Indicateur>)[] plateau = new (IEnumerable<Jeton>, IEnumerable<Indicateur>)[e.Grille.Count()];
for (int i = 0; i < e.Grille.Count(); ++i)
{
plateau[i] = ([new Jeton(Couleur.ROUGE), new Jeton(Couleur.VERT), new Jeton(Couleur.BLEU), new Jeton(Couleur.JAUNE)], e.Indicateurs.ElementAt(i));
}
Plateau = plateau;
}
}
public partial class PlateauPage : ContentPage
{
private Code? code;
private Joueur? joueur;
public PlateauPage()
{
NavigationPage.SetHasNavigationBar(this, false);
InitializeComponent();
}
public async void QuandNouveauTour(object? sender, NouveauTourEventArgs e)
{
if (Application.Current == null || Application.Current.MainPage == null)
return;
if (((NavigationPage)Application.Current!.MainPage).CurrentPage != this)
await Application.Current.MainPage.Navigation.PushAsync(this);
IEnumerable<Page> pages = Application.Current.MainPage.Navigation.NavigationStack.Reverse().Skip(1);
foreach (Page page in pages)
{
if (page is AccueilPage)
break;
Application.Current.MainPage.Navigation.RemovePage(page);
}
code = e.Code;
joueur = e.Joueur;
BindingContext = new Tour(e);
}
private void SupprimerDernierJeton(Object sender, EventArgs e)
{
try
{
if(code != null)
code.SupprimerDernierJeton();
}
catch(CodeVideException)
{
DisplayAlert("Attention", "La code est vide", "OK");
}
}
private void ValiderCode(Object sender, EventArgs e)
{
try
{
if(joueur != null && code != null)
joueur.Code(code);
}
catch (CodeIncompletException)
{
DisplayAlert("Attention", "La code n'est pas complet", "OK");
}
}
private async void QuandReglesClique(object sender, EventArgs e)
{
await Navigation.PushAsync(new Regle());
}
}