-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
290 lines (264 loc) · 11.2 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// MISC
const blinkSpeed1 = 0250;
const darkRed = 'rgb(70, 18, 32)';
// SOUND
const music = document.querySelector('.music');
const soundFX = document.querySelector('.sfx');
const brooksCode = document.querySelector('.brookscode');
brooksCode.addEventListener('click', brooksFunc);
function brooksFunc() {
soundStatus == false ? soundFX.src = '' : soundFX.src = 'audio/click.mp3';
soundFX.play();
}
music.src = 'audio/song.mp3';
window.addEventListener('load', playMusic);
function playMusic() {
music.play();
}
const toggleSound = document.querySelector('.toggle-sound');
let soundStatus = false;
toggleSound.addEventListener('click', () => {
soundStatus = true;
if(music.currentTime == 0) {
music.play();
toggleSound.innerHTML = 'Sound Off';
} else if(music.paused && music.currentTime > 0 && !music.ended) {
music.play();
toggleSound.innerHTML = 'Sound Off';
} else {
music.pause();
soundStatus = false;
toggleSound.innerHTML = 'Sound On';
}
})
// SCOREBOX
const scoreBox = document.querySelector('.score-box');
const scoreBoxFlash = {
time: null,
start: function() {
this.time = setInterval( () => {
scoreBox.style.backgroundColor = (scoreBox.style.backgroundColor === darkRed ? 'rgb(254, 208, 187)' : darkRed);
}, blinkSpeed1);
},
stop: function() {
clearInterval(this.time, 2000);
}
}
let playerScore = 0;
let compScore = 0;
scoreBox.innerHTML = ``;
setTimeout(welcome1, 2000);
function welcome1() {
scoreBox.innerHTML = 'Welcome to Romeo, Present, Syphillis...';
setTimeout(welcome2, 3000);
function welcome2() {
scoreBox.innerHTML = 'the very best in juvenile entertainment.';
setTimeout(welcome3, 3000);
function welcome3() {
scoreBox.innerHTML = 'Check out the instructions below. ↓↓↓'
setTimeout(welcome4, 3000);
setTimeout(welcome5, 1000);
function welcome4() {
scoreBox.innerHTML = `Player: ${playerScore} | Machine: ${compScore}`;
}
}
}
}
// INSTRUCTION BOX
const insBox = document.querySelector('.instruction-box');
const insBoxFlash = {
time: null,
start: function() {
this.time = setInterval( () => {
insBox.style.backgroundColor = (insBox.style.backgroundColor === darkRed ? 'rgb(178, 58, 72)' : darkRed);
}, blinkSpeed1);
},
stop: function() {
clearInterval(this.time);
}
}
function welcome5() {
insBoxFlash.start();
insBox.innerHTML = 'First to 5 points wins...';
setTimeout(stopFlash, 3000);
setTimeout(instruction2, 3000);
setTimeout(instruction3, 7000);
function stopFlash() {
insBoxFlash.stop();
insBox.style.backgroundcolor = darkRed;
};
function instruction2() {
insBox.innerHTML = 'Click the Romeo, Present, or Syphillis icon in the Player box and hit Select';
};
function instruction3() {
insBox.innerHTML = '- Romeo beats Present.<br>- Present beat Syphillis.<br>- Syphillis beats Romeo.';
}
}
// USER CHOICE
const userChoice = document.querySelector('.user-choice');
const romeo = document.querySelector('.ch-romeo');
const present = document.querySelector('.ch-present');
const syphillis = document.querySelector('.ch-syphillis');
const select = document.querySelector('.user-select');
const userImage = document.getElementById('userImage');
romeo.addEventListener('click', romFunc);
function romFunc() {
soundStatus == false ? soundFX.src = '' : soundFX.src = 'audio/click.mp3';
soundFX.play();
userChoice.children[1].style.display = 'block';
userChoice.children[1].style.bottom = '40px';
userChoice.children[1].innerHTML = 'Romeo';
userImage.src = 'pics/romeo.png';
}
present.addEventListener('click', preFunc);
function preFunc() {
soundStatus == false ? soundFX.src = '' : soundFX.src = 'audio/click.mp3';
soundFX.play();
userChoice.children[1].style.display = 'block';
userChoice.children[1].style.bottom = '33px';
userChoice.children[1].innerHTML = 'Present';
userImage.src = 'pics/present.png';
}
syphillis.addEventListener('click', sypFunc);
function sypFunc() {
soundStatus == false ? soundFX.src = '' : soundFX.src = 'audio/click.mp3';
soundFX.play();
userChoice.children[1].style.display = 'block';
userChoice.children[1].style.bottom = '40px';
userChoice.children[1].innerHTML = 'Syphillis';
userImage.src = 'pics/syphillis.png';
}
select.addEventListener('click', selectFunc);
function selectFunc() {
soundStatus == false ? soundFX.src = '' : soundFX.src = 'audio/click.mp3';
soundFX.play();
console.log(`User choice: ${userChoice.children[1].innerHTML}`);
if(userChoice.children[1].innerHTML.length > 0) {
setTimeout(compFunc, 0500);
}
}
// COMP CHOICE
const compChoice = document.querySelector('.comp-choice');
const compImage = document.getElementById('compImage');
function compFunc() {
const compArr = ['Romeo', 'Present', 'Syphillis'];
const compIndex = Math.floor(Math.random() * compArr.length);
compChoice.children[1].innerHTML = compArr[compIndex];
compChoice.children[1].style.display = 'block';
setTimeout(compImgFunc, 0001);
console.log(`Comp choice: ${compChoice.children[1].innerHTML}`);
setTimeout(determineFunc, 1000);
}
function compImgFunc() {
if(compChoice.children[1].innerHTML === 'Romeo') {
compImage.src = 'pics/romeo.png';
} else if(compChoice.children[1].innerHTML === 'Present') {
compImage.src = 'pics/present.png';
} else if(compChoice.children[1].innerHTML === 'Syphillis') {
compImage.src = 'pics/syphillis.png';
} else {
compImage.src = '';
}
compChoice.children[1].innerHTML === 'Present' ?
compChoice.children[1].style.bottom = '33px' :
compChoice.children[1].style.bottom = '40px'; // THE 'PRESENT' TEXT WAS BEING STUPID.
}
// DETERMINE WINNER, COMMENT & RESET
function determineFunc() {
const drawComment = ["It's a draw.", "Even Stevens, carry on.", "Draw? There's no paper here!",
"A draw won't do. Keep going.", "Nobody likes a draw. Play on."];
const winComment = ["Nice one, eat that bot!", "Exactly, it's just a machine.", "No mercy!",
"Yay. You're killing it!", "Eat that bot for breakfast!"];
const loseComment = ["Unlucky.", "Sorry, the computer says 'no'.", "Better luck next time.",
"Don't let the bot win!", "Hang in there!"];
const commentIndex = Math.floor(Math.random() * 5);
if((userChoice.children[1].innerHTML === 'Romeo' && compChoice.children[1].innerHTML === 'Romeo') ||
(userChoice.children[1].innerHTML === 'Present' && compChoice.children[1].innerHTML === 'Present') ||
(userChoice.children[1].innerHTML === 'Syphillis' && compChoice.children[1].innerHTML === 'Syphillis')) {
scoreBox.style.fontFamily = 'Arial, Helvetica, sans-serif';
scoreBox.innerHTML = drawComment[commentIndex];
setTimeout(drawReset, 2000);
} else if((userChoice.children[1].innerHTML === 'Romeo' && compChoice.children[1].innerHTML === 'Present') ||
(userChoice.children[1].innerHTML === 'Present' && compChoice.children[1].innerHTML === 'Syphillis') ||
(userChoice.children[1].innerHTML === 'Syphillis' && compChoice.children[1].innerHTML === 'Romeo')) {
soundStatus == false ? soundFX.src = '' : soundFX.src = 'audio/yay.mp3';
soundFX.play();
playerScore++;
scoreBox.style.fontFamily = 'Arial, Helvetica, sans-serif';
scoreBox.innerHTML = winComment[commentIndex];
scoreBoxFlash.start();
setTimeout(stopScoreFlash, 2000);
function stopScoreFlash() {
scoreBoxFlash.stop();
scoreBox.style.background = darkRed;
}
setTimeout(winReset, 2000);
} else {
soundStatus == false ? soundFX.src = '' : soundFX.src = 'audio/boo.mp3';
soundFX.play();
compScore++;
scoreBox.style.fontFamily = 'Arial, Helvetica, sans-serif';
scoreBox.innerHTML = loseComment[commentIndex];
setTimeout(winReset, 2000);
}
setTimeout(finalDet, 0001);
}
function drawReset() {
scoreBox.style.fontFamily = "'Courier New', Courier, monospace";
scoreBox.innerHTML = `Player: ${playerScore} | Machine: ${compScore}`;
userChoice.children[1].style.display = 'none';
compChoice.children[1].style.display = 'none';
userChoice.style.background = '#FCB9B2';
userChoice.children[1].innerHTML = '';
compChoice.children[1].innerHTML = '';
userImage.src = '';
compImage.src = '';
}
function winReset() {
scoreBox.style.fontFamily = "'Courier New', Courier, monospace";
scoreBox.innerHTML = `Player: ${playerScore} | Machine: ${compScore}`;
userChoice.children[1].style.display = 'none';
compChoice.children[1].style.display = 'none';
userChoice.style.background = '#FCB9B2';
userChoice.children[1].innerHTML = '';
compChoice.children[1].innerHTML = '';
userImage.src = '';
compImage.src = '';
}
// MASTER RESET
const masterReset = document.querySelector('.master-reset');
masterReset.addEventListener('click', masReset)
function masReset() {
soundStatus == false ? soundFX.src = '' : soundFX.src = 'audio/click.mp3';
soundFX.play();
playerScore = 0;
compScore = 0;
scoreBox.style.fontFamily = "'Courier New', Courier, monospace";
scoreBox.innerHTML = `Player: ${playerScore} | Machine: ${compScore}`;
userChoice.children[1].style.display = 'none';
compChoice.children[1].style.display = 'none';
userChoice.style.background = '#FCB9B2';
userChoice.children[1].innerHTML = '';
compChoice.children[1].innerHTML = '';
userImage.src = '';
compImage.src = '';
}
// DETERMINE ABSOLUTE WINNER, COMMENT AND RESET
function finalDet() {
const winComment = ["PLAYER WINS!", "YOU'VE WON!!!", "CONGRATULATIONS. GO HUMANITY!!!", "YOU'VE KILLED IT!!!"];
const loseComment = ["MACHINE WINS!", "OH NO. YOU'VE LOST!", "WWHHHYHYYYYYYY!!!", "BETTER LUCK NEXT TIME!"];
const detIndex = Math.floor(Math.random() * 4);
if(playerScore > 4) {
soundStatus == false ? soundFX.src = '' : soundFX.src = 'audio/cheers.mp3';
soundFX.play();
scoreBox.innerHTML = winComment[detIndex];
// scoreBox.innerHTML.includes('E') ? soundFX.play() : soundFX; // USE LATER
playerScore = 0;
compScore = 0;
} else if(compScore > 4) {
scoreBox.innerHTML = loseComment[detIndex];
// scoreBox.innerHTML.includes('E') ? soundFX.play() : soundFX; // USE LATER
playerScore = 0;
compScore = 0;
}
}