-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatchthegamepage.js
More file actions
124 lines (122 loc) · 4.59 KB
/
catchthegamepage.js
File metadata and controls
124 lines (122 loc) · 4.59 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
let progressBar = document.getElementById("progressBar");
let allcards = [];
for (let i = 1; i <= 100; i++) {
allcards.push(document.getElementById(String(i)));
}
let ready = true;
let waitingfor;
let highscore;
let currentButton;
let countdown;
let score = 0;
let speed = 60000;
if (window.localStorage.getItem("highscore") === null){
window.localStorage.setItem("highscore", 0);
highscore = window.localStorage.getItem("highscore");
}
else {
highscore = window.localStorage.getItem("highscore");
}
function chooseBackgroundTheme(lightstyle, darkstyle){
if (window.localStorage.getItem("theme") === "lightstyle.css"){
return lightstyle;
}
else if (window.localStorage.getItem("theme") === "darkstyle.css"){
return darkstyle;
}
}
waitingfor = setTimeout(() => {
window.alert("Bro what are you waiting for?");
}, speed);
function gamerun(){
function nextCard(){
let nextButton = allcards[Math.floor(Math.random() * allcards.length)];
nextButton.style.backgroundColor = chooseBackgroundTheme("rgb(26, 26, 24)", "bisque");
nextButton.disabled = false;
progressBar.style.width = "0%";
countdown = setTimeout(() => {
window.alert("STOP! Your score is " + score);
nextButton.disabled = true;
document.getElementById("highscore").textContent = "Your high score is " + highscore;
if (score > highscore){
document.body.style.transition = "0.25s";
document.body.style.backgroundColor = chooseBackgroundTheme("#99db8c", "#96cc76");
for (let card of allcards){
card.style.transition = "0.25s";
card.style.backgroundColor = chooseBackgroundTheme("#99db8c", "#96cc76");
}
document.getElementById("highscore").textContent = "New High Score!"
window.localStorage.setItem("highscore", score);
}
}, speed);
nextButton.onclick = function(){
score++;
document.getElementById("score").textContent = score;
nextButton.style.backgroundColor = chooseBackgroundTheme("bisque", "rgb(26, 26, 24)");
nextButton.disabled = true;
// Reset the progressBar animation
progressBar.style.width = "100%";
progressBar.style.transition = "0s";
void progressBar.offsetParent; // Trigger reflow
if (score >= 5 && score < 10){
progressBar.style.transition = "width 5s linear";
speed = 5000;
clearTimeout(countdown);
}
else if (score >= 10 && score < 20){
progressBar.style.transition = "width 3.5s linear";
speed = 3500;
clearTimeout(countdown);
}
else if (score >= 20 && score < 30){
progressBar.style.transition = "width 2.5s linear";
speed = 2500;
clearTimeout(countdown);
}
else if (score >= 30 && score < 40){
progressBar.style.transition = "width 2s linear";
speed = 2000;
clearTimeout(countdown);
}
else if (score >= 40 && score < 50){
progressBar.style.transition = "width 1.5s linear";
speed = 1500;
clearTimeout(countdown);
}
else if (score >= 50 && score < 60){
progressBar.style.transition = "width 1s linear";
speed = 1000;
clearTimeout(countdown);
}
else if (score >= 60 && score < 70){
progressBar.style.transition = "width 0.7s linear";
speed = 700;
clearTimeout(countdown);
}
else if (score >= 70){
progressBar.style.transition = "width 0.5s linear";
speed = 500;
clearTimeout(countdown);
}
else {
progressBar.style.transition = "width 10s linear";
speed = 10000;
clearTimeout(countdown);
}
currentButton = nextCard();
};
return nextButton;
}
currentButton = nextCard();
}
document.addEventListener("keydown", (event) => {
if (event.key === "Enter"){
if (ready){
ready = false;
speed = 10000;
document.getElementById("highscore").textContent = "";
clearTimeout(waitingfor);
gamerun();
}
}
});