-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
733 lines (685 loc) · 19.1 KB
/
Copy pathscript.js
File metadata and controls
733 lines (685 loc) · 19.1 KB
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
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
let questions = [
{
question: "Who stole the apple.",
answers: ["A. George", "B. Jamal", "C. William", "D. Jimmy"],
correctAnswer: "Jamal",
cashAmount: 10000,
},
{
question: "What's 9 + 10.",
answers: ["A. 19", "B. 21", "C. 11", "D. 1"],
correctAnswer: "21",
cashAmount: 10000,
},
{
question: "What is the capital of Ethiopia?",
answers: ["A. Nairobi", "B. Cairo", "C. Addis Ababa", "D. Johannesburg"],
correctAnswer: "Addis Ababa",
cashAmount: 100,
},
{
question: "Which planet is known as the Red Planet?",
answers: ["A. Mars", "B. Venus", "C. Jupiter", "D. Saturn"],
correctAnswer: "Mars",
cashAmount: 100,
},
{
question: "Who painted the Mona Lisa?",
answers: [
"A. Leonardo da Vinci",
"B. Michelangelo",
"C. Raphael",
"D. Rembrandt",
],
correctAnswer: "Leonardo da Vinci",
cashAmount: 100,
},
{
question: "What is the largest ocean in the world?",
answers: [
"A. Atlantic Ocean",
"B. Pacific Ocean",
"C. Indian Ocean",
"D. Arctic Ocean",
],
correctAnswer: "Pacific Ocean",
cashAmount: 100,
},
{
question: "Who wrote the famous play Romeo and Juliet?",
answers: [
"A. William Shakespeare",
"B. Jane Austen",
"C. Charles Dickens",
"D. Mark Twain",
],
correctAnswer: "William Shakespeare",
cashAmount: 100,
},
{
question: "What is the chemical symbol for gold?",
answers: ["A. Ag", "B. Au", "C. Fe", "D. Cu"],
correctAnswer: "Au",
cashAmount: 100,
},
{
question: "Who was the first person to walk on the moon?",
answers: [
"A. Buzz Aldrin",
"B. Neil Armstrong",
"C. John Glenn",
"D. Yuri Gagarin",
],
correctAnswer: "Neil Armstrong",
cashAmount: 100,
},
{
question: "What is the largest country in the world by land area?",
answers: ["A. China", "B. Russia", "C. Canada", "D. United States"],
correctAnswer: "Russia",
cashAmount: 100,
},
{
question: "What is the capital of Australia?",
answers: ["A. Sydney", "B. Melbourne", "C. Canberra", "D. Brisbane"],
correctAnswer: "Canberra",
cashAmount: 1000,
},
{
question: "Who painted the Starry Night?",
answers: [
"A. Vincent van Gogh",
"B. Pablo Picasso",
"C. Claude Monet",
"D. Leonardo da Vinci",
],
correctAnswer: "Vincent van Gogh",
cashAmount: 1000,
},
{
question: "Which classic novel features the character Sherlock Holmes?",
answers: [
"A. Pride and Prejudice",
"B. The Lord of the Rings",
"C. TAHF",
"D. THB",
],
correctAnswer: "The Hound of Baskervilles",
cashAmount: 10000,
},
{
question: 'What is the name of the main character in the novel "1984"?',
answers: [
"A. Winston Smith",
"B. John Snow",
"C. Jane Eyre",
"D. Holden Caulfield",
],
correctAnswer: "Winston Smith",
cashAmount: 10000,
},
{
question: "What is the largest organ in the human body?",
answers: ["A. Heart", "B. Liver", "C. Skin", "D. Brain"],
correctAnswer: "Skin",
cashAmount: 100,
},
{
question: "What is the longest river in the world?",
answers: ["A. Nile", "B. Amazon", "C. Mississippi", "D. Yangtze"],
correctAnswer: "Nile",
cashAmount: 100,
},
{
question: "Which sport is played on a court with a net?",
answers: ["A. Soccer", "B. Basketball", "C. Baseball", "D. Tennis"],
correctAnswer: "Tennis",
cashAmount: 10000,
},
{
question:
"What is the name of the popular board game that involves buying and selling properties?",
answers: ["A. Monopoly", "B. Scrabble", "C. Clue", "D. Risk"],
correctAnswer: "Monopoly",
cashAmount: 100,
},
{
question:
"Markos kaladege min yibalal?",
answers: ["A. Ayadgim", "B. kebede", "C. Biadeglign", "D. Bayadglign"],
correctAnswer: "Biadeglign",
cashAmount: 100,
},
];
questions = shuffleArray(questions);
// #region
let doubleOrNothhingQuestions = [
{
question: "What is the name of the largest known prime number?",
answers: [
"A. Mersenne Prime",
"B. Fermat Prime",
"C. Twin Prime",
"D. M8257582",
],
correctAnswer: "M8257582",
},
{
question: "What is the largest known perfect number?",
answers: [
"A. 2^82589933 - 1",
"B. 2^77232917 - 1",
"C. 2^43112609 - 1",
"D. 2^1257787 - 1",
],
correctAnswer: "2^82589933 - 1",
},
{
question:
"What is the smallest integer that can be expressed as the sum of three cubes in two different ways?",
answers: ["A. 1729", "B. 4104", "C. 1065", "D. 2318"],
correctAnswer: "729",
},
{
question: "Who was the first woman to win the Nobel Prize in Physics?",
answers: [
"A. Marie Curie",
"B. Rosalind Franklin",
"C. Ada Lovelace",
"D. Sally Ride",
],
correctAnswer: "Marie Curie",
},
{
question: "Which U.S. president was assassinated on November 22, 1963?",
answers: [
"A. John F. Kennedy",
"B. Abraham Lincoln",
"C. Franklin D. Roosevelt",
"D. Lyndon B. Johnson",
],
correctAnswer: "John F. Kennedy",
},
{
question: "In what year did the Berlin Wall fall?",
answers: ["A. 1989", "B. 1991", "C. 1993", "D. 1995"],
correctAnswer: "1989",
},
{
question: 'Who wrote the novel "To Kill a Mockingbird"?',
answers: [
"A. Harper Lee",
"B. Ernest Hemingway",
"C. J.K. Rowling",
"D. Mark Twain",
],
correctAnswer: "Harper Lee",
},
];
const tooManyWrongQuestionsJokes = [
{
joke: "I’ve seen people struggle before, but you’re really giving it a new definition. Should we start a new category called ‘Creative Guessing’?",
loc: "assets/audio/tooManyIncorrect01.mp3",
},
{
joke: "I have to say, your guessing skills are truly… unique. You’re redefining what it means to take a chance!",
loc: "assets/audio/tooManyIncorrect02.mp3",
},
{
joke: "I’ve seen people get answers wrong before, but you’re turning it into an art form. I might need to start taking notes!",
loc: "assets/audio/tooManyIncorrect03.mp3",
},
{
joke: "I see you’ve discovered the ‘how not to win a game show’ strategy. You’re really setting a new standard here.",
loc: "assets/audio/tooManyIncorrect04.mp3",
},
];
const tooManyCorrectQuestionsJokes = [
{
joke: "You’re making me look bad with all these correct answers. I’m going to need a new job if you keep this up!",
loc: "assets/audio/tooManyCorrect01.mp3",
},
{
joke: "You’re acing every question. Do you have a PhD in trivia or are you just showing off?",
loc: "assets/audio/tooManyCorrect02.mp3",
},
{
joke: "Are you sure you’re not getting help from a team of trivia nerds? Because you’re making this look way too easy!",
loc: "assets/audio/tooManyCorrect03.mp3",
},
];
const littleTimeLeftJokes = [
{
joke: "We’re down to the wire—like a cat on a high shelf, it’s getting exciting up here!",
loc: "assets/audio/timerRunout01.mp3",
},
{
joke: "We're almost out of time—better hurry, or you might just be writing a novel on that answer!",
loc: "assets/audio/timerRunout02.mp3",
},
{
joke: "The clock’s ticking down! Hurry up before your answer turns into a dinosaur fossil!",
loc: "assets/audio/timerRunout03.mp3",
},
{
joke: "Time’s almost up! And if you don’t get this right, well, let’s just say the replay will be entertaining!",
loc: "assets/audio/timerRunout04.mp3",
},
{
joke: "We’re almost out of time, and if you don’t hurry, we might need to call in a rescue team!",
loc: "assets/audio/timerRunout05.mp3",
},
];
const winningJokes = [
{
joke: "Congratulations! You’ve won the game and officially earned bragging rights for the next century!",
loc: "assets/audio/winJoke01.mp3",
},
{
joke: "You did it! You’ve won a lot of money and possibly made everyone else question their life choices!",
loc: "assets/audio/winJoke02.mp3",
},
{
joke: "You have earned the million dollars and more importantly, made everyone watching feel stupid",
loc: "assets/audio/winJoke03.mp3",
},
{
joke: "You did it! And with that I have to run out of here because I don't have the cash",
loc: "assets/audio/winJoke04.mp3",
},
];
const losingJokes = [
{
joke: "Looks like you didn’t win—don’t worry, you’re still the best at losing with style!",
loc: "assets/audio/loseJoke02.mp3",
},
{
joke: "You didn’t win, but don’t worry, you’ve still achieved the ‘almost’ status with flying colors!",
loc: "assets/audio/loseJoke01.mp3",
},
{
joke: "You might have lost a million but you will also get broken dreams to go.",
loc: "assets/audio/loseJoke04.mp3",
},
{
joke: "You didn't win but atleast we all know now that you aren't special.",
loc: "assets/audio/loseJoke03.mp3",
},
];
//#end region
// doubleOrNothhingQuestions = shuffleArray(doubleOrNothhingQuestions);
var currentIndex = 0,
userAnswers = 0,
currentCash = 100;
const question = document.createElement("div");
question.classList += "question-container";
const clock = $(".clock");
let clk;
var seconds = 30;
const message = $(".message");
const game = document.querySelector(".game");
const chatSection = $(".chat-view");
const money = $(".money");
game.appendChild(question);
//getting all audio sources each are different source
const audioSource = document.getElementById("audSource");
const sfxSource = document.getElementById("sfxSource");
const musicSource = document.getElementById("musicSource");
//streaks
let winStreak = false,
loseStreak = false;
//total ai questions
let aiQuestions = 3;
//tracking timerJoke
let timerJokeBool = false,
legacyAudio = $("#audioToggle").is(":checked"),
legacyArt = $("#artToggle").is(":checked");
//called when the webpage loads
window.onload = () => {
$(".moneyDisp").slideUp();
$(".start-menu").animate({ bottom: "50px" }, 1500, "swing");
$(".lifeline, .clock").hide();
playMessage({
joke: "Welcome to IZZY Trivia. Press Play to start.",
loc: "assets/audio/opening.mp3",
});
toggleArt();
};
//adding pixel before the file extension for the legacy audio
function addPixelToFilePath(filePath) {
const extensionIndex = filePath.lastIndexOf(".mp3");
if (extensionIndex !== -1) {
return (
filePath.substring(0, extensionIndex) +
"pixel" +
filePath.substring(extensionIndex)
);
}
return filePath;
}
//play joke and messages
function playMessage(msg) {
$(".messageBox").show();
setTimeout(() => {
$(".messageBox").fadeOut();
}, 3000);
message.text(msg.joke);
audioSource.pause();
if (legacyAudio) audioSource.src = msg.loc;
else audioSource.src = addPixelToFilePath(msg.loc);
audioSource.playbackRate = 1.5;
audioSource.volume = 0.5;
audioSource.play();
}
//play sound effects
function playSfx(loc) {
sfxSource.pause();
sfxSource.src = loc;
sfxSource.volume = 0.4;
// audioSource.playbackRate = 1.5;
sfxSource.play();
}
function playMusic(loc) {
musicSource.pause();
musicSource.src = loc;
musicSource.volume = 0.1;
musicSource.play();
}
//exit button event listener for ai chat
$(".exit").click(function (e) {
e.preventDefault();
$(".chat-pop").hide();
});
//event listener for start menu play button
$(".play").click(function (e) {
e.preventDefault();
playSfx("assets/audio/answer select.mp3");
//using a callback function to wait for the animation to finish
$(".start-menu").slideUp("fast", "swing", () => {
$(this).parent().hide();
clk = setInterval(clockCount, 1000);
addQuestion();
$(".lifeline, .clock").show();
$(".moneyDisp").slideDown();
});
playMessage({ joke: "Okay let' start with the first question.", loc:"assets/audio/lettuce.mp3" });
// $(this).hide();
});
//lifeline event listener
$(".lifeline button").click(function (e) {
e.preventDefault();
playSfx("assets/audio/life line select.mp3");
$(this).css("background-image", 'url("assets/lifeDisable.png")');
$(this).prop("disabled", true);
if ($(this).hasClass("aiBtn")) {
$(".chat-pop").show(200);
}
if ($(this).hasClass("rmv")) {
const otherButtons = document.querySelectorAll(
`.ansBtn[val]:not([val="${questions[currentIndex].correctAnswer}"])`
);
const idx1 = Math.floor(Math.random() * 3);
let idx2;
//recursivley check for a different index
do {
idx2 = Math.floor(Math.random() * 3);
} while (idx2 === idx1);
otherButtons[idx1].style.opacity = "0";
otherButtons[idx2].style.opacity = "0";
}
});
//event listiner for the legacy toggles
$("#audioToggle").on("change", () => {
if ($("#audioToggle").is(":checked")) {
legacyAudio = true;
} else {
legacyAudio = false;
}
});
$("#artToggle").on("change", () => {
toggleArt();
});
function toggleArt() {
if ($("#artToggle").is(":checked")) {
$(".gameSection").css({
"background-image": "url(assets/background.png)",
});
$(".clock").css({
'left':' 36.2%',
'top': '13.5%',
});
$(".moneyDisp").css({
'background-image': "url('assets/moneyBack.png')",
'color': 'gold',
});
$(".messageBox").css({
'left': '54%',
'top': '16%',
});
legacyArt = true;
} else {
$(".gameSection").css({
"background-image": "url(assets/background-new.png)",
});
$(".clock").css({
'left':' 20%',
'top': '10%',
});
$(".moneyDisp, .moneyDisp h3").css({
'background-image': 'none',
'color': 'white',
});
$(".messageBox").css({
'left': '45%',
'top': '20%',
});
legacyArt = false;
}
}
///checks for answer and for win/lose streaks
function checkAnswer(answer) {
if (answer === questions[currentIndex].correctAnswer) {
playSfx("assets/audio/answer correct.mp3");
++userAnswers;
editMoney(questions[currentIndex].cashAmount);
if (
!winStreak &&
userAnswers >= (currentIndex*0.6) &&
currentIndex > questions.length / 2
) {
winStreak = true;
playMessage(
tooManyCorrectQuestionsJokes[
Math.floor(Math.random() * tooManyCorrectQuestionsJokes.length)
]
);
}
} else {
playSfx("assets/audio/lose.mp3");
editMoney(-1 * (questions[currentIndex].cashAmount / 2));
if (
!loseStreak &&
userAnswers <= currentIndex / 2 &&
currentIndex > questions.length / 2
) {
loseStreak = true;
playMessage(
tooManyWrongQuestionsJokes[
Math.floor(Math.random() * tooManyWrongQuestionsJokes.length)
]
);
}
}
newQuestion();
}
//checks if the questions are done if not new question
function newQuestion() {
$(".chat-pop").hide();
if (++currentIndex == questions.length) {
// alert(
// `Congratulations you finished You answered ${userAnswers} out of ${questions.length} questions`
// );
checkWin();
} else {
addQuestion();
}
}
//checks if the player won the game or not
function checkWin() {
clearInterval(clk);
$(".moneyDisp").slideUp();
if (userAnswers > questions.length * 0.65) {
playSfx("assets/audio/win.mp3");
$(".question-container").hide();
$(".win-screen h2").addClass("win");
$(".win-screen h2").text(`You Win ${currentCash + 10000}`);
$(".win-screen p").text(
`You Answered ${userAnswers} out of ${questions.length} questions.`
);
$(".win-screen").show();
playMessage(winningJokes[Math.floor(Math.random() * winningJokes.length)]);
// message.text(
// winningJokes[Math.floor(Math.random() * winningJokes.length)].joke
// );
} else {
playSfx("assets/audio/lose legacy.mp3");
$(".question-container").hide();
$(".win-screen h2").text("You Lose");
$(".win-screen p").text(
`You Answered ${userAnswers} out of ${questions.length} questions.`
);
$(".win-screen").show();
playMessage(losingJokes[Math.floor(Math.random() * losingJokes.length)]);
}
}
//adds the question to the HTML
function addQuestion() {
let ans = "";
questions[currentIndex].answers.forEach((item) => {
ans += `<button class="ansBtn" val="${item.slice(3)}">${item}</button>`;
});
question.innerHTML = `
<div class=question>
<p>${questions[currentIndex].question}</p>
</div>
<div class=answers>
${ans}
</div>
`;
playMusic("assets/audio/QUESTION TRACK 60 SEC.mp3");
//event listener for each answer
$(".ansBtn").click(function (e) {
e.preventDefault();
checkAnswer($(this).text().slice(3));
});
seconds = 30;
timerJokeBool = false;
}
//shuffling the questios to get different one each time
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
//function to check, count the clock
function clockCount() {
//check to play the timer joke
if (
!timerJokeBool &&
seconds < Math.floor(Math.random() * (14 - 6 + 1)) + 6
) {
timerJoke();
timerJokeBool = true;
}
//timer runout
if (seconds < 1) {
playSfx("assets/audio/wrong answer.mp3");
editMoney(-100);
newQuestion();
} else if (seconds < 11) {
//adding 0 to 9 and below
clock.text(`0${--seconds}`);
} else clock.text(--seconds);
}
function timerJoke() {
playMessage(
littleTimeLeftJokes[Math.floor(Math.random() * littleTimeLeftJokes.length)]
);
}
//event listener to check for chats with the ai
$("#chat-form").on("submit", (e) => {
e.preventDefault();
if (aiQuestions-- > 0) {
chatSection.append(
`
<div class="chat-user">
<p>
${$(".chat-box").val()}
</p>
</div>
`
);
callGemniApi($(".chat-box").val());
} else {
chatSection.append(
`
<div class="chat-user">
<p>
You're out of questions!
</p>
</div>
`
);
setTimeout(2000, () => {
$(".chat-pop").hide();
});
}
});
//calling and adding the gemeni api
function callGemniApi(prompt) {
fetch(
"https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateContent",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"x-goog-api-key": `AIzaSyCaCvcbS2zKq7MvWmkVfdZbK4qiVv1Pik0`,
},
body: JSON.stringify({
contents: [
{
role: "user",
parts: [
{
text:
"I'm going to ask you a question for a game show and i want you to answer me in html format as a p tag " +
prompt,
},
],
},
],
}),
}
)
.then((response) => response.json())
.then((data) => {
chatSection.append(
`
<div class="chat-ai">
${data.candidates[0].content.parts[0].text}
</div>
`
);
})
.catch((error) => {
console.error(error);
});
}
//editing the user's money
function editMoney(amount) {
currentCash += amount;
if (currentCash < 0) currentCash = 0;
money.text(currentCash);
}