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.
59 lines
1.7 KiB
59 lines
1.7 KiB
using CoreLibrary.Events;
|
|
using CoreLibrary.Joueurs;
|
|
|
|
namespace MauiSpark.Pages;
|
|
|
|
public partial class Victoire : ContentPage
|
|
{
|
|
public Victoire()
|
|
{
|
|
NavigationPage.SetHasNavigationBar(this, false);
|
|
|
|
InitializeComponent();
|
|
}
|
|
|
|
public async void QuandPartieTerminee(object? sender, PartieTermineeEventArgs 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);
|
|
}
|
|
|
|
Joueur[] gagnants = e.Gagnants;
|
|
Joueur[] perdants = e.Perdants;
|
|
|
|
if (gagnants.Length == 1)
|
|
BindingContext = ("Victoire", $"Le joueur {gagnants.First().Nom} a gagné");
|
|
else if (gagnants.Length > 1)
|
|
BindingContext = ("Egalité", $"Les joueurs {string.Join(' ', gagnants.Select(joueur => joueur.Nom))} ont gagné");
|
|
else
|
|
BindingContext = ("Défaite", "Personne n'a trouvé le code...");
|
|
|
|
|
|
if (gagnants.Length == 1)
|
|
gagnants.First().AGagne();
|
|
else
|
|
foreach (Joueur gagnant in gagnants)
|
|
gagnant.AEgalite();
|
|
|
|
foreach (Joueur perdant in perdants)
|
|
perdant.APerdu();
|
|
|
|
}
|
|
|
|
public async void QuandMenuPresse(object sender, EventArgs e)
|
|
{
|
|
await Navigation.PopAsync();
|
|
}
|
|
} |