Move “end game” logic into common function

This commit is contained in:
Phil Marell
2021-07-24 16:23:58 +10:00
parent ab6c447a2f
commit b83fd1b28f

View File

@@ -42,6 +42,7 @@ void DoPause (void);
void DoTouchScreenMenu (void); void DoTouchScreenMenu (void);
void DoBatteryEngaged (gliderPtr); void DoBatteryEngaged (gliderPtr);
void DoHeliumEngaged (gliderPtr); void DoHeliumEngaged (gliderPtr);
void DoEndGame (void);
void QuerySaveGame (Boolean &save, Boolean &cancel); void QuerySaveGame (Boolean &save, Boolean &cancel);
@@ -75,24 +76,7 @@ void DoCommandKey (void)
if (theKeys->IsSet(PL_KEY_ASCII('Q'))) if (theKeys->IsSet(PL_KEY_ASCII('Q')))
{ {
Boolean wantCancel = false; DoEndGame();
playing = false;
paused = false;
if ((!twoPlayerGame) && (!demoGoing))
{
Boolean wantSave = false;
QuerySaveGame(wantSave, wantCancel);
if (wantSave)
{
// New save game.
if (!SaveGame2())
wantCancel = true;
}
}
if (wantCancel)
playing = true;
} }
else if ((theKeys->IsSet(PL_KEY_ASCII('S'))) && (!twoPlayerGame)) else if ((theKeys->IsSet(PL_KEY_ASCII('S'))) && (!twoPlayerGame))
{ {
@@ -337,24 +321,7 @@ void DoTouchScreenMenu(void)
switch (highlightedItem) switch (highlightedItem)
{ {
case TouchScreenMenuItems::kQuit: case TouchScreenMenuItems::kQuit:
{ DoEndGame();
Boolean wantCancel = false;
playing = false;
paused = false;
if ((!twoPlayerGame) && (!demoGoing))
{
Boolean wantSave = false;
QuerySaveGame(wantSave, wantCancel);
if (wantSave)
{
if (!SaveGame2()) // New save game.
wantCancel = true;
}
}
if (wantCancel)
playing = true;
}
break; break;
case TouchScreenMenuItems::kSave: case TouchScreenMenuItems::kSave:
assert(!twoPlayerGame); assert(!twoPlayerGame);
@@ -813,6 +780,28 @@ void GetInput (gliderPtr thisGlider)
} }
} }
void DoEndGame() {
Boolean wantCancel = false;
playing = false;
paused = false;
quitting = false;
if ((!twoPlayerGame) && (!demoGoing))
{
Boolean wantSave = false;
QuerySaveGame(wantSave, wantCancel);
if (wantSave)
{
if (!SaveGame2()) // New save game.
wantCancel = true;
}
}
if (wantCancel)
{
playing = true;
}
}
//-------------------------------------------------------------- QuerySaveGame //-------------------------------------------------------------- QuerySaveGame
void QuerySaveGame (Boolean &save, Boolean &cancel) void QuerySaveGame (Boolean &save, Boolean &cancel)