aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavid <[email protected]>2026-05-07 08:07:51 -0300
committerdavid <[email protected]>2026-05-07 08:07:51 -0300
commit06fe6fd82ecf429b852e96bc024f1ddc59c2d7af (patch)
treef61242783f6222fdb2f177d6e0d39f623e8e791e
parentbb8360a1979169e032fa4ed1405cae197661de7a (diff)
downloadpetratc-06fe6fd82ecf429b852e96bc024f1ddc59c2d7af.tar.gz
petratc-06fe6fd82ecf429b852e96bc024f1ddc59c2d7af.zip
added a proper restart function
-rw-r--r--games/gamemaze.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/games/gamemaze.c b/games/gamemaze.c
index 307ff72..8b35afc 100644
--- a/games/gamemaze.c
+++ b/games/gamemaze.c
@@ -193,6 +193,25 @@ void checkexit(cursor *curs) {
}
}
+static void properrestart(cursor *curs, int *W, int *H) {
+ for (int y = 0; y < *H; y++) free(grid[y]);
+ free(grid);
+
+ *W = getmaxx(stdscr);
+ *H = getmaxy(stdscr);
+
+ grid = malloc(*H * sizeof(char *));
+ for (int y = 0; y < *H; y++)
+ grid[y] = malloc(*W * sizeof(char));
+
+ lerw();
+ spawncheeses();
+
+ curs->posy = 1;
+ curs->posx = 1;
+ found = 0;
+}
+
void gamemaze(){
srand(time(NULL));
@@ -227,7 +246,7 @@ void gamemaze(){
int ch = getch();
switch (ch) {
case 'q': case 'Q': stop(); break;
- case 'r': case 'R': stop(); gamemaze(); break;
+ case 'r': case 'R': properrestart(&curs, &W, &H); break;
case 'a': case 'A': case KEY_LEFT:
if (!iswall(curs.posy, curs.posx - 1)) curs.posx -= 1; break;
case 'd': case 'D': case KEY_RIGHT: