aboutsummaryrefslogtreecommitdiff
path: root/games
diff options
context:
space:
mode:
authordavid <[email protected]>2026-07-17 01:13:51 -0300
committerdavid <[email protected]>2026-07-17 01:13:51 -0300
commit1bac6b527b2c9e7cc3069cb3989411831ed6404f (patch)
tree9658fe17e8bf7e98b83430a65495149aa389eb22 /games
parentb36a541862271f0faae949896e1d6bac764e6921 (diff)
downloadpetratc-1bac6b527b2c9e7cc3069cb3989411831ed6404f.tar.gz
petratc-1bac6b527b2c9e7cc3069cb3989411831ed6404f.zip
changed gameguess a bit and i think i touched one other file idk
Diffstat (limited to 'games')
-rw-r--r--games/gameclicker.c1
-rw-r--r--games/gameguess.c173
2 files changed, 156 insertions, 18 deletions
diff --git a/games/gameclicker.c b/games/gameclicker.c
index 7e723de..60bacfa 100644
--- a/games/gameclicker.c
+++ b/games/gameclicker.c
@@ -57,5 +57,4 @@ void gameclicker(){
}
stop();
-printf("yeah");
}
diff --git a/games/gameguess.c b/games/gameguess.c
index 940e4c5..7d56caf 100644
--- a/games/gameguess.c
+++ b/games/gameguess.c
@@ -1,31 +1,170 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <ncurses.h>
#include "../rat.h"
-void gameguess(){
-int guess;
-int solved = 0;
-int range = 100;
+#define boxw 45
+#define boxh 25
+#define maxhistory 4
-int correct = (rand() % (range + 1));
+static int wrapprint(WINDOW *win, int row, int col, int maxwidth, const char *msg){
-printf("let's play a game, squeak!~ you gues a number between 0 and %d!\n", range);
+ char copy[256];
+ strncpy(copy, msg, sizeof(copy));
+ copy[sizeof(copy)-1] = '\0';
+ char line[256] = "";
+ char *word = strtok(copy, " ");
+ while(word){
+ int linelen = strlen(line);
+ int wordlen = strlen(word);
+ int extra = (linelen > 0) ? 1 : 0;
+ if(linelen + extra + wordlen > maxwidth){
+ mvwprintw(win, row++, col, "%s", line);
+ line[0] = '\0';
+ linelen = 0;
+ extra = 0;
+ }
-while(solved != 1){
+ if(linelen > 0) strcat(line, " ");
+ strcat(line, word);
-if(scanf("%d", &guess) != 1){
- while(getchar() != '\n'); //flush the bad input here too
- continue;
-}
+ word = strtok(NULL, " ");
+ }
+ if(strlen(line) > 0){
+ mvwprintw(win, row++, col, "%s", line);
+ }
-if(guess < correct){
-printf("number too low try again\n");
-}else if(guess > correct){
-printf("number too high try again\n");
-}else {printf("yes!! correct! squeaaakk!~\n"); solved = 1;}
+ return row;
}
- addstat(&rat.fun);
+static void drawwin(WINDOW *win, int artpick, const char *msg, int history[], int histcount){
+
+ werase(win);
+ box(win, 0, 0);
+
+ int row = 1;
+ char artcopy[256];
+ strncpy(artcopy, ratart[artpick], sizeof(artcopy));
+ artcopy[sizeof(artcopy)-1] = '\0';
+
+ char *line = strtok(artcopy, "\n");
+ while(line){
+ mvwprintw(win, row++, 2, "%s", line);
+ line = strtok(NULL, "\n");
+ }
+
+ row++;
+ wrapprint(win, row, 2, boxw - 4, msg);
+
+ int inputrow = boxh - 3;
+
+
+ for(int i = 0; i < histcount; i++){
+ mvwprintw(win, inputrow - histcount + i, 2, "%d", history[i]);
+ }
+
+ wrefresh(win);
+}
+
+void gameguess(){
+
+ int guess;
+ int solved = 0;
+ int range = 100;
+
+ int correct = (rand() % (range + 1));
+
+ int history[maxhistory];
+ int histcount = 0;
+
+ static int initialized = 0;
+ if(initialized == 0){ initscr(); }else{ refresh(); }
+ ++initialized;
+
+ noecho();
+ cbreak();
+ curs_set(0);
+
+ WINDOW *win = newwin(boxh, boxw, 1, 1);
+
+ char msg[96];
+ snprintf(msg, sizeof(msg), "let's play a game, squeak!~ you gues a number between 0 and %d!", range);
+ drawwin(win, 4, msg, history, histcount);
+
+ int quitgame = 0;
+
+ while(solved != 1){
+
+ echo();
+ char buf[16];
+ mvwgetnstr(win, boxh - 3, 2, buf, sizeof(buf) - 1);
+ noecho();
+
+ if((buf[0] == 'q' || buf[0] == 'Q') && buf[1] == '\0'){
+ drawwin(win, 2, "are you suuure you don't wanna play anymoreee~?", history, histcount);
+
+ echo();
+ char confirm[16];
+ mvwgetnstr(win, boxh - 3, 2, confirm, sizeof(confirm) - 1);
+ noecho();
+
+ if((confirm[0] == 'q' || confirm[0] == 'Q' || confirm[0] == 'y' || confirm[0] == 'Y') && confirm[1] == '\0'){
+ quitgame = 1;
+ break;
+ } else if((confirm[0] == 'n' || confirm[0] == 'N') && confirm[1] == '\0'){
+ drawwin(win, 4, msg, history, histcount);
+ continue;
+ } else if(sscanf(confirm, "%d", &guess) != 1){
+ drawwin(win, 4, "that's not a number, try again", history, histcount);
+ continue;
+ }
+ } else if(sscanf(buf, "%d", &guess) != 1){
+ drawwin(win, 4, "that's not a number, try again", history, histcount);
+ continue;
+ }
+ //this is too "complicated" for no reason at all
+
+ int diff = abs(guess - correct);
+ int artpick;
+ if(diff <= 10){
+ artpick = 3;
+ } else if(diff > 30){
+ artpick = 4;
+ } else {
+ artpick = rand() % 2;
+ }
+
+ if(guess < correct){
+ if(histcount < maxhistory){
+ history[histcount++] = guess;
+ } else {
+ for(int i = 0; i < maxhistory - 1; i++) history[i] = history[i+1];
+ history[maxhistory-1] = guess;
+ }
+ drawwin(win, artpick, "number too low try again", history, histcount);
+ }else if(guess > correct){
+ if(histcount < maxhistory){
+ history[histcount++] = guess;
+ } else {
+ for(int i = 0; i < maxhistory - 1; i++) history[i] = history[i+1];
+ history[maxhistory-1] = guess;
+ }
+ drawwin(win, artpick, "number too high try again", history, histcount);
+ }else {
+ drawwin(win, artpick, "yes!! correct! squeaaakk!~", history, histcount);
+ solved = 1;
+ }
+ }
+
+ if(!quitgame){
+ usleep(2000000);
+ addstat(&rat.fun);
+ }
+
+ delwin(win);
+ endwin();
}