diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index a3bff6a..a7d7385 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -36,7 +36,9 @@ namespace QwirkleClassLibrary.Games private readonly Dictionary scoreBoard = new Dictionary(); public ReadOnlyDictionary ScoreBoard => scoreBoard.AsReadOnly(); + [DataMember] private readonly ObservableCollection> observableScoreBoard = []; + public ReadOnlyObservableCollection> ObservableScoreBoard => new(observableScoreBoard); diff --git a/Qwirkle/QwirkleViews/App.xaml.cs b/Qwirkle/QwirkleViews/App.xaml.cs index 94d9aab..bb478eb 100644 --- a/Qwirkle/QwirkleViews/App.xaml.cs +++ b/Qwirkle/QwirkleViews/App.xaml.cs @@ -14,7 +14,9 @@ namespace Qwirkle { string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); string targetPath = Path.Combine(appDataPath, "Programs", "Files"); + Directory.CreateDirectory(targetPath); Directory.SetCurrentDirectory(targetPath); + InitializeComponent(); MainPage = new AppShell(); @@ -26,8 +28,15 @@ namespace Qwirkle Routing.RegisterRoute(nameof(Qwirkle.Pages.Leaderboard), typeof(Qwirkle.Pages.Leaderboard)); ILeaderboardPersistence leaderboardLoad = new LeaderboardPersistenceJson(); - - Ld = leaderboardLoad.LoadLeaderboard(); + + try + { + Ld = leaderboardLoad.LoadLeaderboard(); + } + catch + { + Ld = new Leaderboard(); + } } diff --git a/Qwirkle/QwirkleViews/MainPage.xaml b/Qwirkle/QwirkleViews/MainPage.xaml index c8eb72a..454a31a 100644 --- a/Qwirkle/QwirkleViews/MainPage.xaml +++ b/Qwirkle/QwirkleViews/MainPage.xaml @@ -1,4 +1,5 @@ - + + + Style="{StaticResource SuperTitle}" /> + Aspect="AspectFit" /> - - - + InfoClicked="OnInfoClicked" /> + + + InfoClicked="OnCLeaderboardClicked" /> + InfoClicked="OnRulesClicked" /> + InfoClicked="OnSettingsClicked" /> + InfoClicked="OnCreditsClicked" /> - + \ No newline at end of file diff --git a/Qwirkle/QwirkleViews/MainPage.xaml.cs b/Qwirkle/QwirkleViews/MainPage.xaml.cs index fa9d69b..0a5ee92 100644 --- a/Qwirkle/QwirkleViews/MainPage.xaml.cs +++ b/Qwirkle/QwirkleViews/MainPage.xaml.cs @@ -22,6 +22,11 @@ namespace Qwirkle Navigation.PushAsync(new SetPlayers()); } + public void OnContinueClicked(object sender, EventArgs e) + { + Navigation.PushAsync(new Gameboard("ContinueGame")); + } + public void OnRulesClicked(object sender, EventArgs e) { Navigation.PushAsync(new Rules()); diff --git a/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs b/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs index 6da5632..0ae1a57 100644 --- a/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs +++ b/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs @@ -30,18 +30,39 @@ public partial class Gameboard : ContentPage public Color ColorBC3 { get; set; } = Colors.Transparent; public Color ColorBC4 { get; set; } = Colors.Transparent; - - public Gameboard() + public Gameboard(string caller) { - 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) { await PopUpEnd(); @@ -235,9 +256,7 @@ public partial class Gameboard : ContentPage if (answer) { - await Navigation.PushAsync(new MainPage()); - - + await Navigation.PopToRootAsync(); } } diff --git a/Qwirkle/QwirkleViews/Pages/Gameboard.xaml b/Qwirkle/QwirkleViews/Pages/Gameboard.xaml index 01602c0..ce122a6 100644 --- a/Qwirkle/QwirkleViews/Pages/Gameboard.xaml +++ b/Qwirkle/QwirkleViews/Pages/Gameboard.xaml @@ -8,9 +8,9 @@ 75 - 75 - 1 - 1 + 75 + 1 + 1 @@ -28,23 +28,24 @@ - + BackgroundColor="Transparent" + Margin="0"> + + DropCommand="{Binding OnDropB, Source={x:Reference root}}" /> - + + -