From 6e132af56299b9ad939a237e199bc0f1d2499920 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 30 Apr 2026 11:24:17 -0300 Subject: changed name of files and fixed up a couple things --- .gitignore | 2 +- Makefile | 4 +- cpetrat | Bin 0 -> 17144 bytes cpetrat.c | 134 -------------------------------------------------------- petratc.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 149 insertions(+), 137 deletions(-) create mode 100755 cpetrat delete mode 100644 cpetrat.c create mode 100644 petratc.c diff --git a/.gitignore b/.gitignore index baa6c70..0bd93cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -cpetrat +petratc diff --git a/Makefile b/Makefile index 4c4ba4b..a9b1c60 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC = gcc CFLAGS = -Wall -Wextra -TARGET = cpetrat -SRC = cpetrat.c +TARGET = petratc +SRC = petratc.c PREFIX = /usr/local $(TARGET): $(SRC) diff --git a/cpetrat b/cpetrat new file mode 100755 index 0000000..4a64b8e Binary files /dev/null and b/cpetrat differ diff --git a/cpetrat.c b/cpetrat.c deleted file mode 100644 index aa1d0b6..0000000 --- a/cpetrat.c +++ /dev/null @@ -1,134 +0,0 @@ -#include -#include -#include -#include -#include "rat.h" - -void save(void) { - char path[256]; -#ifdef __APPLE__ - snprintf(path, sizeof(path), "%s/Library/Application Support/rat", getenv("HOME")); -#else - snprintf(path, sizeof(path), "%s/.local/share/rat", getenv("HOME")); -#endif - mkdir(path, 0755); -#ifdef __APPLE__ - snprintf(path, sizeof(path), "%s/Library/Application Support/rat/rat.txt", getenv("HOME")); -#else - snprintf(path, sizeof(path), "%s/.local/share/rat/rat.txt", getenv("HOME")); -#endif - - FILE *f = fopen(path, "w"); - if (!f) return; - - fprintf(f, "%f\n%f\n%f\n%f\n%f\n%d\n", - rat.hunger, rat.love, rat.fun, - rat.clean, rat.health, rat.age); - fclose(f); -} - -void load(void) { - char path[256]; -#ifdef __APPLE__ - snprintf(path, sizeof(path), "%s/Library/Application Support/rat/rat.txt", getenv("HOME")); -#else - snprintf(path, sizeof(path), "%s/.local/share/rat/rat.txt", getenv("HOME")); -#endif - FILE *f = fopen(path, "r"); - if (!f) { - //first run - rat.hunger = 100.0f; - rat.love = 100.0f; - rat.fun = 100.0f; - rat.clean = 100.0f; - rat.health = 100.0f; - rat.age = time(NULL); - return; - } - - fscanf(f, "%f\n%f\n%f\n%f\n%f\n%d\n", - &rat.hunger, &rat.love, &rat.fun, - &rat.clean, &rat.health, &rat.age); - fclose(f); -} - -float decay(float current, int timepassed, float rate) { - float result = current - (timepassed * rate); - return result < 0.0f ? 0.0f : result; -} - -void setstat(){ - //int n = rand() % 100; - int timenow = time(NULL); - int newage = timenow - rat.age; - - rat.hunger = decay(100.0f, newage, 0.005f); - rat.love = decay(100.0f, newage, 0.002f); - rat.fun = decay(100.0f, newage, 0.006f); - rat.clean = decay(100.0f, newage, 0.0002f); - rat.health = decay(100.0f, newage, 0.00002f); - - - rat.age = timenow; //while asking grok if the ifdefs for the mac path where fine he said something about time() returning a 64 int in mac but i don't know what that means so i'll ignore it -} - -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", rat. hunger, rat.love, rat.fun, rat.clean, rat.health); - -} - -void gameguess(){ - int guess; - int solved = 0; - int range = 100; - - int correct = (rand() % (range + 1)); - - printf("let's play a game, squeak!~ you gues a number between 0 and %d!\n", range); - - - while(solved != 1){ - - scanf("%d", &guess); - - 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;} - } - - - if(rat.fun < 98.5){rat.fun += 1.5;} else {rat.fun += 0.05;} //stupid function but it's smart if you think about it. just ignore it - -} - -int main(){ -srand(time(NULL)); -int choice; -int truing = 1; - - load(); - setstat(); - printrat(); - - while(truing){ - printf("1: play a game! (fun up), 9: print me!, 0: exit...\n"); - scanf("%d", &choice); - switch(choice){ - - case 1: gameguess(); break; - case 9: printrat(); break; - case 0: truing = 0; break; - } - } - - - save(); - printf("bye bye~~\n"); - return(0); -} diff --git a/petratc.c b/petratc.c new file mode 100644 index 0000000..0d6308e --- /dev/null +++ b/petratc.c @@ -0,0 +1,146 @@ +#include +#include +#include +#include +#include "rat.h" + +#ifdef __APPLE__ + #define ratpath "%s/Library/Application Support/rat" + #define ratsave "%s/Library/Application Support/rat/rat.txt" +#else + #define ratpath "%s/.local/share/rat" + #define ratsave "%s/.local/share/rat/rat.txt" +#endif + +void save(void) { + char path[256]; + snprintf(path, sizeof(path), ratpath, getenv("HOME")); + mkdir(path, 0755); + snprintf(path, sizeof(path), ratsave, getenv("HOME")); + + FILE *f = fopen(path, "w"); + if (!f) return; + fprintf(f, "%f\n%f\n%f\n%f\n%f\n%d\n", + rat.hunger, rat.love, rat.fun, rat.clean, rat.health, rat.age); + fclose(f); +} + +void load(void) { + char path[256]; + snprintf(path, sizeof(path), ratsave, getenv("HOME")); + + FILE *f = fopen(path, "r"); + if (!f) { + rat.hunger = 100.0f; + rat.love = 100.0f; + rat.fun = 100.0f; + rat.clean = 100.0f; + rat.health = 100.0f; + rat.age = time(NULL); + return; + } + fscanf(f, "%f\n%f\n%f\n%f\n%f\n%d\n", + &rat.hunger, &rat.love, &rat.fun, &rat.clean, &rat.health, &rat.age); + fclose(f); +} + +float decay(float current, int timepassed, float rate) { + float result = current - (timepassed * rate); + return result < 0.0f ? 0.0f : result; +} + +void setstat(){ + int timenow = time(NULL); + int newage = timenow - rat.age; + + rat.hunger = decay(rat.hunger, newage, 0.005f); + rat.love = decay(rat.love, newage, 0.002f); + rat.fun = decay(rat.fun, newage, 0.006f); + rat.clean = decay(rat.clean, newage, 0.0002f); + rat.health = decay(rat.health, newage, 0.00002f); + + + rat.age = timenow; //thinking about this makes my cortisol spike so i'll just ignore it even more +} + +//stupid function but it's smart if you think about it. just ignore it +void addstat(float *guy){ + + if(*guy < 98.5){ + *guy += 1.5; + } else{*guy += 0.05;} +} + +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", + rat.hunger, rat.love, rat.fun, rat.clean, rat.health); + +} + +void gameguess(){ + int guess; + int solved = 0; + int range = 100; + + int correct = (rand() % (range + 1)); + + printf("let's play a game, squeak!~ you gues a number between 0 and %d!\n", range); + + + while(solved != 1){ + + scanf("%d", &guess); + + 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;} + } + + addstat(&rat.fun); + +} + +void showergame(){ + +//ignore this i'm working on it + + + + addstat(&rat.clean); +} + + + +int main(){ +srand(time(NULL)); +int choice; +int truing = 1; + + load(); + setstat(); + printrat(); + + while(truing){ + printf("1: play a game! (fun up), 4: take a shower!, 9: print me!, 0: exit...\n"); + scanf("%d", &choice); + switch(choice){ + + case 1: gameguess(); break; + case 4: showergame(); break; + case 8: printf("%d\n", rat.age); break; + case 9: printrat(); break; + case 0: truing = 0; break; + } + } + + + save(); + printf("bye bye~~\n"); + return(0); +} -- cgit v1.3-2-g0d8e