-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
386 lines (347 loc) · 11.3 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rock, Paper, Scissors Game</title>
<script src="https://use.fontawesome.com/b169762f77.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@900&display=swap" rel="stylesheet">
<style>
body {
background-color: #0065a0;
}
footer {
background-color: #044164;
text-align: center;
width: 100%;
height: 30px;
position: fixed;
bottom: 0px;
padding: 5px;
margin: 0px;
color: white;
}
.container {
width: 80%;
background-color: #689f39;
margin: auto;
height: 100%;
display: flex;
flex-direction: column;
position: relative;
}
.playcontainer {
position: relative;
display: flex;
flex-direction: row;
justify-content: center;
flex-wrap: wrap;
border: 1px whitesmoke solid;
}
.scorecontainer {
display: flex;
flex-direction: row;
justify-content: center;
flex-wrap: wrap;
align-self: flex-start;
width: 100%;
/* border: 1px whitesmoke solid; */
}
.rulescontainer {
display: flex;
flex-direction: row;
justify-content: center;
flex-wrap: wrap;
}
.button {
border: 1px #0065a0 solid;
width: 170px;
height: 70px;
border-radius: 5px;
background-color: #f0ae00;
text-align: center;
padding: 5px 10px;
margin: 10px;
font-family: 'Orbitron', sans-serif;
;
font-size: 30px;
color: #0065a0;
box-shadow: 5px 5px #888888;
display: flex;
align-items: center;
justify-content: center;
}
.button:hover {
background-color: #a9e00f;
}
.game-title {
margin: auto;
font-family: 'Orbitron', sans-serif;
font-size: 30px;
text-align: center;
color: #f0ae00;
}
.rules {
border: 1px whitesmoke dashed;
margin: 3px;
color: brown;
width: 90%;
font-weight: bolder;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
}
.scorecard {
width: 50px;
height: 50px;
border: 1px solid white;
background-color: #0065a0;
color: antiquewhite;
margin: 10px;
padding: 5px;
}
#comp {
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
font-size: 20px;
background-color: black;
}
ol {
list-style-type: decimal-leading-zero;
}
.modal {
display: none;
/* Hidden by default */
position: fixed;
/* Stay in place */
z-index: 1;
/* Sit on top */
left: 0;
top: 0;
width: 100%;
/* Full width */
height: 100%;
/* Full height */
overflow: auto;
/* Enable scroll if needed */
}
.message {
display: flex;
flex-direction: row;
justify-content: center;
align-content: center;
flex-wrap: wrap;
background-color: #0065a0;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
#yes,
#no,
#ok {
width: 120px;
height: 60px;
;
}
#ok {
visibility: hidden;
}
#msg {
color: #f0ae00;
font-size: 20px;
margin: 5px;
}
#msg-check {
color: #f0ae00;
font-size: 15px;
}
a,a:visited{
color: wheat;
}
</style>
</head>
<body>
<div class="game-title">Game On!</div>
<div class="game-title"> let's Play...Rock, Paper, Scissors</div>
<hr />
<div class="container">
<div class="scorecontainer">
<div class="scorecard" name="totalgames">
<div class="scorecardheader">Total</div>
<div class="scorecardtext" id="total">0</div>
</div>
<div class="scorecard" name="wins">
<div class="scorecardheader">Wins</div>
<div class="scorecardtext" id="wins">0</div>
</div>
<div class="scorecard" name="lost">
<div class="scorecardheader">Lose</div>
<div class="scorecardtext" id="lost">0</div>
</div>
<div class="scorecard" name="ties">
<div class="scorecardheader">Ties</div>
<div class="scorecardtext" id="tie">0</div>
</div>
</div>
<div class="playcontainer">
<button id="rock" class="button" onclick="play('rock')">
<i class="fa fa-hand-rock-o" aria-hidden="true">Rock</i>
</button>
<button id="paper" class="button" onclick="play('paper')">
<i class="fa fa-hand-paper-o" aria-hidden="true">Paper</i>
</button>
<button id="scissors" class="button" onclick="play('scissors')">
<i class="fa fa-hand-scissors-o" aria-hidden="true">Scissors</i>
<button id="comp" class="button" disabled>
Computer<i class="fa fa-spinner fa-spin fa-cog fa-fw"></i>
</button>
<div class="modal" id="mymodal">
<div class="message">
<div id="msg">You Win!</div>
<div id="msg-check">Play Again?</div>
<button id="yes" class="button" onclick="askPlayAgain('yes')">Yes</button>
<button id="no" class="button" onclick="askPlayAgain('no')">No</button>
<button id="ok" class="button" onclick="stopPlaying()">Ok</button>
<span style="color:red; font-size: 10px;">*</span>
<span id="values" style="color:rgb(255, 196, 0); font-size: 10px;"></span>
</div>
</div>
</div>
<div class="rulescontainer">
<div class="rules">
How to Play:
<ol>
<li>Select one of among the objects - Rock, Paper, Scissors.</li>
<li>Computer will randomly select an object too.</li>
<li>Depending on what object you select and what object computer selects, the win or lose or tie is decided as
per the rules.</li>
<li>See the score board as you play.Enjoy!</li>
</ol>
</div>
<div class="rules">
Rules: You are playing against computer.
<ol>
<li>Rock, beats scissors, loses to paper.</li>
<li>Paper, beats rock, loses to scissors.</li>
<li>Scissors, beats paper, loses to rock.</li>
<li>Anytime you and computer selects same object. It's a tie.</li>
</ol>
</div>
</div>
</div>
<div style="height: 40px;"></div>
<footer>
©Abhijeet Bhagat | <a href="https://github.com/bhagatabhijeet/RockPaperScissorsGame"><i class="fa fa-github" aria-hidden="true"></i></a>
</footer>
<script>
var playCount = 0;
var winCount = 0;
var lostCount = 0;
var tieCount = 0;
var playAgain = true;
var computerValueArray = ['rock', 'paper', 'scissors'];
var randomSelection;
function play(val) {
playCount++;
playerSelection = val;
//Generate a random number between 0-2;
document.getElementById("total").innerText = playCount;
randomSelection = Math.floor(Math.random() * 3);
var computerSelection = computerValueArray[randomSelection];
// alert("player selection=" + playerSelection + " computer: " + randomSelection + computerSelection);
if (playerSelection === computerSelection) {
setTieCount(computerSelection,playerSelection);
return;
}
switch (playerSelection) {
case 'rock':
if (computerSelection === 'scissors') {
setWinCount(computerSelection,playerSelection);
return;
}
else {
setLostCount(computerSelection,playerSelection);
return;
}
case 'scissors':
if (computerSelection === 'paper') {
setWinCount(computerSelection,playerSelection);
return;
}
else {
setLostCount(computerSelection,playerSelection);
return;
}
case 'paper':
if (computerSelection === 'rock') {
setWinCount(computerSelection,playerSelection);
return;
}
else {
setLostCount(computerSelection,playerSelection);
return;
}
}
}
//set winCount and update UI
function setWinCount(coumputerVal,playerVal) {
++winCount;
document.getElementById("values").innerText = "[Player : " + playerVal + ", Computer : " + coumputerVal + "]";
document.getElementById("wins").innerText = winCount;
coumputerVal="<span style='color:white;'>" + coumputerVal + "</span>";
document.getElementById("msg").innerHTML = "Computer Selected " + coumputerVal + " so,You Win!";
document.getElementsByClassName("modal")[0].style.display = "block";
}
//set lostCount and update UI
function setLostCount(coumputerVal,playerVal) {
++lostCount;
document.getElementById("values").innerText = "[Player : " + playerVal + ", Computer : " + coumputerVal+ "]";
document.getElementById("lost").innerText = lostCount;
coumputerVal="<span style='color:white;'>" + coumputerVal + "</span>";
document.getElementById("msg").innerHTML = "Computer Selected " + coumputerVal + " so,You Lose :(";
document.getElementsByClassName("modal")[0].style.display = "block";
}
//set tieCount and update UI
function setTieCount(coumputerVal,playerVal) {
++tieCount;
document.getElementById("values").innerText = "[Player : " + playerVal + ", Computer : " + coumputerVal+ "]";
document.getElementById("tie").innerText = tieCount;
coumputerVal="<span style='color:white;'>" + coumputerVal + "</span>";
document.getElementById("msg").innerHTML = "Computer Selected " + coumputerVal + " so,It's a Tie";
document.getElementsByClassName("modal")[0].style.display = "block";
}
//reset all counts and update UI
function resetCounts() {
playCount = winCount = lostCount = tieCount = 0;
document.getElementById("total").innerText = 0;
document.getElementById("wins").innerText = 0;
document.getElementById("lost").innerText = 0;
document.getElementById("tie").innerText = 0;
}
function askPlayAgain(val) {
if (val === 'yes') {
document.getElementsByClassName("modal")[0].style.display = "none";
}
else {
document.getElementById("ok").style.visibility = "visible";
document.getElementById("yes").style.display = "none";
document.getElementById("no").style.display = "none";
document.getElementById("msg-check").style.display = "none";
document.getElementById("msg").innerText = "Thanks for Playing! Your Scores will now reset.";
}
}
function stopPlaying() {
document.getElementsByClassName("modal")[0].style.display = "none";
document.getElementById("yes").style.display = "block";
document.getElementById("no").style.display = "block";
document.getElementById("msg").style.display = "block";
document.getElementById("msg-check").style.display = "block";
document.getElementById("ok").style.visibility = "hidden";
resetCounts();
}
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
</html>