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.
118 lines
3.3 KiB
118 lines
3.3 KiB
using CoreLibrary;
|
|
using CoreLibrary.Core;
|
|
using CoreLibrary.Events;
|
|
using CoreLibrary.Exceptions;
|
|
using CoreLibrary.Joueurs;
|
|
using MauiSpark.Convertisseurs;
|
|
using System.Globalization;
|
|
|
|
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] = (e.Grille.ElementAt(i).Where(x => x.HasValue).Select(x => x!.Value), e.Indicateurs.ElementAt(i));
|
|
}
|
|
Plateau = plateau;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public partial class Plateau : ContentPage
|
|
{
|
|
private Code? code;
|
|
private Joueur? joueur;
|
|
|
|
public Plateau()
|
|
{
|
|
NavigationPage.SetHasNavigationBar(this, false);
|
|
NavigationPage.SetBackButtonTitle(this, "Retour");
|
|
|
|
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 Accueil)
|
|
break;
|
|
|
|
Application.Current.MainPage.Navigation.RemovePage(page);
|
|
}
|
|
|
|
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, 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
|
|
{
|
|
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());
|
|
}
|
|
} |