-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
245 lines (220 loc) · 9.1 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RPS Enhanced</title>
</head>
<body>
<div class="flex"></div>
<p class="roundCounter">
Round 1
</p>
<div class="scores">
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
</div>
<div class="instructions-box">
<p class="instructions">Player, it's your turn!</p>
<p2 class="sub-instructions">Choose one of the following:</p2>
</div>
<div class="choices">
<div class="choice" id="scissors">
<img src="assets/scissors.png" alt="Scissors">
Scissors
</div>
<div class="choice" id="paper">
<img src="assets/paper.png" class="paper_img" alt="Paper">
Paper
</div>
<div class="choice" id="rock">
<img src="assets/rock.png" alt="Rock">
Rock
</div>
<div class="choice" id="lizard">
<img src="assets/lizard.png" alt="Lizard">
Lizard
</div>
<div class="choice" id="spock">
<img src="assets/spock.png" alt="Spock">
Spock
</div>
</div>
<div class="flex"></div>
<div class="logos">
<div class="logo">
<img src="assets/dark.png" alt="Dark Mode">
</div>
<div class="logo">
<img src="assets/settings.png" alt="Settings">
</div>
<div class="logo">
<img src="assets/info.png" alt="Information">
</div>
</div>
<script>
function getComputerChoice() {
let choice = Math.floor(Math.random() * 5);
if (choice === 0) {
return "rock";
} else if (choice === 1) {
return "paper";
} else if (choice === 2) {
return "scissors";
} else if (choice === 3) {
return "lizard";
} else {
return "spock";
}
}
const instructionsBox = document.querySelector(".instructions-box");
const result = document.querySelector(".instructions");
const subInstructions = document.querySelector(".sub-instructions");
const choices = document.querySelectorAll(".choice");
const roundCounter = document.querySelector(".roundCounter");
const scores = document.querySelector(".scores")
let choiceEnabled = true;
let humanScore = 0, computerScore = 0
let round = 1
gameOver = false;
const logos = document.querySelectorAll(".logo");
function toggleChoiceClick(toggle) {
if (toggle == true) {
choiceEnabled = true;
} else if (toggle == false) {
choiceEnabled = false;
}
}
function resetRound() {
choices.forEach((choice) => {
choice.setAttribute("style", "color: var(--cardtext-light); background-color: var(--cardbg-light); border-color: var(--cardborder-light);");
});
if (round < 5) {
result.textContent = "Player, it's your turn!";
subInstructions.textContent = "Choose one of the following:";
round++;
roundCounter.textContent = `Round ${round}`;
toggleChoiceClick(true);
} else {
gameOver = true;
if (humanScore > computerScore) {
roundCounter.textContent = "You Win!"
result.textContent = `Congratulations! You beat the opponent ${humanScore}-${computerScore}.`
subInstructions.textContent = "Wanna have another go? You know what to do!";
} else if (humanScore < computerScore) {
roundCounter.textContent = "You Lose!"
result.textContent = `Oopsies! You lost to the opponent ${humanScore}-${computerScore}.`
subInstructions.textContent = "Wanna have another go? You know what to do!";
} else if (humanScore == computerScore) {
roundCounter.textContent = "You Tied!"
result.textContent = `What a tough match! You tied with the opponent ${humanScore}-${computerScore}.`
subInstructions.textContent = "Wanna have another go? You know what to do!";
}
}
}
instructionsBox.addEventListener("click", () => {
if (choiceEnabled === false && gameOver == false) {
resetRound();
} else if (gameOver == true) {
round = 0, computerScore = 0, humanScore = 0, choiceEnabled = true, gameOver = false;
resetRound();
for (const child of scores.children) {
child.setAttribute("style", "background-color: var(--circle-blank-light)");
}
}
});
function win(choice) {
humanScore += 1;
choice.setAttribute("style", "color: var(--cardtext-win-light); background-color: var(--cardbg-win-light); border-color: var(--cardborder-win-light);");
scores.children[round - 1].setAttribute("style", "background-color: var(--circle-win-light)");
}
function lose(choice) {
computerScore += 1;
choice.setAttribute("style", "color: var(--cardborder-lose-light); background-color: var(--cardbg-lose-light); border-color: var(--cardborder-lose-light);");
scores.children[round - 1].setAttribute("style", "background-color: var(--circle-lose-light)");
}
choices.forEach((choice) => {
choice.addEventListener("click", () => {
if (choiceEnabled === true) {
toggleChoiceClick(false);
const comChoice = getComputerChoice();
subInstructions.textContent = "Click here to continue.";
if (comChoice == choice.id) {
result.textContent = `It\'s a tie! Both sides chose ${choice.id}.`
scores.children[round - 1].setAttribute("style", "background-color: var(--circle-tie-light)");
} else if (comChoice == "spock" && choice.id == "scissors") {
lose(choice);
result.textContent = "The opponent's Spock smashes your Scissors!";
} else if (comChoice == "scissors" && choice.id == "spock") {
win(choice);
result.textContent = "Your Spock smashes the opponent's Scissors!";
} else if (comChoice == "scissors" && choice.id == "paper") {
lose(choice);
result.textContent = "The opponent's Scissors cuts your Paper!";
} else if (comChoice == "paper" && choice.id == "scissors") {
win(choice);
result.textContent = "Your Scissors cuts the opponent's Paper!";
} else if (comChoice == "paper" && choice.id == "rock") {
lose(choice);
result.textContent = "The opponent's Paper covers your Rock!";
} else if (comChoice == "rock" && choice.id == "paper") {
win(choice);
result.textContent = "Your Paper covers the opponent's Rock!";
} else if (comChoice == "rock" && choice.id == "lizard") {
lose(choice);
result.textContent = "The opponent's Rock crushes your Lizard!";
} else if (comChoice == "lizard" && choice.id == "rock") {
win(choice);
result.textContent = "Your Rock crushes the opponent's Lizard!";
} else if (comChoice == "lizard" && choice.id == "spock") {
lose(choice);
result.textContent = "The opponent's Lizard poisons your Spock!";
} else if (comChoice == "spock" && choice.id == "lizard") {
win(choice);
result.textContent = "Your Lizard poisons the opponent's Spock!";
} else if (comChoice == "spock" && choice.id == "rock") {
lose(choice);
result.textContent = "The opponent's Spock vaporizes your Rock!";
} else if (comChoice == "rock" && choice.id == "spock") {
win(choice);
result.textContent = "Your Spock vaporizes the opponent's Rock!";
} else if (comChoice == "rock" && choice.id == "scissors") {
lose(choice);
result.textContent = "The opponent's Rock crushes your Scissors!";
} else if (comChoice == "scissors" && choice.id == "rock") {
win(choice);
result.textContent = "Your Scissors crushes the opponent's Rock!";
} else if (comChoice == "scissors" && choice.id == "lizard") {
lose(choice);
result.textContent = "The opponent's Scissors decapitates your Lizard!";
} else if (comChoice == "lizard" && choice.id == "scissors") {
win(choice);
result.textContent = "Your Scissors decapitates the opponent's Lizard!";
} else if (comChoice == "lizard" && choice.id == "paper") {
lose(choice);
result.textContent = "The opponent's Lizard eats your Paper!";
} else if (comChoice == "paper" && choice.id == "lizard") {
win(choice);
result.textContent = "Your Lizard eats the opponent's Paper!";
} else if (comChoice == "paper" && choice.id == "spock") {
lose(choice);
result.textContent = "The opponent's Paper disproves your Spock!";
} else {
win(choice);
result.textContent = "Your Paper disproves the opponent's Spock!";
}
}
});
});
logos.forEach((logo) => {
logo.addEventListener("click", () => {
alert("This feature will be added in a future update!");
})
})
</script>
</body>
</html>