tamagotchi.h - brcon2024-hackathons - Bitreichcon 2024 Hackathons
(HTM) git clone git://bitreich.org/brcon2024-hackathons git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/brcon2024-hackathons
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) Submodules
---
tamagotchi.h (3324B)
---
1 #ifndef TAMAGOTCHI_TAMAGOTCHI_H
2 #define TAMAGOTCHI_TAMAGOTCHI_H
3
4 #include <stdio.h>
5 #include <string.h>
6 #include <stdbool.h>
7 #include <stdlib.h>
8 #include <time.h>
9
10 struct Tamagotchi{
11
12 char name[50];
13 int age;
14 int age_of_death;
15 int hunger;
16 int happiness;
17 bool alive;
18
19 };
20
21 void tamagotchi_sad(){
22 printf(" .^._.^.\n"
23 " | ; ; |\n"
24 " ( --- )\n"
25 " .' '.\n"
26 " |/ \\|\n"
27 " \\ /-\\ /\n"
28 " V V\n");
29 }
30
31 void tamagotchi_happy(){
32 printf(" .^._.^.\n"
33 " | . . |\n"
34 " ( \\_/ )\n"
35 " .' '.\n"
36 " |/ \\|\n"
37 " \\ /-\\ /\n"
38 " V V\n");
39 }
40
41 void clearScreen(){
42 #ifdef _WIN32
43 system("cls");
44 #else
45 system("clear");
46 #endif
47 }
48
49 void print_menu(){
50 printf("What would you like to do?\n");
51 printf("1. Feed\n");
52 printf("2. Play\n");
53 printf("3. Quit\n");
54 printf("(Any onther number) Do nothing\n");
55 }
56
57 void tamagotchi_status_and_menu(struct Tamagotchi* tamagotchi){
58
59 if(tamagotchi->hunger > 60 || tamagotchi->happiness <= 25){
60 tamagotchi_sad();
61 }else {
62 tamagotchi_happy();
63 }
64 printf("My name is %s, and I'm %d years old!\n",tamagotchi->name,tamagotchi->age);
65
66 if (tamagotchi->hunger > 60){
67 printf("Hunger: (%d%%)\n\tI am starving :( \n",tamagotchi->hunger);
68 } else if (tamagotchi->hunger > 25){
69 printf("Hunger: (%d%%)\n\tI am hungry \n",tamagotchi->hunger);
70 } else{
71 printf("Hunger: (%d%%)\n\tI am not hungry :)\n",tamagotchi->hunger);
72 }
73
74 if (tamagotchi->happiness > 50){
75 printf("Happiness: (%d%%)\n\tI am happy :) \n",tamagotchi->happiness);
76 } else if (tamagotchi->happiness > 25){
77 printf("Happiness: (%d%%)\n\tI am a okay \n",tamagotchi->happiness);
78 } else{
79 printf("Happiness: (%d%%)\n\tI am sad :( \n",tamagotchi->happiness);
80 }
81
82 print_menu();
83 }
84
85 void tamagotchi_name(struct Tamagotchi* tamagotchi){
86 char name_var[11];
87
88 printf("Hello, my name is ...\n");
89
90 scanf(" %[^\n]s",name_var);
91
92 while (strlen(name_var)>10 || strlen(name_var)<0){
93 printf("Please choose another name I wont remember that\nMy name must be between 0 and 10 characters.\n");
94
95 scanf(" %[^\n]s",name_var);
96 }
97
98 strcpy(tamagotchi->name,name_var);
99 }
100
101 void feed(struct Tamagotchi *tamagotchi){
102 if (tamagotchi->hunger < 5){
103 tamagotchi->hunger=0;
104 } else{
105 tamagotchi->hunger-=5;
106 }
107
108 }
109
110 void play(struct Tamagotchi *tamagotchi){
111 if (tamagotchi->happiness > 96){
112 tamagotchi->happiness=100;
113 } else{
114 tamagotchi->happiness+=5;
115 }
116 }
117
118 void check_status(struct Tamagotchi *tamagotchi){
119 clearScreen();
120
121 if (tamagotchi->happiness <= 0){
122 tamagotchi_sad();
123 printf("I died from being unhappy!\n");
124 tamagotchi->alive = false;
125 } else if (tamagotchi->hunger >= 100){
126 tamagotchi_sad();
127 printf("I died from being too hungry!\n");
128 tamagotchi->alive = false;
129 } else if (tamagotchi->age >= tamagotchi->age_of_death){
130 tamagotchi_sad();
131 printf("I died from old age!\n");
132 tamagotchi->alive = false;
133 } else {
134 tamagotchi_status_and_menu(tamagotchi);
135 }
136 }
137
138 #endif //TAMAGOTCHI_TAMAGOTCHI_H