-
Notifications
You must be signed in to change notification settings - Fork 0
/
onePlayer.html
132 lines (120 loc) · 5.11 KB
/
onePlayer.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Rock, Paper, Scissors</title>
<link rel="stylesheet" type="text/css" href="./assets/css/reset.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="./assets/css/style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<div class="container singlePlayer">
<div class="row">
<h4 class="col-md-12 instructions">Once you select your option, the computer will let you know it's answer.
<div class="p1keyboard">Keyboard options:
<ul>
<li>rock: 1 or r</li>
<li>paper: 2 or p</li>
<li> scissors: 3 or s</li>
</ul>
</div>
</h4>
</div>
<div class="container">
<div class="row">
<div class="col-md-offset-2 col-md-8">
<div class="jumbotron game">
<h2>You picked <span id="player1"><strong></strong></span></h2>
<h2>The computer selected <span id="player2"><strong></strong></span></h2>
<h2 id="roundScore"></h2>
</div>
</div>
</div>
</div>
<div class="winningPic">
<img src="./assets/images/rockWins.jpg" alt="rockWins" class="winningPic rock hide">
<img src="./assets/images/paperBeatsRock.jpg" alt="paperWins" class="winningPic paper hide">
<img src="./assets/images/scissorsBeatsPaper.jpg" alt="scissorsWins" class="winningPic scissors hide">
</div>
</div>
<script type="text/javascript">
const firebaseConfig = {
apiKey: "AIzaSyCic4VCtBetK7liUQEpEvywBskpJ5tot9w",
authDomain: "rockpaperscissors-fd4ec.firebaseapp.com",
databaseURL: "https://rockpaperscissors-fd4ec.firebaseio.com",
projectId: "rockpaperscissors-fd4ec",
storageBucket: "rockpaperscissors-fd4ec.appspot.com",
messagingSenderId: "169821655260",
appId: "1:169821655260:web:1961792ff0a9be7a40e419"
};
function userSelection() {
var userText = document.getElementById("player1");
document.onkeyup = function(event) {
if(!(document.querySelector(".win") === null)){
document.querySelector(".win").classList.add("hide");
document.querySelector(".win").classList.remove("win");
};
switch(event.key){
case 'r':
case '1':
userText.textContent = 'rock';
break;
case 'p':
case '2':
userText.textContent = 'paper';
break;
case 's':
case '3':
userText.textContent = 'scissors';
break;
}
var player1selection = document.getElementById("player1").innerText;
if(event.key === 'r' || 's' || 'p' || '1' || '2' || '3'){
computerSelection();
var player2selection = document.getElementById("player2").innerText;
score(player1selection, player2selection);
}
}
};
userSelection();
function computerSelection() {
var choices = ["rock", "paper", "scissors"];
var randomChoice = choices[Math.floor(Math.random()*choices.length)];
document.getElementById("player2").textContent = randomChoice;
};
function score(player1selection, player2selection) {
var scoreBreakdown = {
'rock-paper': 'Point goes to player 2.',
'rock-scissors': 'Point goes to player 1.',
'rock-rock': 'There was a tie.',
'paper-rock': 'Point goes to player 1.',
'paper-scissors': 'Point goes to player 2.',
'paper-paper': 'There was a tie.',
'scissors-rock': 'Point goes to player 2.',
'scissors-paper': 'Point goes to player 1.',
'scissors-scissors': 'There was a tie.'
}
document.getElementById("roundScore").textContent = (scoreBreakdown[player1selection + '-' + player2selection]);
var gamePlay = [player1selection + '-' + player2selection];
switch(gamePlay[0]){
case 'rock-scissors':
case 'scissors-rock':
document.querySelector(".rock").classList.remove("hide");
document.querySelector(".rock").classList.add("win");
break;
case 'rock-paper':
case 'paper-rock':
document.querySelector(".paper").classList.remove("hide");
document.querySelector(".paper").classList.add("win");
break;
case 'scissors-paper':
case 'paper-scissors':
document.querySelector(".scissors").classList.remove("hide");
document.querySelector(".scissors").classList.add("win");
break;
}
};
</script>
</body>
</html>