pet-rock/rock/rock.c
2022-05-05 11:33:25 -06:00

444 lines
19 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <windows.h>
char in;
int health = 100;
int hunger = 100;
int happiness = 100;
time_t currenttime;
time_t oldtime;
time_t starttime;
int healthhold = 0;
int hungerhold = 0;
int happinesshold = 0;
int firstplay = 1;
char rock[24][26] = {
{" \262\333\333\333\333 "},
{" \333 \260\260\262\333 "},
{" \333 \261\260\260\262\333\333 "},
{" \333 \261\261\261 \262\333 "},
{" \333\333\333 \260\260\261\261\261 \262\262\333 "},
{" \262\262 \261\261\260\261\261\261\261\262\262\333 "},
{" \262\262 \261\261 \260\260\260\261\261\261\261\262\262\262\333 "},
{" \262 \260\261 \261 \260\261\261\261\261\261\262\262\333 "},
{" \262 \260\261\261 \260\260\261\260\260\261\261\261\261\261\262\262\333 "},
{" \262 \260\262 \261\261\260\260\260\261\261\261\261\261\261\262\333 "},
{" \262 \261\261\261 \260\260\261\261\260\260\261\260\261\261\261\262\262\333 "},
{" \262 \260\260\261\261 \260\261\261\261\260\260\260\260\260\261\261\262\262\333 "},
{" \262\260\261\260\260\261\261\260\261\261\261\261\260\261\261\261\260\261\260\262\262\333 "},
{" \262\261 \260\261\261\261\261\261\261\261\261\260\261\261\261\261\262\261\261\262\333 "},
{"\262\262\260\261\261\261\262\261\260\260\261\260\261\260\261\261\261\261\261\262\261\262\262\333 "},
{"\262\260 \261\261\261\262\260\260\260\261\261\261\261\262\261\261\261\261\261\261\261\262\333 "},
{"\333\260\261\261\261\262\262\260\261\261\261\261\261\261\261\261\261\261\261\261\262\261\262\333 "},
{"\333\261\261\261\261\262\261\261\261\261\261\261\261\261\262\261\261\261\261\261\261\261\262\262\333"},
{"\333\262\261\261\262\262\261\261\260\260\261\261\261\261\261\260\261\260\261\261\261\262\262\262\333"},
{"\333\261\262\261\261\262\261\260\260\261\261\261\261\261\261\260\261\260\260\262\261\262\262\262\333"},
{"\333\262\262\262\261\262\261\261\261\262\261\261\262\261\261\261\261\261\260\262\262\262\262\333 "},
{" \333\333\333\333\333\262\261\261\261\261\262\261\261\260\260\261\262\262\262\262\262\333 "},
{" \333\262\262\262\261\261\261\261\260\260\260\262\262\262\262\333\333 "},
{" \333\333\333\333\333\333\333\333\333\333\333\333\333\333 "}
};
char healthrock[24][30] = { //`yellow .red ,reset
{" \262\333\333\333\333 "},
{" \333 \260\260\262\333 "},
{" \333 \261\260\260\262\333\333 "},
{" \333 \261\261\261 \262\333 "},
{" \333\333\333 \260\260\261\261\261 \262\262\333 "},
{" \262\262 \261\261\260\261\261\261\261\262\262\333 "},
{" \262\262 \261\261 \260\260\260\261\261\261\261\262\262\262\333 "},
{" \262 \260\261 \261 \260\261\261\261\261\261\262\262\333 "},
{" \262 \260\261\261 \260\260\261\260\260\261\261\261\261\261\262\262\333 "},
{" \262 \260\262 \261\261\260\260\260\261\261\261\261\261\261\262\333 "},
{" \262 \261\261\261 \260\260\261\261\260\260\261\260\261\261\261\262\262\333 "},
{" \262 \260\260\261\261 \260\261\261\261\260\260\260\260\260\261\261\262\262\333 "},
{" \262\260\261\260\260\261\261\260\261\261\261\261\260\261\261\261\260\261\260\262\262\333 "},
{" \262\261 \260\261\261\261\261\261\261\261\261\260\261\261\261\261\262\261\261\262\333 "},
{"\262\262\260\261\261\261\262\261\260\260\261\260\261\260\261\261\261\261\261\262\261\262\262\333 "},
{"\262\260 \261\261\261\262\260\260\260\261\261\261\261\262\261\261\261\261\261\261\261\262\333 "},
{"\333\260\261\261\261\262\262\260\261\261`\311\315\315\321\315\321\315\315\273,\261\262\261\262\333 "},
{"\333\261\261\261\261\262\261\261\261\261`\272 \263.+`\263 \272,\261\261\261\262\262\333"},
{"\333\262\261\261\262\262\261\261\260\260`\310\315\315\317\315\317\315\315\274,\261\261\262\262\262\333"},
{"\333\261\262\261\261\262\261\260\260\261\261\261\261\261\261\260\261\260\260\262\261\262\262\262\333"},
{"\333\262\262\262\261\262\261\261\261\262\261\261\262\261\261\261\261\261\260\262\262\262\262\333 "},
{" \333\333\333\333\333\262\261\261\261\261\262\261\261\260\260\261\262\262\262\262\262\333 "},
{" \333\262\262\262\261\261\261\261\260\260\260\262\262\262\262\333\333 "},
{" \333\333\333\333\333\333\333\333\333\333\333\333\333\333 "}
};
char cake[7][20] = { //`bright yellow .yellow w bg -white with bg ,reset
{"` $$ $$ $$ "},
{", \263\263 \263\263 \263\263 "},
{"___\263\263__\263\263__\263\263___"},
{".\263- * * * * * * *.\263"},
{".\263-* * * * * * * .\263"},
{".\263- * * * * * * *.\263"},
{"\300\304\304\304\304\304\304\304\304\304\304\304\304\304\304\331,"}
};
char balloon[28][14] = { //` light red ,reset
{"` \333\333\333 "},
{" \333\333\333\333\333\333\333 "},
{" \333\333\333,\261`\333\333\333\333\333 "},
{" \333\333,\261\262\261`\333\333\333\333 "},
{"\333\333\333\333,\261`\333\333\333\333\333\333"},
{"\333\333\333\333\333\333\333\333\333\333\333"},
{"\333\333\333\333\333\333\333\333\333\333\333"},
{" \333\333\333\333\333\333\333\333\333 "},
{" \333\333\333\333\333\333\333\333\333 "},
{" \333\333\333\333\333\333\333 "},
{" \333\333\333 ,"},
{" \263 "},
{" \\ "},
{" \\ "},
{" \263 "},
{" \263 "},
{" / "},
{" / "},
{" \263 "},
{" \263 "},
{" \263 "},
{" \\ "},
{" \\ \262"},
{" \263 \262"},
{" \263 \262"},
{" \\ \262"},
{" \\ \262\260"},
{" \\\262\261"}
};
char instructions[22][77] = {
{"\332\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\277"},
{"\263 INSTRUCTIONS FOR YOUR NEW PET ROCK \263"},
{"\303\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\264"},
{"\263 Congratulations on buying a new pet rock! \263"},
{"\263 Pet rocks are very simple to care for, but they need a lot of care. \263"},
{"\263 \263"},
{"\263 Standard care procedure for your pet rock follows: \263"},
{"\263 -Press '1' to apply a bandage, in case your pet rock is damaged. \263"},
{"\263 -Press '2' to feed your pet rock. (They love a nice, big cake) \263"},
{"\263 -Press '3' to give your pet rock some entertainment. \263"},
{"\263 Make sure you take breaks between caring for your pet rock, as the - \263"},
{"\263 - rock will not take kindly to such overstimulation. \263"},
{"\263 \263"},
{"\263 Your pet rock comes equipped with a state-of-the-art wellbeing sensor. \263"},
{"\263 The sensor informs you of your pet rock's health, hunger, and happiness. \263"},
{"\263 (abbreviated as 'Happy') \263"},
{"\263 Surely nothing good will happen when one of these values reaches '0%' \263"},
{"\263 But you might find out what happens anyway! \263"},
{"\263 \263"},
{"\263 Best of wishes to your and your new pet rock's wellbeing, \263"},
{"\263 -Audy \263"},
{"\300\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\331"}
};
char passing[16][77] = {
{"\332\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\227"},
{"\263 THE PASSING OF YOUR PET ROCK \263"},
{"\303\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\264"},
{"\263As with the passing of any pet, the passing of your pet rock can be tough.\263"},
{"\263 And so we've decided to remedy that issue with the pet rock: \263"},
{"\263The pet rock cannot die, and your pet rock has not, despite what may seem.\263"},
{"\263 \263"},
{"\263This is one of the many traits you may find about your pet rock: \263"},
{"\263They are very loyal to their caretaker, and will not leave their side - \263"},
{"\263 - no matter what!\263"},
{"\263 \263"},
{"\263 It's as simple as that, your pet rock lives on! \263"},
{"\263 \263"},
{"\263 Best of wishes to you and your pet rock, \263"},
{"\263 -Audy \263"},
{"\300\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\304\331"}
};
void hidecursor() { //i hate windows, and you do too
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
info.dwSize = 100;
info.bVisible = FALSE;
SetConsoleCursorInfo(consoleHandle, &info);
} //i dont even know how this works, it looks like c++ with those .'s and such
void printrock() {
printf("\033[5;12H"); //balloon
for (int i = 0; i < 27; i++) {
printf(" \033[B\033[12D");
}
printf("\033[35;47H"); //cake
for (int i = 0; i < 7; i++) {
printf(" \033[B\033[17D");
}
printf("\033[19;20H");
for (int i = 0; i < 24; i++) {
for (int j = 0; j < 26; j++) {
printf("%c",rock[i][j]);
}
printf("\033[B\033[25D");
}
}
void printhealthrock() {
printf("\033[19;20H");
for (int i = 0; i < 24; i++) {
for (int j = 0; j < 30; j++) {
switch(healthrock[i][j]) {
case '`' :
printf("\033[33;103m");
break;
case '.' :
printf("\033[31;103m");
break;
case ',' :
printf("\033[0m");
break;
default :
printf("%c",healthrock[i][j]);
}
}
printf("\033[B\033[25D");
}
}
void printcake() {
printf("\033[35;47H");
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 20; j++) {
switch(cake[i][j]) {
case '`' :
printf("\033[93m");
break;
case '.' :
printf("\033[33;43m");
break;
case '-' :
printf("\033[97;43m");
break;
case ',' :
printf("\033[0m");
break;
default :
printf("%c",cake[i][j]);
}
}
printf("\033[B\033[16D");
}
}
void printballoon() {
printf("\033[5;12H");
for (int i = 0; i < 27; i++) {
for (int j = 0; j < 14; j++) {
switch(balloon[i][j]) {
case '`' :
printf("\033[91m");
break;
case ',' :
printf("\033[0m");
break;
default :
printf("%c",balloon[i][j]);
}
}
printf("\033[B\033[11D");
}
}
void dead(int why) { //:(
system("cls");
system("mode con: cols=76 lines=16");
printf("\033[30;107m\033[H");
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 76; j++) {
printf("%c",passing[i][j]);
}
if (i != 15) {
printf("\n");
}
}
getch();
initialize();
}
void initialize() {
if (firstplay) {
system("mode con: cols=76 lines=22");
hidecursor();
printf("\033]0;Pet Rock\x1b\x5c"); //set conlse title to Pet Rock
printf("\033[30;107m\033[H");
for (int i = 0; i < 22; i++) {
for (int j = 0; j < 76; j++) {
printf("%c",instructions[i][j]);
}
if (i != 21) {
printf("\n");
}
}
getch();
}
printf("\033[m");
system("cls");
health = 100;
hunger = 100;
happiness = 100;
healthhold = 0;
hungerhold = 0;
happinesshold = 0;
system("mode con: cols=64 lines=68");
starttime = time(NULL);
printrock();
printf("\033[2;1H----------------------------------------------------------------");
printf("\033[64;1H----------------------------------------------------------------");
}
int main() {
initialize();
while(1) {
currenttime = time(NULL);
currenttime = currenttime - starttime; //seconds the games been going
if (oldtime != currenttime) { //runs once a second
if (health - 1 > 0) {
health--;
} else {
dead(0);
}
if (hunger - 1 > 0) {
hunger--;
} else {
dead(1);
}
if (happiness - 1 > 0) {
happiness--;
} else {
dead(2);
}
if (healthhold == 13) {
healthhold = 0;
printrock();
} else if (healthhold == 3) {
printf("\033[HYour pet rock feels better! ");
if ((health + 20) > 100) {
health = 100;
} else {
health = health + 20;
}
printhealthrock();
healthhold++;
} else if (healthhold) {
healthhold++;
}
if (hungerhold == 13) {
hungerhold = 0;
printrock();
} else if (hungerhold == 3) {
printf("\033[HYour pet rock is well fed! ");
if ((hunger + 20) > 100) {
hunger = 100;
} else {
hunger = hunger + 20;
}
printcake();
hungerhold++;
} else if (hungerhold) {
hungerhold++;
}
if (happinesshold == 13) {
happinesshold = 0;
printrock();
} else if (happinesshold == 3) {
printf("\033[HYour pet rock is entertained! ");
if ((happiness + 20) > 100) {
happiness = 100;
} else {
happiness = happiness + 20;
}
printballoon();
happinesshold++;
} else if (happinesshold) {
happinesshold++;
}
}
oldtime = currenttime; //makes the once per second loop work
printf("\033[65;1HHealth: %d%% \nHunger: %d%% \nHappy : %d%% ",health,hunger,happiness);
printf("\033[68;15H\"State-of-the-art wellbeing sensor\"");
printf("\033[65;14H");
for (int j = 0; j < (health / 2); j++) {
printf("\260");
}
printf(" ");
printf("\033[66;14H");
for (int j = 0; j < (hunger / 2); j++) {
printf("\261");
}
printf(" ");
printf("\033[67;14H");
for (int j = 0; j < (happiness / 2); j++) {
printf("\262");
}
printf(" ");
if (!(healthhold) && !(hungerhold) && !(happinesshold)) {
if ((health >= 90) && (hunger >= 90) && (happiness >= 90)) { //shouldve done a switch statement
printf("\033[HYour pet rock is doing great! ");
} else if ((health >= 75) && (hunger >= 75) && (happiness >= 75)) {
printf("\033[HYour pet rock is doing well. ");
} else if ((health >= 50) && (hunger >= 50) && (happiness >= 50)) {
printf("\033[HYour pet rock is doing fine. ");
} else if ((health >= 30) && (hunger >= 30) && (happiness >= 30)) {
printf("\033[HYour pet rock isn't doing so well!");
} else if ((health >= 10) && (hunger >= 10) && (happiness >= 10)) {
printf("\033[HYour pet rock is surely done for! ");
}
}
if (kbhit()) {
in = getch();
if (in == 0 || in == 0xE0) in = getch(); //dang ol windows makes you call functions and arrows keys twice to get the input
switch(in) {
case 49 : //1 health
if (!(healthhold) && !(hungerhold) && !(happinesshold)) {
healthhold = 1;
printf("\033[HApplying bandage... ");
}
break;
case 50 : //2 hunger
if (!(healthhold) && !(hungerhold) && !(happinesshold)) {
hungerhold = 1;
printf("\033[HBuying a cake... ");
}
break;
case 51 : //3 happiness
if (!(healthhold) && !(hungerhold) && !(happinesshold)) {
happinesshold = 1;
printf("\033[HInflating balloon... ");
}
break;
default :
printf("\a"); //bell, possibly annoying
break;
}
}
}
}