add end of game test
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Wed, 16 Oct 2024 09:45:17 +0000 (11:45 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Wed, 16 Oct 2024 09:45:17 +0000 (11:45 +0200)
function.c
function.h
pacman.c

index e48e66ed72768548f2b591fa89f42f03d8d22e34..de1c47ca467ecc0951e9f081559dfe721604e5cd 100644 (file)
@@ -230,4 +230,9 @@ int findchar (board_t *board, char c, int *px, int *py)
     return ret;
 }
 
+int endofgame (board_t *board)
+{
+    return ((strchr (board->tab, '.') == NULL) && (strchr (board->tab, '*') == NULL));
+}
+
 /* vim: set ts=4 sw=4 et: */
index 2624ada8bf18bdb24edcb11535c71c7c7e532dad..81ed6e3e4d21166304f4fa91ebef72b7ac62711f 100644 (file)
@@ -43,6 +43,8 @@ board_t *loadboard (char *str);
 
 int findchar (board_t *board, char c, int *px, int *py);
 
+int endofgame (board_t *board);
+
 #endif /* __FUNCTION_H__ */
 
 /* vim: set ts=4 sw=4 et: */
index a291372e50d40b7ba2460d652e09be36764b1655..c0a4a54d17fcd7fcd0803c092bcb781f244af4d3 100644 (file)
--- a/pacman.c
+++ b/pacman.c
@@ -283,6 +283,13 @@ int main (int argc, char *argv[])
             spin = 1;
         }
 
+        /* test end of game */
+        if (endofgame (board)) {
+            mode = 2;
+            sprintf (msg, "End of game");
+            msgwindow (msg, xboard + (board->width - strlen (msg)) / 2, yboard + (board->height - 1) / 2, strlen (msg), 1);
+        }
+
         int ch = getch ();
 
         /* record key pressed */
@@ -336,6 +343,10 @@ int main (int argc, char *argv[])
             break;
         }
 
+        if (mode == 2) {
+            continue;
+        }
+
         /* game controls */
         switch (ch) {
         case KEY_UP: