aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavid <[email protected]>2026-04-30 11:24:17 -0300
committerdavid <[email protected]>2026-04-30 11:24:17 -0300
commit6e132af56299b9ad939a237e199bc0f1d2499920 (patch)
treedcb8e79011d2fd8f37bdec7af73dbb4f7ad26b07
parent085c78540c5d980ea39208581185b5b7f1aef3f5 (diff)
downloadpetratc-6e132af56299b9ad939a237e199bc0f1d2499920.tar.gz
petratc-6e132af56299b9ad939a237e199bc0f1d2499920.zip
changed name of files and fixed up a couple things
-rw-r--r--.gitignore2
-rw-r--r--Makefile4
-rwxr-xr-xcpetratbin0 -> 17144 bytes
-rw-r--r--petratc.c (renamed from cpetrat.c)76
4 files changed, 47 insertions, 35 deletions
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
--- /dev/null
+++ b/cpetrat
Binary files differ
diff --git a/cpetrat.c b/petratc.c
index aa1d0b6..0d6308e 100644
--- a/cpetrat.c
+++ b/petratc.c
@@ -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;
}