aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavid <[email protected]>2026-07-04 00:11:12 -0300
committerdavid <[email protected]>2026-07-04 00:11:12 -0300
commit7b460110b139c0e8a488f695459c150a517d34b6 (patch)
tree5bfad11ecc9d1c5a17d38a362e2e3136da848b81
parent95295e94f2ed3953e84e7f0b3c024941ed3f6862 (diff)
downloadpetratc-7b460110b139c0e8a488f695459c150a517d34b6.tar.gz
petratc-7b460110b139c0e8a488f695459c150a517d34b6.zip
made the 'main menu' also ncurses because i was bored and remembered this thing existed and i wanna work on it more but i don't really have any idea what else to add to it...
-rw-r--r--Makefile5
-rw-r--r--petratc.c105
2 files changed, 81 insertions, 29 deletions
diff --git a/Makefile b/Makefile
index a1e2ae7..ba710d9 100644
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,12 @@
CC = gcc
-CFLAGS = -Wall -Wextra -lncurses
+CFLAGS = -Wall -Wextra -O2 -pipe
+LDLIBS = -lncurses -ltinfo
TARGET = petratc
SRC = petratc.c $(wildcard games/*.c)
PREFIX = /usr/local
$(TARGET): $(SRC)
- $(CC) $(CFLAGS) -o $(TARGET) $(SRC)
+ $(CC) $(CFLAGS) -o $(TARGET) $(SRC) $(LDLIBS)
install: $(TARGET)
install -D $(TARGET) $(DESTDIR)$(PREFIX)/bin/$(TARGET)
diff --git a/petratc.c b/petratc.c
index 3b3adad..f2f8c34 100644
--- a/petratc.c
+++ b/petratc.c
@@ -1,6 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
+#include <ncurses.h>
+#include <string.h>
#include <sys/stat.h>
#include "rat.h"
#include "defs.h"
@@ -87,45 +89,94 @@ void setstat(){
}
-void printrat(){
-
- printf("%s\n", ratart);
+void printrat(WINDOW *win){
+
+ werase(win);
+ box(win, 0, 0);
+
+ int row = 1;
+ char artcopy[256];
+ strncpy(artcopy, ratart, 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++;
int howmany = sizeof(messages) / sizeof(messages[0]);
- printf("%s\n", messages[rand() % howmany]);
- 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);
+ mvwprintw(win, row++, 2, "%s", messages[rand() % howmany]);
+
+ row++;
+ mvwprintw(win, row++, 2, "hunger: %.2f", rat.hunger);
+ mvwprintw(win, row++, 2, "love: %.2f", rat.love);
+ mvwprintw(win, row++, 2, "fun: %.2f", rat.fun);
+ mvwprintw(win, row++, 2, "clean: %.2f", rat.clean);
+ mvwprintw(win, row++, 2, "health: %.2f", rat.health);
+ row++;
+ mvwprintw(win, row++, 2, "1: play a game! (fun up)");
+ mvwprintw(win, row++, 2, "2: go to the maze (hunger up)");
+ mvwprintw(win, row++, 2, "4: take a shower! (clean up)");
+ mvwprintw(win, row++, 2, "9: print me! (refreshes stats)");
+ mvwprintw(win, row++, 2, "0: exit...");
+
+ wrefresh(win);
}
-
-
+
+
int main(){
srand(time(NULL));
-int choice;
int truing = 1;
-
+
load();
setstat();
- printrat();
-
+
+ initscr();
+ cbreak();
+ noecho();
+ keypad(stdscr, TRUE);
+ curs_set(0);
+
+ WINDOW *win = newwin(20, 40, 1, 1);
+ printrat(win);
+
while(truing){
- printf("1: play a game! (fun up), 2: go down to the maze... (hunger up), 4: take a shower! (clean up), 9: print me!, 0: exit...\n");
-
- if(scanf("%d", &choice) != 1){
- while(getchar() != '\n'); //flush the bad input if you're a bad boy and put q instead of 1
- continue;
- }
- switch(choice){
-
- case 1: gameguess(); break;
- case 2: gamemaze(); printf("the maze is really dark squeak...\n\n"); break;
- case 4: gamecatch(); printf("your rat feels cleaner!\n\n"); break;
- case 9: printrat(); break;
- case 0: truing = 0; break;
+ int choice = wgetch(win);
+
+ switch(choice){
+
+ case '1':
+ endwin();
+ gameguess();
+ refresh();
+ break;
+ case '2':
+ endwin();
+ gamemaze();
+ printf("the maze is really dark squeak...\n\n");
+ refresh();
+ break;
+ case '4':
+ endwin();
+ gamecatch();
+ printf("your rat feels cleaner!\n\n");
+ refresh();
+ break;
+ case '9': break;
+ case '0': truing = 0; break;
}
+
+ if(truing) printrat(win);
}
-
-
+
+ delwin(win);
+ endwin();
+
save();
printf("bye bye~~\n");
return(0);
}
+