-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
425 lines (392 loc) · 14.8 KB
/
app.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
//Declaration of initial variables
let gameActive;
let dailyCount;
let notifyIsOpen;
let revDiv = document.querySelector('.reviewDiv');
let scoreUpdate = document.querySelector('.notify-text');
let gameTimer;
let time;
function startUp(){
daysFailed = 0;
noteBoxOn();
gameActive = false
buttonsToggle();
scoreUpdate.style.margin = `1em`;
scoreUpdate.innerHTML = 'Ok, kid. Thanks for accepting the job as a bouncer for my club. I\'ll let you know who to let in each day. Check that list and make sure the IDs aren\'t fake (check the watermark).<br><br> Good luck<br>\- Boss';
revDiv.innerHTML = ``;
nextBtn.innerHTML=`I'll do my best`;
nextBtn.removeEventListener('click', startUp);
nextBtn.removeEventListener('click',startDay);
nextBtn.addEventListener('click', noteBoxOff);
nextBtn.addEventListener('click',reset)
function reset(){
nextBtn.removeEventListener('click',noteBoxOff);
nextBtn.removeEventListener('click', reset)
nextBtn.addEventListener('click', startDay)
};
let id = document.querySelector('.id-photo').src = `./resources/titleID.gif`;
}
//
window.onload = startUp;
class CatID {
constructor(picNum, name, age, fur, eyeColor, isLegit, isCat = true){
this.getPic(picNum);
this.catNamer(name);
this.age = age
this.fur = fur;
this.eyeColor = eyeColor;
this.isLegit;
this.realOrFake(isLegit);
this.isCat = isCat;
this.name;
this.updateID();
}
getPic(picNum){
let idPhoto = document.querySelector('.id-photo');
if (picNum === 'ran'){
picNum = Math.floor(Math.random()*6)
}
let picArr = [
`./resources/id0.jpg`,
`./resources/id1.jpg`,
`./resources/id2.jpg`,
`./resources/id3.jpg`,
`./resources/id4.jpg`,
`./resources/id5.jpg`,
`./resources/id6.jpg`,
]
idPhoto.src = picArr[picNum];
}
catNamer(name){
let nameList = ['Elmer', 'Cornelius','Sprout','Bok Choy', 'Luna', 'Milo', 'Oliver', 'Leo', 'Loki', 'Bella', 'Charlie', 'Willow', 'Lucy', 'Simba', 'Beans'];
this.nameList = nameList;
if (name.toLowerCase() === 'random'){
let ran = Math.floor(Math.random()*nameList.length)
this.name = nameList[ran]}
else {this.name = name}
;
}
updateID(){
let idName = document.querySelector('.id-name');
idName.innerHTML = this.name;
let idAge = document.querySelector('.idAge');
idAge.innerHTML = this.age;
let idFur = document.querySelector('.idFur');
idFur.innerHTML = this.fur;
let idEyeColor = document.querySelector('.idEyeColor');
idEyeColor.innerHTML = this.eyeColor;
}
realOrFake(isLegit){
if (!isLegit){
if (Math.floor(Math.random()*100)<50){
document.getElementById('watermark').style.opacity = 0;
this.isLegit = false;
}
else {document.getElementById('watermark').style.opacity = 0.1;
this.isLegit = true;}
}
else{document.getElementById('watermark').style.opacity = 0.1;
this.isLegit = true;}
}
}
let cats =
[
function cat0(){
return cat = new CatID(0, 'random', (Math.floor(Math.random()*14)+1), 'Grey', 'Green', true)},
function cat1(){
return cat = new CatID(1, 'random', (Math.floor(Math.random()*14)+1), 'Orange', 'Green', true)},
function cat2(){
return cat = new CatID(2, 'random', (Math.floor(Math.random()*14)+1), 'Orange', 'Green', true)},
function cat3(){
return cat = new CatID(3, 'random', (Math.floor(Math.random()*14)+1), 'Grey', 'Green')},
function cat4(){
return cat = new CatID(4, 'random', (Math.floor(Math.random()*14)+1), 'Black', 'Green')},
function cat5(){
return cat = new CatID(5, 'random', (Math.floor(Math.random()*14)+1), 'Brown', 'Green')},
function cat6(){
return cat = new CatID(6, 'random', (Math.floor(Math.random()*14)+1), 'White', 'Blue', true)},
];
let allow = document.querySelector('.allow');
let deny = document.querySelector('.deny');
let start = document.querySelector('.start');
let dailyCorrect;
let daysWorked;
let kidName;
start.addEventListener('click', startGame)
function startGame(e){
//startGame is different from startDay in that it is only invoked once to hard reset some values and toggle button functionality.
daysWorked = 0;
startDay();
start.style.opacity = 0;
start.removeEventListener('click', startGame);
start.addEventListener('click', startDay);
buttonsToggle();
}
function startDay(){
//start of day re-initializes values for new 'day' loop
gameActive = true;
buttonsToggle();
noteBoxOff();
dailyCount = 0;
dailyCorrect = 0;
//Days Worked is initialized to zero and only begins updating when a value >0 is present
if(daysWorked >= 0){
let daysWorkedText = document.querySelector('.days-worked');
daysWorkedText.innerHTML = `Days Worked: ${daysWorked}`
}
//New cat generated from constructor class at start of day IF gameActive is true. Commented out 'else' for testing
if (gameActive === true){
todaysCat = cats[Math.floor(Math.random()*cats.length)]();
}
//criteriaGen is fed the daysWorked to generate criteria for club entry semi-dynamically
criteriaGen(daysWorked);
//setTimer is invoked here with reference to days worked inorder to generate a (decrementing) value for the timer
time = setTimer();
clearInterval(gameTimer);
gameTimer = setInterval(function(){
if(time <= 0){
setTimeout(endOfDayCheck(),1000);
}
else{
time--;
document.querySelector('.timer').innerHTML = `Time until shift ends: ${time}`;
}},1000);
}
let todaysAge;
let fakeCount;
let ranLet;
function setTimer(){
if (daysWorked<3){return 40}
else if (daysWorked<5){return 30}
else if (daysWorked<7){return 20}
else if (daysWorked<9){return 15}
else if (daysWorked<11){return 10}
else if (daysWorked<13){return 8}
else{return 5};
}
function criteriaGen(daysWorked){
let textHolder;
Math.floor(Math.random());
if ((daysWorked+2)%5 === 0){todaysAge = Math.floor(Math.random()*4+10);
textHolder = `Senior night! No one under the age of ${todaysAge}.`;}
else if ((daysWorked+2)%9 === 0){
todaysAge = Math.floor(Math.random()*4+2);
shortNameList = ['Elmer', 'Cornelius','Sprout'];
kidName =shortNameList[Math.floor(Math.random()*shortNameList.length)];
textHolder = `Same old thing today. No one under ${todaysAge} unless it's my sibling's kid, ${kidName}. I'm watching ${kidName} after school. Might be more than one?`;
}
else{
todaysAge = Math.floor(Math.random()*4+4);
textHolder = `Keep the kids out. No one under the age of ${todaysAge}.`;
let letArr = ['s','c','l'];
ranLet = letArr[Math.floor(Math.random()*3)];
if(daysWorked>1)
{textHolder += ` Oh and no one with a name that starts with '${ranLet.toUpperCase()}'.`}
}
if(!todaysCat.isLegit){fakeCount += 1}
document.querySelector('.criteria-text').innerHTML=textHolder;
}
function buttonsToggle(){
if (gameActive === true){
allow.addEventListener('click', idCheck);
deny.addEventListener('click', idCheck);
}
else if (gameActive === false){
allow.removeEventListener('click', idCheck);
deny.removeEventListener('click', idCheck);
}
}
function idCheck(e){
response = document.querySelector('.response');
let whichBtn =e.target.classList.toString();
let currentCheck;
// when you push a button, one of a few text strings is returned as 'dialog'
if(whichBtn.includes('allow')){
currentCheck = whichBtn.includes('allow')
responsePos= ["Come on in, pal!", "Right this way, friend","Hurry on inside, chum"];
response.innerHTML = responsePos[Math.floor(Math.random()*responsePos.length)];
}
if(whichBtn.includes('deny')){
responseNeg= ["No way!", "Scram, ya chump!","Who do you think you're fooling?", "Not today, friend."];
response.innerHTML = responseNeg[Math.floor(Math.random()*responseNeg.length)];
}
function criteriaCheck(){
// the criteria are stored as a reference to the modulo of the number of days worked.
// on each allow/deny button press, a true or false value is pushed into the criteriaArr
// the value at index zero is TRUE if you allow the cat and FALSE if you deny them (more on this later)
// otherwise, TRUE is pushed if the cat meets the criteria, FALSE is pushed if not.
if ((daysWorked+2)%5 === 0){
criteriaArr = [];
criteriaArr.push(whichBtn.includes('allow'));
criteriaArr.push(todaysCat.age>todaysAge);
criteriaArr.push(todaysCat.isLegit);
}
else if ((daysWorked+2)%9 === 0){
criteriaArr = [];
if (todaysCat.name === kidName){
criteriaArr.push(whichBtn.includes('allow'));
criteriaArr.push(todaysCat.name === kidName);
}
else{
criteriaArr.push(whichBtn.includes('allow'));
criteriaArr.push(todaysCat.age>todaysAge);
criteriaArr.push(todaysCat.isLegit)
}
}
else{
criteriaArr = [];
criteriaArr.push(whichBtn.includes('allow'));
criteriaArr.push(todaysCat.age >= todaysAge);
criteriaArr.push(todaysCat.isLegit);
if (daysWorked>1){
criteriaArr.push(todaysCat.name[0].toLowerCase() !== ranLet);
}
}
// Because criteriaArr[0] is TRUE if you allow the cat and FALSE if you do not, checking if the cat should have been allowed in is simple.
// A cat that is permitted into the club should have a criteriaArr where every value is true
if(criteriaArr[0] === true && !criteriaArr.includes(false, 1)){dailyCorrect += 1}
// If a cat should have been denied entry, the index 0 should be false and at least one other value should be false
else if(criteriaArr[0] === false && criteriaArr.includes(false, 1)){dailyCorrect += 1}
}
criteriaCheck();
dailyCount += 1;
gameActive = false;
buttonsToggle();
setTimeout(function(){
response.innerHTML="";
if(daysFailed<2){
gameActive = true;
todaysCat = cats[Math.floor(Math.random()*cats.length)]();
buttonsToggle();
}
}, 1500);
if (dailyCount === 5){setTimeout(endOfDayCheck(),1000)}
}
let daysFailed = 0;
function endOfDayCheck(){
// At the end of each day, timers and buttons are toggled and the noteBox appears to feed score info and feedback.
gameActive = false;
buttonsToggle();
setTimeout(function(){
response.innerHTML="";
buttonsToggle();
}, 1500);
daysWorked += 1;
time = 0;
clearInterval(gameTimer);
noteBoxOn();
scoreUpdate.innerHTML = `You got ${dailyCorrect} out of 5`
let score;
score = dailyCorrect/5
// If the player score falls below 80%, then daysFailed +=1. Once it reaches 2, the gameOver function is invoked
nextBtn.innerHTML=`Next Day`;
if (score<=0.6){
daysFailed += 1;
if (daysFailed < 2){
revDiv.innerHTML= `Disappointing Performance. Another day like that and you're fired!`;
}
else if (daysFailed >= 2){gameOver()}
}
else if(score>.6){
let goodJobText = [
`I knew I could count on you! Great work!`,
`Thank you for keeping this place running smooth!`,
`Fantastic work today`,
`I couldn't do it without you. Great job!`,
`You're just the best :)`,
`I don't know how I did this without an employee like you!`,
];
revDiv.innerHTML = goodJobText[Math.floor(Math.random()*goodJobText.length)]
}
function gameOver(){
let gameOverText = [
`Are you even paying attention? You're fired!`,
`I'm not mad, just disappointed. You're fired.`,
`Can you read? YOU'RE FIRED!`,
`Your work is repugnant. You're fired.`,
];
gameActive = false;
revDiv.innerHTML= gameOverText[Math.floor(Math.random()*gameOverText.length)];
nextBtn.innerHTML = 'Go Find A New Job';
nextBtn.removeEventListener('click',startDay);
nextBtn.addEventListener('click',startUp);
start.style.opacity = 1;
start.addEventListener('click', startGame);
buttonsToggle();
response.innerHTML = '';
}
}
let nextBtn = document.querySelector('.next')
nextBtn.addEventListener('click',startDay)
function noteBoxOff(){
let noteBox = document.querySelector('.notify-box');
noteBox.style.zIndex = 1;
noteBox.style.opacity = 0;
notifyIsOpen = false;
}
function noteBoxOn(){
let noteBox = document.querySelector('.notify-box');
noteBox.style.zIndex = 4;
noteBox.style.opacity = 1;
notifyIsOpen = true;
}
let id = document.querySelector('.catID-wrapper')
//Unnecessary Konami Code
let arr = [];
window.addEventListener('keydown', e => {
if(arr.length === 0 && e.keyCode === 38){
arr.push(1);
return;
}
if(arr.length === 1 && e.keyCode === 38){
arr.push(1);
return;
}
if(arr.length === 2 && e.keyCode === 40){
arr.push(1);
return;
}
if(arr.length === 3 && e.keyCode === 40){
arr.push(1);
return;
}
if(arr.length === 4 && e.keyCode === 37){
arr.push(1);
return;
}
if(arr.length === 5 && e.keyCode === 39){
arr.push(1);
return;
}
if(arr.length === 6 && e.keyCode === 37){
arr.push(1);
return;
}
if(arr.length === 7 && e.keyCode === 39){
arr.push(1);
return;
}
if(arr.length === 8 && e.keyCode === 66){
arr.push(1);
return;
}
if(arr.length === 9 && e.keyCode === 65){
arr.push(1);
return;
}
if(arr.length === 10 && e.keyCode === 66){
arr.push(1);
return;
}
if(arr.length === 11 && e.keyCode === 65){
arr.push(1);
return;
}
if(arr.length === 12 && e.keyCode === 13){
arr.push(1);
document.body.style.backgroundImage = 'url(./resources/cat-explosion.gif)';
document.body.style.backgroundSize = '25%';
return;
}
else{arr = [];}
})