From 40aa294bd9bcbd4a1b6ccf5f9b5b23cfc2df7f57 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Thu, 6 Jun 2024 19:22:31 +0200 Subject: [PATCH] persistence work now + rules --- Qwirkle/QwirkleViews/MainPage.xaml.cs | 21 ++++++++++-- Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs | 30 ++++-------------- Qwirkle/QwirkleViews/Pages/Gameboard.xaml | 2 ++ Qwirkle/QwirkleViews/Pages/Rules.xaml | 3 +- Qwirkle/QwirkleViews/Pages/SetPlayers.xaml.cs | 2 +- .../Resources/Images/bookicon.png | Bin 0 -> 38796 bytes 6 files changed, 30 insertions(+), 28 deletions(-) create mode 100644 Qwirkle/QwirkleViews/Resources/Images/bookicon.png diff --git a/Qwirkle/QwirkleViews/MainPage.xaml.cs b/Qwirkle/QwirkleViews/MainPage.xaml.cs index 0a5ee92..e4bfe0f 100644 --- a/Qwirkle/QwirkleViews/MainPage.xaml.cs +++ b/Qwirkle/QwirkleViews/MainPage.xaml.cs @@ -3,6 +3,7 @@ using QwirkleClassLibrary; using QwirkleClassLibrary.Games; using Microsoft.Maui.Controls; using Qwirkle.Pages; +using QwirkleClassLibrary.Persistences; namespace Qwirkle { @@ -22,9 +23,25 @@ namespace Qwirkle Navigation.PushAsync(new SetPlayers()); } - public void OnContinueClicked(object sender, EventArgs e) + public async void OnContinueClicked(object sender, EventArgs e) { - Navigation.PushAsync(new Gameboard("ContinueGame")); + IGamePersistence gameLoad = new GamePersistenceXml(); + try + { + ((App)Application.Current!).Game = gameLoad.LoadGame(); + await Navigation.PushAsync(new Gameboard()); + } + catch + { + await DisplayAlert("Error", "No game found", "Got it !"); + await Navigation.PopAsync(); + } + + if (!((App)Application.Current!).Game.GameRunning) + { + await DisplayAlert("Error", "No game found", "Got it !"); + await Navigation.PopAsync(); + } } public void OnRulesClicked(object sender, EventArgs e) diff --git a/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs b/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs index 0ae1a57..85ad7ad 100644 --- a/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs +++ b/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs @@ -30,37 +30,14 @@ public partial class Gameboard : ContentPage public Color ColorBC3 { get; set; } = Colors.Transparent; public Color ColorBC4 { get; set; } = Colors.Transparent; - public Gameboard(string caller) + public Gameboard() { InitializeComponent(); BindingContext = game; ChangeColorBC(); - if (caller == "ContinueGame") - { - CheckContinuedGame(); - } - } - - private async void CheckContinuedGame() - { - IGamePersistence gameLoad = new GamePersistenceXml(); - try - { - game = gameLoad.LoadGame(); - } - catch - { - await DisplayAlert("Error", "No game found", "Got it !"); - await Navigation.PopAsync(); - } - if (game.GameRunning == false) - { - await DisplayAlert("Error", "No game found", "Got it !"); - await Navigation.PopAsync(); - } } private async void Game_EndOfGameNotified(object? sender, EndOfGameNotifiedEventArgs e) @@ -260,5 +237,10 @@ public partial class Gameboard : ContentPage } } + private void OnButtonBookClicked(object? sender, EventArgs e) + { + Navigation.PushAsync(new Rules()); + } + } diff --git a/Qwirkle/QwirkleViews/Pages/Gameboard.xaml b/Qwirkle/QwirkleViews/Pages/Gameboard.xaml index cd5d839..da93ebb 100644 --- a/Qwirkle/QwirkleViews/Pages/Gameboard.xaml +++ b/Qwirkle/QwirkleViews/Pages/Gameboard.xaml @@ -39,6 +39,8 @@ + +