added request dialog to play again after game is over without solving level
authorHolger Schemel <info@artsoft.org>
Fri, 12 Oct 2018 19:23:26 +0000 (21:23 +0200)
committerHolger Schemel <info@artsoft.org>
Fri, 12 Oct 2018 19:23:26 +0000 (21:23 +0200)
src/game.c
src/game.h
src/screens.c

index 5bfa71db14d69900b035c2d31a0e60df472027bd..eed459776345f33d6bc402864eb4ba6bf1a56c00 100644 (file)
@@ -14949,6 +14949,38 @@ void RequestRestartGame(char *message)
   }
 }
 
+void CheckGameOver(void)
+{
+  static boolean last_game_over = FALSE;
+  static int game_over_delay = 0;
+  int game_over_delay_value = 50;
+  boolean game_over = checkGameFailed();
+
+  /* do not handle game over if request dialog is already active */
+  if (game.request_active)
+    return;
+
+  if (!game_over)
+  {
+    last_game_over = FALSE;
+    game_over_delay = game_over_delay_value;
+
+    return;
+  }
+
+  if (game_over_delay > 0)
+  {
+    game_over_delay--;
+
+    return;
+  }
+
+  if (last_game_over != game_over)
+    game.restart_game_message = "Game over! Play it again?";
+
+  last_game_over = game_over;
+}
+
 boolean checkGameSolved(void)
 {
   /* set for all game engines if level was solved */
index 5fab8390aa479813373faab3268edc2890632152..bd26e264633cf7d6cea0c9f413bffaa9bd7cf5d0 100644 (file)
@@ -417,6 +417,7 @@ void RaiseScoreElement(int);
 void RequestQuitGameExt(boolean, boolean, char *);
 void RequestQuitGame(boolean);
 void RequestRestartGame(char *);
+void CheckGameOver(void);
 
 boolean checkGameSolved(void);
 boolean checkGameFailed(void);
index 5900616f1956d78c6ad87b6b1585ca4971f995a9..ae4f7038dde2b8c6741dcf874f36942bd909e65a 100644 (file)
@@ -8211,6 +8211,8 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
 
 void HandleGameActions(void)
 {
+  CheckGameOver();
+
   if (game.restart_game_message != NULL)
     RequestRestartGame(game.restart_game_message);