From 6b3829ef5888ff48dbf47b2cf99faf3c4b65e168 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 20 Sep 2026 07:59:28 -0300 Subject: [PATCH] i'm suck a fucking genius --- games/gamemaze.c | 43 +++++++++++++++++++++++-------------------- rat.c | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/games/gamemaze.c b/games/gamemaze.c index d4fb956..37ca3b9 100644 --- a/games/gamemaze.c +++ b/games/gamemaze.c @@ -1,4 +1,3 @@ -#include #include #include #include @@ -93,26 +92,29 @@ void lerw() { int pl = 1; int cx = sx, cy = sy; - while (!vis[cy * cw + cx]) { + while (!vis[cy * cw + cx]) { int dir = rand() % 4; int nx = cx + ddx[dir]; int ny = cy + ddy[dir]; if (nx < 0 || nx >= cw || ny < 0 || ny >= ch) continue; - + int ni = ny * cw + nx; + if (vis[ni]) { + cx = nx; cy = ny; + continue; + } if (ip[ni] >= 0) { int idx = ip[ni]; - for (int i = idx + 1; i < pl; i++) - ip[py[i] * cw + px[i]] = -1; + for (int i = idx + 1; i < pl; i++) ip[py[i] * cw + px[i]] = -1; pl = idx + 1; - cx = nx; cy = ny; - } else { - px[pl] = nx; py[pl] = ny; + cx = nx; cy = ny; + } else { + px[pl] = nx; py[pl] = ny; ip[ni] = pl++; - cx = nx; cy = ny; + cx = nx; cy = ny; } } - + //each cell as 2x2 for (int i = 0; i < pl; i++) { int gx = 3*px[i]+1, gy = 3*py[i]+1; @@ -306,15 +308,14 @@ void gamemaze(){ mvwprintw(win, 1, width/3+2, "move around the maze and find food!"); mvwprintw(win, 2, width/3+2, "you've collected %d/5 cheeses", found); mvwprintw(win, 3, width/3+2, "(only if you find food your rat will be less hungry)"); - mvwprintw(win, height/1.5-2+1, width/3+2, "btw sometimes the maze is impossible just press R"); - mvwprintw(win, height/1.5-1+1, width/3+2, "if that's the case"); - for (int y = 0; y < H; y++) - for (int x = 0; x < W; x++){ - if (grid[y][x] == '#') mvwaddch(win, y+1, x+1, '#'); - else if (grid[y][x] == 'O') { - int dist = abs(y - curs.posy) + abs(x - curs.posx); - if (dist <= 5) mvwaddch(win, y+1, x+1, 'O'); + for (int y = 0; y < H; y++){ + for (int x = 0; x < W; x++){ + if (grid[y][x] == '#') mvwaddch(win, y+1, x+1, '#'); + else if (grid[y][x] == 'O') { + int dist = abs(y - curs.posy) + abs(x - curs.posx); + if (dist <= 5) mvwaddch(win, y+1, x+1, 'O'); + } } } @@ -330,9 +331,11 @@ void gamemaze(){ usleep(50000); } - for (int y = 0; y < H; y++) - free(grid[y]); + for (int y = 0; y < H; y++){ + free(grid[y]); + } free(grid); + //those two for loops were giving me warnings on my lsp so i just fixed them stop(); } diff --git a/rat.c b/rat.c index 247412d..86b27f6 100644 --- a/rat.c +++ b/rat.c @@ -79,12 +79,33 @@ void setstat(){ rat.age = timenow; } +#define minlines 25 +#define mincols 80 + +static void checkminsize(void){ + if(LINES >= minlines && COLS >= mincols) return; + + clear(); + mvprintw(0, 0, "terminal too small! need at least %dx%d, got %dx%d.", mincols, minlines, COLS, LINES); + mvprintw(1, 0, "press any key to exit..."); + refresh(); + + nodelay(stdscr, FALSE); + getch(); + + save(); + endwin(); + exit(1); +} + WINDOW *ratdrawbox(void){ static int initialized = 0; if(!initialized){ initscr(); }else{ refresh(); } ++initialized; + checkminsize(); + noecho(); cbreak(); nodelay(stdscr, TRUE);