-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslapscript.js
379 lines (275 loc) · 11.1 KB
/
slapscript.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
let player1Health= 100;
let player2Health = 100;
let player1Wins = false;
let player2wins = false;
let p1gonnaslap = false;
var player1;
var player2;
$( document ).ready(function() // function runs when the page is ready
{ // On load, the script hides two DIV elements 'hidebox' and 'healthmonitor'
console.log( "Page loaded fully!" );
console.log( "Hiding hidebox DIV" );
$("#hidebox").hide(); //jQuery hide() Method Source : w3schools Link: https://www.w3schools.com/jquery/eff_hide.asp
console.log( "Hiding healthmonitor DIV" );
$("#healthmonitor").hide();
$("#bibleverse").hide();
console.log( "Activating event listener for Click to start game" );
$("#startbutton").bind('click',showinputbox); //a
});
function showinputbox()
{
console.log( "shows hide box" );
$("#hidebox").show(); //jQuery show() method, source: w3schools Link: https://www.w3schools.com/jquery/eff_show.asp
$("#tossbox").hide();
document.getElementById("commentatorsays").innerHTML = "Mention two names that you love to hate.";
console.log("Showing input fields, Primary Enter button hidden");
$("#entergame").hide();
$("#playerdetailsbox").show();
}
function myMessage() {
$("#hidebox").show();
//disable
$(".button").prop('disabled', true);
}
function welcome (){
debugger;
/* Welcome message") */
$("#playerdetailsbox").hide();
$("#tossbox").show();
defineplayer1details($("#player1name").val(),$("#player1nick").val());
defineplayer2details($("#player2name").val(),$("#player2nick").val()); //Jquery val method. Sourced from https://www.w3schools.com/jquery/html_val.asp
console.log("COMMENTATOR: Welcome to the ULTIMATE SLAP-THE-FACE-OFF FACE OFF!")
document.getElementById("commentatorsays").innerHTML = "Welcome! Welcome! Welcome! Todays face off is between " + player1.name + " And " + player2.name;
console.log('COMMENTATOR: Todays face off is between player 1 & player 2')
}
function defineplayer1details(name,nick){
player1 ={
"name": name,
"nick" : nick
};
}
function defineplayer2details(name,nick){
player2 ={
"name": name,
"nick" : nick
};
}
function toss (){
debugger;
let tosscondition=Math.random()<0.5;
// TossWaitingMessage("And we toss!", 1500);
// TossWaitingMessage("Is it heads?", 1000);
// TossWaitingMessage("or maybe tails?", 1000);
// TossWaitingMessage("Aaaand here we have it!", 1000);
//if (tosscondition=true)
if (tosscondition == true)
{
p1gonnaslap=true;
console.log("COMMENTATOR: player 1 wins the toss.")
document.getElementById("commentatorsays").innerHTML = "And " + player1.name + " wins the toss";
}
else
{
p1gonnaslap=false;
console.log("COMMENTATOR: Player 2 wins the toss.")
document.getElementById("commentatorsays").innerHTML = "And " + player2.name + " wins the toss";
}
$("#healthmonitor").show();
/* code to change button text and fuction */
var button = document.getElementById("tossbuton");
button.textContent = "Start Match"; //changes the button's text (source : w3schools : https://www.w3schools.com/cssref/tryit.php?filename=trycss_js_background-color)
button.onclick = whistle; //changes the assigned function on click of the button to whistle();
document.getElementById("player1healthname").innerHTML = player1.name;
document.getElementById("player2healthname").innerHTML = player2.name;
}
function nameupdatebycommentator(player) // this function changes the name so that the user knows who is going to be slapped next.
{
document.getElementById("consolesays").innerHTML = "(click below to slap " + player.name + ")";
}
function whistle()
{
debugger;
console.log('*Referee Whistles*')
console.log('COMMENTATOR: FIGHT!')
if(p1gonnaslap===true)
{
if(!player1Wins && !player2wins)
{
nameupdatebycommentator(player2);
}
}
else
{
if(!player1Wins && !player2wins)
{
nameupdatebycommentator(player1);
}
// document.getElementById("commentatorsays").innerHTML = "(click below to slap " + player1.name + ")";
}
var button = document.getElementById("tossbuton");
button.textContent = "SLAP!"; //changes the button's text (source : w3schools : https://www.w3schools.com/cssref/tryit.php?filename=trycss_js_background-color)
button.onclick = slapattack; //changes the assigned function on click of the button to whistle();
//https://tuna.voicemod.net/sound/1c811306-b62e-457c-be68-0e295d12d510
}
function updatehealthbar1()
{
debugger;
console.log("update healthbar 1 function ");
let life1=player1Health;
let lifebar1=document.getElementById("p1bar");
lifebar1.value=life1;
if(player2wins)
{
document.getElementById('player1health').style.backgroundColor = "black";
}
}
function updatehealthbar2()
{
debugger;
console.log("update healthbar 2 function ");
let life2=player2Health;
let lifebar2=document.getElementById("p2bar");
lifebar2.value=life2;
if(player1Wins)
{
document.getElementById('player2health').style.backgroundColor = "black";
}
}
function slapattack()
{
if(p1gonnaslap==true)
{
if (!player1Wins && !player2wins)
{
player1slaps();
if(player2Health>0)
{
nameupdatebycommentator(player1);
}
p1gonnaslap=false;
}
}
else
{
if (!player1Wins && !player2wins)
{
player2slaps();
if(player1Health>0)
{
nameupdatebycommentator(player2);
}
p1gonnaslap=true;
}
}
console.log("player1 health:" + player1Health);
console.log("player2 health:" + player2Health);
}
function player1slaps() {
debugger;
var damage=100*Math.random();
player2Health=player2Health-damage;
if (player2Health<=0)
{
player2Health=0;
player1Wins=true;
document.getElementById("commentatorsays").innerHTML = "OUT COLD! OUT COLD! " + player2.name + " is KNOCKED OUT!";
console.log('COMMENTATOR: Player 1 knocks out player 2');
updatehealthbar2();
knockoutReport();
}
else
{
updatehealthbar2();
if (damage>60)
{
document.getElementById("commentatorsays").innerHTML = "OMG THAT WAS A CRITICAL HIT! And it shows on " + player2.name + "'s face.";
console.log('COMMENTATOR : Player 1 slaps player 2 with a critical hit OMG!!')
console.log('player 2: *blinks rapidly*')
}
else {
document.getElementById("commentatorsays").innerHTML = "What a slap on " + player2.name + "'s face!!";
console.log('COMMENTATOR: Player 1 slaps Jezos ')
console.log('player 2: *smirks* ')
console.log('player 2: That felt micro and soft. Is that the best you got?')
}
}
console.log("exiting player1slaps, function completed");
}
function player2slaps() {
debugger;
var damage=100*Math.random();
player1Health=player1Health-damage;
if (player1Health<=0)
{
player1Health=0;
player2wins=true;
document.getElementById("commentatorsays").innerHTML = "OUT COLD! OUT COLD! " + player1.name + " is KNOCKED OUT!";
console.log('COMMENTATOR: player 2 knocks out player 1');
updatehealthbar1();
knockoutReport();
}
else
{
updatehealthbar1();
if (damage>60) {
//annie are you okay? - alert
document.getElementById("commentatorsays").innerHTML = "OMG THAT WAS A CRITICAL HIT! And it shows on " + player1.name + "'s face.";
console.log('COMMENTATOR : Player2 slaps sheet out Mr. Dates with a critical hit OMG!!')
console.log('DATES: *blinks rapidly*')
}
else {
document.getElementById("commentatorsays").innerHTML = "What a slap on " + player1.name + "'s face!!";
console.log('COMMENTATOR: Player 2 slaps Mr. Dates ')
console.log('player 1: *smirks*')
console.log("player 1: Poor delivery. Ama'zone you out now.")
}
}
//return health;
console.log("exiting player2slaps, function completed");
}
function knockoutReport() {
debugger;
console.log("starting knockout report")
if (player2wins) {
console.log('COMMENTATOR: Can you believe it? player 1 has been knocked out!')
document.getElementById("commentatorsays").innerHTML = "Can you believe it? " + player1.name + " has been knocked out!";
}
if (player1Wins) {
console.log('COMMENTATOR: Can you believe it? Player 2 has been knocked out!')
document.getElementById("commentatorsays").innerHTML = "Can you believe it? " + player2.name + " has been knocked out!";
}
$("#consolesays").hide();
console.log("changing button & proceeding to winner declaration")
var button = document.getElementById("tossbuton");
button.textContent = "Proceed";
button.onclick = winnderDeclaration;
}
function winnderDeclaration()
{
debugger;
$("#consolesays").show();
if(player1Wins==true)
{
console.log('COMMENTATOR: Ladies & Gentlemen, here is your winner : Player 1!')
document.getElementById("commentatorsays").innerHTML = "Ladies & Gentlemen, here is your winner : " + player1.name + " (" + player2.nick +")";
}
/* if (player2wins==true) */
else
{
console.log('COMMENTATOR: Ladies & Gentlemen, here is your winner : Player 2!!')
document.getElementById("commentatorsays").innerHTML = "Ladies & Gentlemen, here is your winner : " + player2.name + " (" + player2.nick +")";
}
console.log("changing button & proceeding to try again")
document.getElementById("consolesays").innerHTML = "Still Angry??";
var button = document.getElementById("tossbuton");
button.textContent = "Play Again";
button.onclick = playagain;
console.log("*************shows input box");
debugger;
$("#bibleverse").show();
}
function playagain()
{
location.reload();
}
//document.getElementById("startbutton").addEventListener("click" , startSlapFaceOff);