diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | Makefile | 4 | ||||
| -rwxr-xr-x | cpetrat | bin | 0 -> 17144 bytes | |||
| -rw-r--r-- | petratc.c (renamed from cpetrat.c) | 76 |
4 files changed, 47 insertions, 35 deletions
@@ -1 +1 @@ -cpetrat +petratc @@ -1,7 +1,7 @@ CC = gcc CFLAGS = -Wall -Wextra -TARGET = cpetrat -SRC = cpetrat.c +TARGET = petratc +SRC = petratc.c PREFIX = /usr/local $(TARGET): $(SRC) Binary files differ@@ -4,39 +4,33 @@ #include <sys/stat.h> #include "rat.h" -void save(void) { - char path[256]; #ifdef __APPLE__ - snprintf(path, sizeof(path), "%s/Library/Application Support/rat", getenv("HOME")); + #define ratpath "%s/Library/Application Support/rat" + #define ratsave "%s/Library/Application Support/rat/rat.txt" #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")); + #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); + 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 + snprintf(path, sizeof(path), ratsave, getenv("HOME")); + FILE *f = fopen(path, "r"); if (!f) { - //first run rat.hunger = 100.0f; rat.love = 100.0f; rat.fun = 100.0f; @@ -45,10 +39,8 @@ void load(void) { 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); + &rat.hunger, &rat.love, &rat.fun, &rat.clean, &rat.health, &rat.age); fclose(f); } @@ -58,18 +50,25 @@ float decay(float current, int timepassed, float rate) { } 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.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){ - 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 + if(*guy < 98.5){ + *guy += 1.5; + } else{*guy += 0.05;} } void printrat(){ @@ -77,7 +76,8 @@ 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); + 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); } @@ -102,11 +102,21 @@ void gameguess(){ }else {printf("yes!! correct! squeaaakk!~\n"); solved = 1;} } + addstat(&rat.fun); + +} - 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 +void showergame(){ +//ignore this i'm working on it + + + + addstat(&rat.clean); } + + int main(){ srand(time(NULL)); int choice; @@ -117,11 +127,13 @@ int truing = 1; printrat(); while(truing){ - printf("1: play a game! (fun up), 9: print me!, 0: exit...\n"); + 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; } |
