From 3c3826b7464b8420bfe9491074f09ff64d12236b Mon Sep 17 00:00:00 2001 From: Laurent MAZET Date: Wed, 16 Oct 2024 11:45:17 +0200 Subject: [PATCH] add end of game test --- function.c | 5 +++++ function.h | 2 ++ pacman.c | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/function.c b/function.c index e48e66e..de1c47c 100644 --- a/function.c +++ b/function.c @@ -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: */ diff --git a/function.h b/function.h index 2624ada..81ed6e3 100644 --- a/function.h +++ b/function.h @@ -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: */ diff --git a/pacman.c b/pacman.c index a291372..c0a4a54 100644 --- 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: -- 2.30.2