Introduction
Introduction Statistics Contact Development Disclaimer Help
tamagotchi.c - brcon2024-hackathons - Bitreichcon 2024 Hackathons
git clone git://bitreich.org/brcon2024-hackathons git://enlrupgkhuxnvlhsf6lc3fz…
Log
Files
Refs
Tags
Submodules
---
tamagotchi.c (1550B)
---
1 #include "tamagotchi.h"
2 #include <pthread.h>
3 #include <unistd.h>
4
5 #define SIMULATION_SPEED 5
6
7 void *time_thread(void *arg){
8 struct Tamagotchi *tamagotchi = (struct Tamagotchi *)arg;
9
10 while (tamagotchi->alive){
11 sleep(SIMULATION_SPEED);
12
13 tamagotchi->hunger += 3;
14 tamagotchi->happiness -= 3;
15 tamagotchi->age++;
16
17 check_status(tamagotchi);
18 }
19
20 pthread_exit(NULL);
21 }
22
23 void create(struct Tamagotchi* tamagotchi){
24
25 //tamagotchi_name(tamagotchi);
26
27 strcpy(tamagotchi->name, "pazz0");
28 tamagotchi->age=0;
29 tamagotchi->age_of_death=rand() % 61 + 50;
30 tamagotchi->hunger=0;
31 tamagotchi->happiness=100;
32 tamagotchi->alive=true;
33 }
34
35 void life(struct Tamagotchi* tamagotchi){
36
37 int choice;
38
39 srand(time(NULL));
40
41 while(tamagotchi->alive){
42
43 scanf("%d", &choice);
44
45 if(tamagotchi->alive == false){
46 break;
47 }
48
49 if (choice == 1){
50 feed(tamagotchi);
51 } else if (choice == 2){
52 play(tamagotchi);
53 } else if (choice == 3){
54 break;
55 } else{
56 printf("I miss you :/ \n");
57 }
58
59 check_status(tamagotchi);
60
61 }
62
63 }
64
65 int main() {
66
67 struct Tamagotchi tamagotchi;
68
69 create(&tamagotchi);
70
71 tamagotchi_status_and_menu(&tamagotchi);
72
73 pthread_t tid;
74 if (pthread_create(&tid, NULL, time_thread, (void *)&tamagotchi) != …
75 perror("Error creating thread");
76 return 1;
77 }
78
79 life(&tamagotchi);
80
81 pthread_join(tid, NULL);
82
83 return 0;
84 }
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.