-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
81 lines (69 loc) · 2.88 KB
/
Copy pathmain.cpp
File metadata and controls
81 lines (69 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <string>
#include <emscripten.h>
int happiness = 50, fullness = 50, cleanliness = 50, health = 90;
std::string cat_name = "Сэм";
extern "C" {
EMSCRIPTEN_KEEPALIVE
void update_status() {
std::string message = "Меня зовут " + cat_name;
if (happiness > 80 && fullness > 80 && cleanliness > 80 && health > 80) {
message += " и я счастлив как никогда! /ᐠ-⩊-マ₊˚⊹♡₊ ⊹";
} else if (happiness <= 10 || fullness <= 10 || cleanliness <= 10 || health <= 10) {
EM_ASM({
alert("Игра окончена! Кот устал. Кот уходит. ᨐฅ");
});
emscripten_cancel_main_loop();
} else if (happiness <= 25 || fullness <= 25 || cleanliness <= 25 || health <= 25) {
message += " и мне очень плохо! /ᐠﹷ ‸ ﹷ ᐟ поухаживай за мной!";
}
else {
message += " и как я себя чувствую в процентах (а что такое проценты?..)";
}
std::string status = "Счастье: " + std::to_string(happiness) +
"%, Сытость: " + std::to_string(fullness) +
"%, Ухоженность: " + std::to_string(cleanliness) +
"%, Здоровье: " + std::to_string(health) + "%";
EM_ASM({
document.getElementById("status").innerText = UTF8ToString($0);
document.getElementById("dialogue").innerText = UTF8ToString($1);
}, status.c_str(), message.c_str());
}
EMSCRIPTEN_KEEPALIVE
void feed_cat() {
fullness = std::min(100, fullness + 20);
health = std::min(100, health + 10);
update_status();
}
EMSCRIPTEN_KEEPALIVE
void play_cat() {
happiness = std::min(100, happiness + 20);
fullness = std::max(0, fullness - 10);
cleanliness = std::max(0, cleanliness - 10);
if (fullness < 20 || cleanliness < 20) {
health = std::max(0, health - 5);
}
update_status();
}
EMSCRIPTEN_KEEPALIVE
void groom_cat() {
cleanliness = std::min(100, cleanliness + 20);
happiness = std::max(0, happiness - 10);
health = std::min(100, health + 5);
update_status();
}
EMSCRIPTEN_KEEPALIVE
void leave_cat() {
fullness = std::max(0, fullness - 5);
happiness = std::max(0, happiness - 5);
cleanliness = std::max(0, cleanliness - 5);
if (fullness < 30 || cleanliness < 30) {
health = std::max(0, health - 10);
}
update_status();
}
}
int main() {
emscripten_set_main_loop(update_status, 1, 1);
return 0;
}