-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
648 lines (621 loc) · 25.3 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
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
// *-*-*-*-*-*-*-*-*-*-*-*
// **** TREASURE HUNT ****
// *-*-*-*-*-*-*-*-*-*-*-*
// store values for the Rounds, treasuresFound and treasureMap indices
let round = 0;
// let search = treasureMap[0]
let currentRound = round + 1
let num = 0
let token = 0
// use below for testing
// let treasureMap = [
// 1,
// "Treasure 6",
// 7,
// 6,
// "Treasure 5",
// 9,
// 10,
// "Treasure 3",
// 12,
// 11,
// 3,
// "Treasure 1",
// 13,
// "Treasure 4",
// 8,
// 2,
// "Treasure 7",
// 4,
// 5,
// "Treasure 2",
// ];
// -- begin creation of sorted treasure map --
let treasureMap = []
const loadMap = () => {
// create array to hold numbers from 1-20 and the 7 treasure locations will replace 7 of the numbers
// create array of treasures 'T'; default is 7 (can be expanded later)
// add number to each "T" to test indexOf for testing
// -----
const treasures = []
for (i = 1; i <= 7; i++) {
treasures.push('Treasure ' + i);
}
// -----
// array of numbers 1 through 20
// treasure locations will need to subtract from the amount of treasures "hidden" within the game
// -----
const treasureLocations = []
for (i = 1; i <= 20 - treasures.length; i++) {
treasureLocations.push(i)
}
// -----
// join arrays treasureLocations and treasures into new array, treasure map with concat method
// -----
treasureMap = treasureLocations.concat(treasures)
// -----
// --- shuffle treasures within treasureMap
const shuffle = (totalTreasures) => {
// randomly sort the treasures within the array
totalTreasures.sort(() => Math.random() - 0.5)
return;
}
// shuffles treasureMap
// -----
shuffle(treasureMap)
// ----
};
// --- end of sorted treasure map section ---
// -- set up players - class --
// human player will input name later
let humanName // to use inputted 'humanName' throughout the entire game, simply declare the variable
// using random number for humanChoice while creating the code, change later
// create 5 buttons and click will be user input for variable humanChoice
// let humanChoice = Math.floor(Math.random() * 5) + 1;
let humanChoice
let cpuChoice = Math.floor(Math.random() * 5) + 1;
class Player {
constructor(name, choice, treasuresFound) {
(this.name = name), // activate window prompt later
(this.choice = choice), // connect choice buttons to images later
(this.treasuresFound = token)
// (this.revealTreasure = this.revealTreasure.bind(this));
}
}
// determine if treasure was found by testing for a string
const revealTreasure = (index) => {
let num = index
let search = treasureMap[index]
if (currentRound <= treasureMap.length) {
if (typeof search === "string") {
if (isWinner) {
let mainGamePlay = document.createElement('p')
let mainGameBox = document.getElementById('gameplay-area2')
mainGameBox.appendChild(mainGamePlay)
mainGamePlay.classList.add('game-text2')
mainGamePlay.innerText = `X marks the spot! A treasure was found!`;
let introImg = document.getElementById('cartoonMap')
introImg.classList.add('hidden')
let treasureImg = document.createElement('img')
treasureImg.setAttribute('src', 'images/treasure-chest.png')
treasureImg.classList.add('chest')
mainGameBox.appendChild(treasureImg)
// increase winner's found treasures by 1 -- fix this
this.treasuresFound = token++
// then, increase Round by 1, currentRound by 1, and treasureMap[i] by 1 and return to showChoices()
num++
let continueButton14 = document.createElement('button')
let continueHome3 = document.getElementById('gameplay-area2')
continueButton14.innerText = "Continue"
continueButton14.classList.add('main-button')
continueButton14.classList.add('dark')
continueHome3.appendChild(continueButton14)
continueButton14.addEventListener('click', () => {
mainGamePlay.classList.add('hidden')
continueButton14.classList.add('hidden')
introImg.classList.remove('hidden')
treasureImg.classList.add('hidden')
nextRound()
})
}
} else if (typeof search === "string") {
if (!isWinner) {
let mainGamePlay = document.createElement('p')
let mainGameBox = document.getElementById('gameplay-area2')
mainGameBox.appendChild(mainGamePlay)
mainGamePlay.classList.add('game-text2')
mainGamePlay.innerText = 'A treasure was left behind!'
let introImg = document.getElementById('cartoonMap')
introImg.classList.add('hidden')
let treasureImg = document.createElement('img')
treasureImg.setAttribute('src', 'images/treasure-chest.png')
mainGameBox.appendChild(treasureImg)
treasureImg.classList.add('chest')
num++
let continueButton14 = document.createElement('button')
let continueHome3 = document.getElementById('gameplay-area2')
continueButton14.innerText = "Continue"
continueButton14.classList.add('main-button')
continueButton14.classList.add('dark')
continueHome3.appendChild(continueButton14)
continueButton14.addEventListener('click', () => {
mainGamePlay.classList.add('hidden')
continueButton14.classList.add('hidden')
introImg.classList.remove('hidden')
treasureImg.classList.add('hidden')
nextRound()
})
}
} else {
let mainGamePlay = document.createElement('p')
let mainGameBox = document.getElementById('gameplay-area2')
mainGameBox.appendChild(mainGamePlay)
mainGamePlay.classList.add('game-text2')
mainGamePlay.innerText = `Oh no! It was just a rock!`;
let introImg = document.getElementById('cartoonMap')
introImg.classList.add('hidden')
let rockImg = document.createElement('img')
rockImg.setAttribute('src', 'images/rock01.png')
rockImg.style.width = '20%'
rockImg.classList.add('rock')
mainGameBox.appendChild(rockImg)
num++
let continueButton14 = document.createElement('button')
let continueHome3 = document.getElementById('gameplay-area2')
continueButton14.innerText = "Continue"
continueButton14.classList.add('main-button')
continueButton14.classList.add('dark')
continueHome3.appendChild(continueButton14)
continueButton14.addEventListener('click', () => {
rockImg.classList.add('hidden')
mainGamePlay.classList.add('hidden')
continueButton14.classList.add('hidden')
introImg.classList.remove('hidden')
nextRound()
})
}
}
}
const finalReveal = (index) => {
let num = index
let search = treasureMap[index]
if (currentRound === treasureMap.length) {
if (typeof search === "string") {
if (isWinner) {
let mainGamePlay = document.createElement('p')
let mainGameBox = document.getElementById('gameplay-area2')
mainGameBox.appendChild(mainGamePlay)
mainGamePlay.classList.add('game-text2')
mainGamePlay.innerText = `X marks the spot! A treasure was found!`;
let treasureImg = document.createElement('img')
treasureImg.setAttribute('src', 'images/treasure-chest.png')
treasureImg.classList.add('chest')
mainGameBox.appendChild(treasureImg)
// increase winner's found treasures by 1 -- fix this
this.treasuresFound = token++
// then, increase Round by 1, currentRound by 1, and treasureMap[i] by 1 and return to showChoices()
let continueButton15 = document.createElement('button')
let continueHome4 = document.getElementById('gameplay-area2')
continueButton15.innerText = "Continue"
continueButton15.classList.add('main-button')
continueButton15.classList.add('dark')
continueHome4.appendChild(continueButton15)
continueButton15.addEventListener('click', () => {
window.location = '#gameplay-area3';
mainGamePlay.classList.add('hidden')
continueButton15.classList.add('hidden')
treasureImg.classList.add('hidden')
endGame()
})
}
} else if (typeof search === "string") {
if (!isWinner) {
let mainGamePlay = document.createElement('p')
let mainGameBox = document.getElementById('gameplay-area2')
mainGameBox.appendChild(mainGamePlay)
mainGamePlay.classList.add('game-text2')
mainGamePlay.innerText = 'A treasure was left behind!'
let introImg = document.getElementById('cartoonMap')
introImg.classList.add('hidden')
let treasureImg = document.createElement('img')
treasureImg.setAttribute('src', 'images/treasure-chest.png')
treasureImg.classList.add('chest')
mainGameBox.appendChild(treasureImg)
let continueButton15 = document.createElement('button')
let continueHome4 = document.getElementById('gameplay-area2')
continueButton15.innerText = "Keep Digging!"
continueButton15.classList.add('main-button')
continueButton15.classList.add('dark')
continueHome4.appendChild(continueButton14)
continueButton15.addEventListener('click', () => {
window.location = '#gameplay-area3';
mainGamePlay.classList.add('hidden')
continueButton15.classList.add('hidden')
introImg.classList.remove('hidden')
treasureImg.classList.add('hidden')
endGame()
})
}
} else {
let mainGamePlay = document.createElement('p')
let mainGameBox = document.getElementById('gameplay-area2')
mainGameBox.appendChild(mainGamePlay)
mainGamePlay.classList.add('game-text2')
mainGamePlay.innerText = `Oh no! ${this.name} found a rock!`;
let introImg = document.getElementById('cartoonMap')
introImg.classList.add('hidden')
let rockImg = document.createElement('img')
rockImg.setAttribute('src', 'images/rock01.png')
rockImg.style.width = '20%'
rockImg.classList.add('rock')
mainGameBox.appendChild(rockImg)
let continueButton15 = document.createElement('button')
let continueHome4 = document.getElementById('gameplay-area2')
continueButton15.innerText = "Continue"
continueButton15.classList.add('main-button')
continueButton15.classList.add('dark')
continueHome4.appendChild(continueButton15)
continueButton15.addEventListener('click', () => {
window.location = '#gameplay-area3';
rockImg.classList.add('hidden')
mainGamePlay.classList.add('hidden')
continueButton15.classList.add('hidden')
introImg.classList.remove('hidden')
endGame()
})
}
}
}
const humanPlayer = new Player(humanName, humanChoice, token);
const cpuPlayer = new Player("CPU", cpuChoice, token);
// prompt user for input from 1 - 5
const userChoicePrompt = () => {
let userChoice = prompt('Choose a number between 1 and 5', '1, 2, 3, 4, or 5')
if (userChoice != null) {
humanChoice = userChoice
showChoices()
} else {
userChoicePrompt()
}
}
// randomly determine which player chooses first
const firstChoice = () => {
let mainGamePlay = document.createElement('p')
let mainGameBox = document.getElementById('gameplay-area2')
mainGameBox.appendChild(mainGamePlay)
mainGamePlay.classList.add('game-text2')
mainGamePlay.innerText = `Let's see who chooses first... \n Click "Randomize"`
let randomPlayer = document.createElement('button')
mainGameBox.appendChild(randomPlayer)
randomPlayer.classList.add('main-button')
randomPlayer.innerText = "Randomize"
randomPlayer.addEventListener('click', () => {
let human = Math.floor(Math.random() * 2) + 1;
let cpu = Math.floor(Math.random() * 2) + 1;
if (human === cpu) {
randomPlayer.classList.add('hidden')
mainGamePlay.innerText = `${humanName} chooses first!`
let continueButton10 = document.createElement('button')
let continueHome2 = document.getElementById('gameplay-area2')
continueButton10.innerText = "Continue"
continueButton10.classList.add('main-button')
continueButton10.classList.add('dark')
continueHome2.appendChild(continueButton10)
continueButton10.addEventListener('click', () => {
mainGamePlay.classList.add('hidden')
continueButton10.classList.add('hidden')
userChoicePrompt()
})
} else {
let introImg = document.getElementById('cartoonMap')
mainGameBox.appendChild(introImg)
randomPlayer.classList.add('hidden')
introImg.classList.add('hidden')
let pirateImg = document.createElement('img')
pirateImg.setAttribute('src', 'images/pirate-player.png')
pirateImg.style.width = '20%'
pirateImg.classList.add('pirate')
mainGameBox.appendChild(pirateImg)
mainGamePlay.innerText = `${cpuPlayer.name} chooses first!`;
let continueButton11 = document.createElement('button')
let continueHome3 = document.getElementById('gameplay-area2')
continueButton11.innerText = "Continue"
continueButton11.classList.add('main-button')
continueButton11.classList.add('dark')
continueHome3.appendChild(continueButton11)
continueButton11.addEventListener('click', () => {
mainGamePlay.classList.add('hidden')
pirateImg.classList.add('hidden')
continueButton11.classList.add('hidden')
introImg.classList.remove('hidden')
userChoicePrompt()
})
}
})
}
// to win space, code will check if contents of the array index is a string (true or false) and will output the winner based on comparison of user's chosen number vs cpu's randomized number between 1 and maybe 6
const showChoices = () => {
humanPlayer.name = humanName
if (humanChoice > cpuChoice) {
let mainGamePlay2 = document.createElement('p')
let mainGameBox2 = document.getElementById('gameplay-area2')
mainGamePlay2.classList.add('game-text2')
mainGameBox2.appendChild(mainGamePlay2)
mainGamePlay2.innerText = `${humanPlayer.name} chooses ${humanChoice}.\n${cpuPlayer.name} chose ${cpuPlayer.choice}.`
let continueButton12 = document.createElement('button')
let continueHome4 = document.getElementById('gameplay-area2')
continueButton12.innerText = "Continue"
continueButton12.classList.add('main-button')
continueButton12.classList.add('dark')
continueHome4.appendChild(continueButton12)
continueButton12.addEventListener('click', () => {
mainGamePlay2.classList.add('hidden')
continueButton12.classList.add('hidden')
pickSpot()
})
} else {
let mainGamePlay2 = document.createElement('p')
let mainGameBox2 = document.getElementById('gameplay-area2')
mainGamePlay2.classList.add('game-text2')
mainGameBox2.appendChild(mainGamePlay2)
mainGamePlay2.innerText = `${humanPlayer.name} chooses ${humanChoice}.\n${cpuPlayer.name} chose ${cpuPlayer.choice}.`
let continueButton13 = document.createElement('button')
let continueHome5 = document.getElementById('gameplay-area2')
continueButton13.innerText = "Continue"
continueButton13.classList.add('main-button')
continueButton13.classList.add('dark')
continueHome5.appendChild(continueButton13)
continueButton13.addEventListener('click', () => {
mainGamePlay2.classList.add('hidden')
continueButton13.classList.add('hidden')
pickSpot()
})
}
}
const pickSpot = () => {
if (currentRound <= 19) {
if (isTie() === true) {
console.log('we made it to line 348')
let mainGamePlay = document.createElement('p')
let mainGameBox2 = document.getElementById('gameplay-area2')
mainGameBox2.appendChild(mainGamePlay)
mainGamePlay.classList.add('game-text2')
mainGamePlay.innerText = `It's a tie! Let's see if there was a treasure...`;
let continueButton3 = document.createElement('button')
continueButton3.innerText = "Next"
continueButton3.classList.add('main-button')
continueButton3.classList.add('dark')
mainGameBox2.appendChild(continueButton3)
continueButton3.addEventListener('click', () => {
mainGamePlay.classList.add('hidden')
continueButton3.classList.add('hidden')
// cpuPlayer.revealTreasure(round)
revealTreasure(round)
})
} else if (isWinner() === true) {
let mainGameBox2 = document.getElementById('gameplay-area2')
let mainGamePlay = document.createElement('p')
mainGameBox2.appendChild(mainGamePlay)
mainGamePlay.classList.add('game-text2')
mainGamePlay.innerText = `${humanPlayer.name} digs for a treasure!\nLet's see what you found...`
let continueButton4 = document.createElement('button')
continueButton4.innerText = "Continue"
continueButton4.classList.add('main-button')
continueButton4.classList.add('dark')
mainGameBox2.appendChild(continueButton4)
continueButton4.addEventListener('click', () => {
mainGamePlay.classList.add('hidden')
continueButton4.classList.add('hidden')
// humanPlayer.revealTreasure(round)
revealTreasure(round)
})
} else {
let mainGamePlay = document.createElement('p')
let mainGameBox2 = document.getElementById('gameplay-area2')
mainGamePlay.classList.add('game-text2')
mainGameBox2.appendChild(mainGamePlay)
mainGamePlay.innerText = `${cpuPlayer.name} digs for a treasure!\nLet's see if there was a treasure...`;
// then reveal if space is treasure and do not log to any player's
let continueButton5 = document.createElement('button')
continueButton5.innerText = "Continue"
continueButton5.classList.add('main-button')
continueButton5.classList.add('dark')
mainGameBox2.appendChild(continueButton5)
continueButton5.addEventListener('click', () => {
mainGamePlay.classList.add('hidden')
continueButton5.classList.add('hidden')
// cpuPlayer.revealTreasure(round)
revealTreasure(round)
})
}
}
}
const isTie = () => {
if (humanChoice === cpuChoice) {
return true;
} else {
return false;
}
};
const isWinner = () => {
if (humanChoice > cpuChoice) {
return true;
} else {
return false;
}
};
const nextRound = () => {
round++
currentRound++
let announceRound = document.getElementById('game-round')
announceRound.innerText = `Round ${currentRound}`
if (currentRound === 20) {
if (isTie() === true) {
let mainGamePlay = document.createElement('p')
let mainGameBox2 = document.getElementById('gameplay-area2')
mainGamePlay.classList.add('game-text2')
mainGameBox2.appendChild(mainGamePlay)
mainGamePlay.innerText = `It's a tie! Let's see if there was a treasure...`
let continueButton5 = document.createElement('button')
continueButton5.innerText = "Continue"
continueButton5.classList.add('main-button')
continueButton5.classList.add('dark')
mainGameBox2.appendChild(continueButton5)
continueButton5.addEventListener('click', () => {
continueButton5.classList.add('hidden')
finalReveal(round)
})
} else if (isWinner() === true) {
let mainGamePlay = document.createElement('p')
let mainGameBox2 = document.getElementById('gameplay-area2')
mainGamePlay.classList.add('game-text2')
mainGameBox2.appendChild(mainGamePlay)
mainGamePlay.innerText = `${humanPlayer.name} digs for a treasure!\nLet's see what you found...`
// then reveal if space is treasure and log to winner's score
let continueButton5 = document.createElement('button')
continueButton5.innerText = "Continue"
continueButton5.classList.add('main-button')
continueButton5.classList.add('dark')
mainGameBox2.appendChild(continueButton5)
continueButton5.addEventListener('click', () => {
continueButton5.classList.add('hidden')
finalReveal(round)
})
} else {
let mainGamePlay = document.createElement('p')
let mainGameBox2 = document.getElementById('gameplay-area2')
mainGamePlay.classList.add('game-text2')
mainGameBox2.appendChild(mainGamePlay)
mainGamePlay.innerText = `${cpuPlayer.name} digs for a treasure!\nLet's see if there was a treasure...`
// then reveal if space is treasure and do not log to any player's
let continueButton5 = document.createElement('button')
continueButton5.innerText = "Continue"
continueButton5.classList.add('main-button')
continueButton5.classList.add('dark')
mainGameBox2.appendChild(continueButton5)
continueButton5.addEventListener('click', () => {
continueButton5.classList.add('hidden')
finalReveal(round)
})
}
} else {
let mainGamePlay = document.createElement('p')
let mainGameBox2 = document.getElementById('gameplay-area2')
mainGamePlay.classList.add('game-text2')
mainGameBox2.appendChild(mainGamePlay)
mainGamePlay.innerText = 'Get ready to choose a space...'
let continueButton5 = document.createElement('button')
continueButton5.innerText = "Continue"
continueButton5.classList.add('main-button')
continueButton5.classList.add('dark')
mainGameBox2.appendChild(continueButton5)
continueButton5.addEventListener('click', () => {
continueButton5.classList.add('hidden')
mainGamePlay.classList.add('hidden')
userChoicePrompt()
})
}
}
// ------------------------
// **** START GAME ****
// ------------------------
const startGame = () => {
let announceRound = document.getElementById('game-round')
announceRound.innerText = `Round ${currentRound}`
loadMap()
firstChoice()
}
// =================
// *** END GAME ***
// =================
// Game will end and reveal the total of how many treasures found and determine winner of entire game
const endGame = () => {
let gameEnd = document.createElement('p')
let mainGameBox3 = document.getElementById('gameplay-area3')
gameEnd.classList.add('game-text')
gameEnd.style.color = "red"
mainGameBox3.appendChild(gameEnd)
gameEnd.innerText = `It's been a great treasure hunt!\nLet's see who won...`
let continueButton20 = document.createElement('button')
continueButton20.innerText = "Continue"
continueButton20.classList.add('main-button')
continueButton20.classList.add('dark')
mainGameBox3.appendChild(continueButton20)
continueButton20.addEventListener('click', () => {
continueButton20.classList.add('hidden')
let quitGameButton = document.getElementById('quit-game')
quitGameButton.classList.add('hidden')
let treasureImg = document.createElement('img')
treasureImg.setAttribute('src', 'images/treasure-chest.png')
treasureImg.classList.add('chest')
mainGameBox3.appendChild(treasureImg)
let finalQuitGameButton = document.getElementById('final-quit-game')
finalQuitGameButton.classList.remove('hidden')
if (humanPlayer.treasuresFound > cpuPlayer.treasuresFound) {
let gameEnd = document.createElement('p')
let mainGameBox3 = document.getElementById('gameplay-area3')
gameEnd.classList.add('game-text2')
mainGameBox3.appendChild(gameEnd)
gameEnd.innerText = `${humanPlayer.name} collected ${humanPlayer.treasuresFound} treasures.\n${cpuPlayer.name} collected ${cpuPlayer.treasuresFound} treasures.\n${humanPlayer.name} wins!`
finalQuitGameButton.addEventListener('click', () => {
window.location = '#'
})
} else if (humanPlayer.treasuresFound === cpuPlayer.treasuresFound) {
let gameEnd = document.createElement('p')
let mainGameBox3 = document.getElementById('gameplay-area3')
gameEnd.classList.add('game-text2')
mainGameBox3.appendChild(gameEnd)
gameEnd.innerText = `${cpuPlayer.name} collected ${cpuPlayer.treasuresFound} treasures.\n${humanPlayer.name} collected ${humanPlayer.treasuresFound} treasures.\nIt's a tie! Please play again.`
finalQuitGameButton.addEventListener('click', () => {
window.location = '#'
})
} else {
let gameEnd = document.createElement('p')
let mainGameBox3 = document.getElementById('gameplay-area3')
gameEnd.classList.add('game-text2')
mainGameBox3.appendChild(gameEnd)
gameEnd.innerText = `${humanPlayer.name} collected ${humanPlayer.treasuresFound} treasures.\n${cpuPlayer.name} collected ${cpuPlayer.treasuresFound} treasures.\n${cpuPlayer.name} wins!\nBetter luck next time.`
finalQuitGameButton.addEventListener('click', () => {
window.location = '#'
})
}
})
}
const getPlayerName = () => {
let humanNameButton = document.getElementById('submit-name')
humanNameButton.addEventListener('click', () => {
humanName = document.getElementById('name-input').value
if (humanName) {
let welcomeName = document.getElementById('entered-name')
welcomeName.innerText = `Welcome to the Treasure Hunt, ${humanName}!`
let removeBoxes = document.querySelectorAll('.enter-name')
for (const box of removeBoxes) {
box.classList.add('hidden');
}
let continueButton = document.createElement('button')
let continueHome = document.getElementById('gameplay-area')
continueButton.innerText = "Continue"
continueButton.classList.add('main-button')
continueButton.classList.add('dark')
continueHome.appendChild(continueButton)
continueButton.addEventListener('click', () => {
window.location = '#gameplay-area2';
let beginGameButton = document.getElementById('game-play')
beginGameButton.classList.add('main-button')
beginGameButton.addEventListener('click', () => {
beginGameButton.classList.add('hidden')
startGame()
})
})
} else {
humanName = "Player 1"
}
})
}
// gameplay buttons
let startButton = document.getElementById('next-enter-name');
startButton.addEventListener('click', () => {
// startGame()
window.location = '#gameplay-area';
getPlayerName()
});