-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
268 lines (210 loc) · 8.09 KB
/
script.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
//COunters for each function
let food = 5;
let bath = 5;
let sleep = 5;
let bored = 0;
let training = 0;
//variable for kirby element
var kirby= document.querySelector("#kirby");
document.getElementById("displayFood").innerHTML = "Food = " + food ;
document.getElementById("displayBath").innerHTML = "Bath = " + bath ;
document.getElementById("displaySleep").innerHTML = "Sleep = " + sleep;
document.getElementById("displayBored").innerHTML = "Boredome = " + bored;
document.getElementById("displayTraining").innerHTML = "Training = " + training ;
//disable buttons First
document.getElementById("b1").classList.add('disabled');
document.getElementById("b2").classList.add('disabled');
document.getElementById("b3").classList.add('disabled');
document.getElementById("b4").classList.add('disabled');
document.getElementById("b5").classList.add('disabled');
//functions for each button
function feed(){
food++;
document.getElementById("displayFood").innerHTML = "Food =" + food ;
document.getElementById("message").innerHTML = "YUM!";
document.getElementById("message").style.fontSize = "500%";
//Check status
if(food <= 0 ){
kirby.src = "angryKirby.png"
}else {
kirby.src = "foodKirby.png"
}
}
function bathe(){
bath++;
document.getElementById("displayBath").innerHTML = "Bath = " + bath ;
document.getElementById("message").innerHTML = "AH! Clean!";
//check status
if(bath <= 0 ){
kirby.src = "angryKirby.png"
} else {
kirby.src = "bubbleKirby.png"
}
}
function nap(){
sleep++;
document.getElementById("displaySleep").innerHTML = "Sleep = " + sleep;
document.getElementById("message").innerHTML = "ZzZzZzZ";
//Check status
if(sleep <= 0 ){
kirby.src = "angryKirby.png"
}else {
kirby.src = "sleepKirby.png"
}
}
function fun(){
bored--;
document.getElementById("displayBored").innerHTML = "Boredome = " + bored;
document.getElementById("message").innerHTML = "Yay!";
//Check status
if(bored >= 5){
kirby.src = "angryKirby.png"
} else {
kirby.src = "kirbyHappy.png"
}
}
function train(){
training++;
kirby.src = "trainKirby.png"
document.getElementById("displayTraining").innerHTML = "Training = " + training ;
document.getElementById("message").innerHTML = "POWER UP!";
//Check status
if(training>= 10 && training < 20){
kirby.src = "kirbyNinja.png"
} else if(training >= 20 && training < 30){
kirby.src = "coolKirby.png"
} else if (training >= 30){
kirby.src = "sayanKirby.png"
} else{
kirby.src = "trainKirby.png"
}
}
//functions for decreasing each variable
//Function that increases boredom when called and checks if boredom is enough to get mad
function funLoss(){
bored++;
document.getElementById("message").innerHTML = "Getting Bored";
document.getElementById("displayBored").innerHTML = "Boredome = " + bored;
if(bored > 5){
kirby.src = "angryKirby.png"
document.getElementById("message").innerHTML = "I'M BORED!";
} else {
}
}
//Function that decreases bath ability and checks if bath is less than zero when he is angry
function bathLoss(){
bath--;
document.getElementById("message").innerHTML = "Getting Dirty!";
document.getElementById("displayBath").innerHTML = "Bath = " + bath ;
if(bath <= 0 ){
kirby.src = "angryKirby.png"
document.getElementById("message").innerHTML = "YO! I'm Dirty!";
} else {
}
}
//Function that decreases food and checks iffood is less than zero when he is angry
function foodLoss(){
food--;
document.getElementById("message").innerHTML = "Getting Hungry...";
document.getElementById("displayFood").innerHTML = "Food = " + food ;
if(food <= 0 ){
kirby.src = "angryKirby.png"
document.getElementById("message").innerHTML = "Don't Talk to me I'm Hungry!";
}else {
}
}
//Function that decreases sleep and checks if sleep is less than zero when he is angry
function sleepLoss(){
sleep--;
document.getElementById("message").innerHTML = "Getting Tired";
document.getElementById("displaySleep").innerHTML = "Sleep = " + sleep;
if(sleep <= 0 ){
kirby.src = "angryKirby.png"
document.getElementById("message").innerHTML = "I'm Exausted!";
}else {
}
}
//Function that decreases sleep and checks if sleep is less than zero when he is angry
function skillLoss(){
training--;
document.getElementById("displayTraining").innerHTML = "Training = " + training ;
if(training <= 10){
document.getElementById("message").innerHTML = "I feel out of shape...";
} else if (training > 10 && training < 20){
kirby.src = "kirbyNinja.png"
document.getElementById("message").innerHTML = "Getting out of shape...";
}
else if(training >= 20 && training < 30){
kirby.src = "coolKirby.png"
document.getElementById("message").innerHTML = "Getting out of shape...";
} else if (training >= 30){
kirby.src = "sayanKirby.png"
document.getElementById("message").innerHTML = "Getting out of shape...";
} else if (training == -5 ){
kirby.src ="loseKirby.png"
document.getElementById("message").innerHTML = "GAME OVER!";
}else{
}
}
//Timer Variables
var funLossTimer;
var bathLossTimer;
var foodLossTimer;
var sleepLossTimer;
var skillLossTimer;
function gameOver(){
//Game over is when food = 0; sleep = 0 bath = 0 Training is -5 Bored = 10
if (food < 0 || sleep < 0 || bath < 0 || training < - 1 || bored > 1 ){
document.getElementById("message").innerHTML = "Game OVER!";
kirby.src = "loseKirby.png"
document.getElementById("b1").classList.add('disabled');
document.getElementById("b2").classList.add('disabled');
document.getElementById("b3").classList.add('disabled');
document.getElementById("b4").classList.add('disabled');
document.getElementById("b5").classList.add('disabled');
clearInterval(funLossTimer);
clearInterval(bathLossTimer);
clearInterval(foodLossTimer);
clearInterval(skillLossTimer);
clearInterval(sleepLossTimer);
}
}
setInterval(gameOver, 100);
function restart(){
//Begin by displaying variables on page
//Reset Variables
food = 5;
bath = 5;
sleep = 5;
bored = 0;
training = 0;
document.getElementById("displayFood").innerHTML = "Food = " + food ;
document.getElementById("displayBath").innerHTML = "Bath = " + bath ;
document.getElementById("displaySleep").innerHTML = "Sleep = " + sleep;
document.getElementById("displayBored").innerHTML = "Boredome = " + bored;
document.getElementById("displayTraining").innerHTML = "Training = " + training ;
//Rewrite messae and picture
document.getElementById("message").innerHTML = "Hello!";
kirby.src = "helloKirby.png"
//Enable Buttons
document.getElementById("b1").classList.remove('disabled');
document.getElementById("b2").classList.remove('disabled');
document.getElementById("b3").classList.remove('disabled');
document.getElementById("b4").classList.remove('disabled');
document.getElementById("b5").classList.remove('disabled');
//Start the Timeer
funLossTimer = setInterval(funLoss, 5000)
//Bathe: Every 20 seconds trigger bathLoss();
bathLossTimer = setInterval(bathLoss, 20000)
//Hunger: Every 7 seconds trigger foodLoss();
foodLossTimer = setInterval(foodLoss, 7000)
//Nap: Every 10 seconds trigger sleepLoss();
sleepLossTimer = setInterval(sleepLoss, 30000)
//Train: Every 2 seconds trigger skillLoss();
skillLossTimer = setInterval(skillLoss, 3000)
}
//Set a timer rules win a loop before GameOver
//for (var i = 0; i< 1000000; i++){
// timer();
//}
//Extension: Set a cap for eating in a certain period of time