Quelques modification pour continuer une partie non terminée
continuous-integration/drone/push Build is failing Details

pull/112/head
Rémi LAVERGNE 11 months ago
parent 1f723b64f1
commit 3fbe28accf

@ -23,6 +23,8 @@ namespace Models.Game
[DataContract]
public class Game : INotifyPropertyChanged
{
public bool IsPreviousGameNotFinished { get; private set; }
/* Persistence Interface */
public IPersistence PersistenceManager { get; set; }
@ -134,6 +136,20 @@ namespace Models.Game
{
Maps.Add(map);
}
/// <summary>
/// Deletes the last game in the list of games. Use for avoiding stack not finished games.
/// </summary>
/// <returns></returns>
public bool DeleteGame()
{
if (Games.Count == 0)
{
return false;
}
Games.RemoveAt(Games.Count - 1); // Remove the last game
return true;
}
/// <summary>
/// Adds a new best score to the list of best scores. Or updates it if it already exists.
@ -248,6 +264,10 @@ namespace Models.Game
}
foreach (var game in data.Item2)
{
if (game.IsRunning)
{
IsPreviousGameNotFinished = true;
}
Games.Add(game);
}
foreach (var map in data.Item3)

@ -42,6 +42,16 @@
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<Button Text="Reprendre"
TextColor="White"
BackgroundColor="DarkRed"
FontAttributes="Bold"
FontSize="Large"
Grid.Row="2"
Margin="80"
HorizontalOptions="Center"
Clicked="ResumeButton_Clicked"
IsVisible="{Binding IsPreviousGameNotFinished}"/>
<Button Text="Retour"
FontAttributes="Bold"
FontSize="Large"

@ -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));
}
}
Loading…
Cancel
Save