From 6a91e36534e430597ee84a4e0239ee1b9d1fa507 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 4 May 2026 03:47:21 -0300 Subject: [PATCH] finished gamecatch now you can take a shower --- games/gamecatch.c | 80 ++++++++++++++++++++++++++++++++++++++++------- petratc.c | 4 +-- 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/games/gamecatch.c b/games/gamecatch.c index e12e48e..0b28c6e 100644 --- a/games/gamecatch.c +++ b/games/gamecatch.c @@ -34,35 +34,51 @@ // i just realized this is basically cmatrix with a little guy at the bottom */ -#define width 40; -#define height 50; +#define width 40 +#define height getmaxy(stdscr) +#define maxdrops 70 int running; +int won; +int howmany; typedef struct{ int posx; int posy; - char *symbol[3]; + int active; + char *symbol; }drop; typedef struct{ int posx; char *face[2]; + int direction; }cursor; -void spawndrops(){ - -return; - +static drop droop[maxdrops]; +void spawndrops() { + for (int i = 0; i < maxdrops; i++) { + if (!droop[i].active) { + droop[i].posx = 1 + rand() % (width - 2); + droop[i].posy = 0; + droop[i].active = 1; + char *symbols[] = {"O", "0", "o"}; + droop[i].symbol = symbols[rand() % 3]; + break; + } + } } void stop() { if (!isendwin()) { + clear(); + refresh(); endwin(); } - addstat(&rat.clean); + if(won){addstat(&rat.clean);} + won = 0; running = 0; } @@ -75,15 +91,17 @@ void gamecatch(){ static int initialized = 0; if(initialized == 0){ initscr();}else{refresh();} // turns out you don't wanna call initscr() many times per session so do this because it glitches otherwise ++initialized; + howmany = 0; noecho(); cbreak(); + nodelay(stdscr, TRUE); keypad(stdscr, TRUE); curs_set(0); - drop droop = {0, 0, {"O", "0", "o"}}; //on spawn random which symbol it'll use - cursor curs = {20, {"(>.<)_", "_(>.<)" }}; //face[0] is going left face[1] is going right + cursor curs = {width / 2, {"(>.<)_", "_(>.<)"}, 0}; + for (int i = 0; i < maxdrops; i++) droop[i].active = 0; running = 1; while (running) { @@ -91,12 +109,50 @@ void gamecatch(){ switch (ch) { case 'q': case 'Q': stop(); break; case 'a': case 'A': case KEY_LEFT: - curs.posx--; + curs.posx-= 2; + if(curs.posx < 0) curs.posx = width - 6; + curs.direction = 0; break; case 'd': case 'D': case KEY_RIGHT: - curs.posx++; + curs.posx += 2; + if(curs.posx > width - 6) curs.posx = 0; + curs.direction = 1 ; break; } + + + if (!running) break; + if (rand() % 10 < 2) spawndrops(); + + clear(); + + mvprintw(0, width + 2, "caught: %d/30", howmany); + mvprintw(1, width + 2, "(catch 30 to win!)"); + mvprintw(2, width + 2, "move with A and D"); + mvprintw(3, width + 2, "or the or the corresponding arrows"); + + + + for (int i = 0; i < maxdrops; i++) { + if (droop[i].active) { + mvaddstr(droop[i].posy, droop[i].posx, droop[i].symbol); + droop[i].posy++; + if (droop[i].posy >= height) droop[i].active = 0; + + if (droop[i].posy == height - 1 && + droop[i].posx >= curs.posx && + droop[i].posx <= curs.posx + 5) { + droop[i].active = 0; + howmany++; + if(howmany == 30){won = 1; running = 0;} + } + } + } + + mvaddstr(height - 1, curs.posx, curs.face[curs.direction]); + + refresh(); + usleep(100000); } stop(); diff --git a/petratc.c b/petratc.c index 5334e7b..5889f89 100644 --- a/petratc.c +++ b/petratc.c @@ -92,7 +92,7 @@ void printrat(){ printf("%s\n", ratart); int howmany = sizeof(messages) / sizeof(messages[0]); printf("%s\n", messages[rand() % howmany]); - printf("rat hunger: %.2f, rat love: %.2f, rat fun: %.2f, rat dirt: %.2f, rat health: %.2f\n", + printf("rat hunger: %.2f, rat love: %.2f, rat fun: %.2f, rat clean: %.2f, rat health: %.2f\n", rat.hunger, rat.love, rat.fun, rat.clean, rat.health); } @@ -108,7 +108,7 @@ int truing = 1; printrat(); while(truing){ - printf("1: play a game! (fun up), 4: take a shower!, 9: print me!, 0: exit...\n"); + printf("1: play a game! (fun up), 4: take a shower! (clean up), 9: print me!, 0: exit...\n"); scanf("%d", &choice); switch(choice){