@ -10,12 +10,16 @@ public partial class PageSelectMap : ContentPage
public Game SelectMapManager = > ( App . Current as App ) . Manager ;
private Map ? _selectedMap ;
private bool previousGameRunning = false ;
private bool isVisibleContinueButton = false ;
protected override async void OnAppearing ( )
{
base . OnAppearing ( ) ;
if ( SelectMapManager . Games . Any ( g = > g . IsRunning ) )
{
previousGameRunning = true ;
await DisplayAlert ( "Warning" , "You've previously quit in the middle of a game.\nIf you start a new game, this one will be permanently lost." , "I understand" ) ;
}
@ -59,8 +63,16 @@ public partial class PageSelectMap : ContentPage
SelectMapManager . InitializeGame ( _selectedMap , chosenPlayer ) ;
if ( SelectMapManager . UsedMap = = _selectedMap & & Equals ( SelectMapManager . CurrentPlayer , chosenPlayer ) )
if ( SelectMapManager . UsedMap = = _selectedMap & & Equals ( SelectMapManager . CurrentPlayer , chosenPlayer ) )
{
// Delete the previous game if it was running
if ( previousGameRunning )
{
bool rep = SelectMapManager . DeleteGame ( ) ;
SelectMapManager . SaveData ( ) ;
if ( rep ) await DisplayAlert ( "Game deleted" , "The previous game has been deleted because you started a new one." , "OK" ) ;
}
await Shell . Current . GoToAsync ( nameof ( PageBoard ) ) ;
}
else
@ -79,4 +91,17 @@ public partial class PageSelectMap : ContentPage
return SelectMapManager . Players . FirstOrDefault ( p = > p . Pseudo = = pseudo ) ;
}
private async void ResumeButton_Clicked ( object sender , EventArgs e )
{
Game game = SelectMapManager . Games . FirstOrDefault ( g = > g . IsRunning ) ;
if ( game = = null )
{
await DisplayAlert ( "No game found" , "No game found to resume. Please start a new game." , "OK" ) ;
return ;
}
SelectMapManager . InitializeGame ( game . UsedMap , game . CurrentPlayer ) ;
await Shell . Current . GoToAsync ( nameof ( PageBoard ) ) ;
}
}