-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
162 lines (137 loc) · 8.71 KB
/
script.js
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
/*
███╗░░░███╗░█████╗░██╗███╗░░██╗ ░██████╗░░█████╗░███╗░░░███╗███████╗ ░█████╗░░█████╗░██████╗░███████╗
████╗░████║██╔══██╗██║████╗░██║ ██╔════╝░██╔══██╗████╗░████║██╔════╝ ██╔══██╗██╔══██╗██╔══██╗██╔════╝
██╔████╔██║███████║██║██╔██╗██║ ██║░░██╗░███████║██╔████╔██║█████╗░░ ██║░░╚═╝██║░░██║██║░░██║█████╗░░
██║╚██╔╝██║██╔══██║██║██║╚████║ ██║░░╚██╗██╔══██║██║╚██╔╝██║██╔══╝░░ ██║░░██╗██║░░██║██║░░██║██╔══╝░░
██║░╚═╝░██║██║░░██║██║██║░╚███║ ╚██████╔╝██║░░██║██║░╚═╝░██║███████╗ ╚█████╔╝╚█████╔╝██████╔╝███████╗
╚═╝░░░░░╚═╝╚═╝░░╚═╝╚═╝╚═╝░░╚══╝ ░╚═════╝░╚═╝░░╚═╝╚═╝░░░░░╚═╝╚══════╝ ░╚════╝░░╚════╝░╚═════╝░╚══════╝
*/
// define weapons of choice
let choices = ["rock","paper","scissors"];
// select random weapon for computer
function getComputerChoice(arr) {
let choice = arr[Math.floor(Math.random()*arr.length)];
return choice;
}
// define variables that will be used
let playerSelection = "";
let computerSelection = getComputerChoice(choices);
let playerScore = 0;
let computerScore = 0;
let roundCount = 0;
// add score element
let score = document.querySelector(".playerScore");
score.textContent = `Player Score: ${playerScore} `;
let compScore = document.querySelector(".computerScore");
compScore.textContent = `Computer Score: ${computerScore}`;
// add message and round element counter
let display = document.querySelector(".message");
display.textContent = `Nothing has been played yet`;
// add emoji display boxes - comment out old feature
// let playerEmojiBox = document.querySelector(".playerEmojiBox");
// let computerEmojiBox = document.querySelector(".computerEmojiBox");
let playerEmojiBoxSingle = document.querySelector(".playerEmojiBoxSingle");
let computerEmojiBoxSingle = document.querySelector(".computerEmojiBoxSingle");
let emojiBox = document.querySelector(".emojiBox");
const emojiBoxArray = []
//function to display player weapon display
function displayPlayerWeapon(input){
if (input == "rock") {
playerEmojiBoxSingle.textContent=("🪨");
} else if (input == "paper") {
playerEmojiBoxSingle.textContent=("📄");
} else {
playerEmojiBoxSingle.textContent=("✂️");
}
}
//function to display computer weapon display
function displayComputerWeapon(input){
if (input == "rock") {
computerEmojiBoxSingle.textContent=("🪨");
} else if (input == "paper") {
computerEmojiBoxSingle.textContent=("📄");
} else {
computerEmojiBoxSingle.textContent=("✂️");
}
}
//function to determine the main logic - win/lose scenarios
function getWinnerLoser(playerSelection, computerSelection) {
if (playerSelection == computerSelection) {
display.textContent=(`You both played ${playerSelection}`);
} else if (playerSelection == "rock") {
if (computerSelection == "paper") {
display.textContent=("you lose, paper beats rock");
computerScore += 1;
compScore.textContent = `Computer Score: ${computerScore}`;
} else if (computerSelection == "scissors") {
display.textContent=("you win, rock beats scissors");
playerScore += 1;
score.textContent = `Player Score: ${playerScore} `;
}
} else if (playerSelection == "paper") {
if (computerSelection == "scissors") {
display.textContent=("you lose, scissors beats paper");
computerScore += 1;
compScore.textContent = `Computer Score: ${computerScore}`;
} else if (computerSelection == "rock") {
display.textContent=("you win, paper beats rock");
playerScore += 1;
score.textContent = `Player Score: ${playerScore} `;
}
} else if (playerSelection == "scissors") {
if (computerSelection == "rock") {
display.textContent=("you lose, rock beats scissors");
computerScore += 1;
compScore.textContent = `Computer Score: ${computerScore}`;
} else if (computerSelection == "paper") {
display.textContent=("you win, scissors beats paper");
playerScore += 1;
score.textContent = `Player Score: ${playerScore} `;
}
}
}
// play a round
function playRound(playerSelection, computerSelection) {
playerSelection = playerSelection;
computerSelection = getComputerChoice(choices);
emojiDisplayBoxFunction(playerSelection,computerSelection);
// player weapon counter/display emoji boxes
displayPlayerWeapon(playerSelection);
// computer weapon counter/display emoji boxes
displayComputerWeapon(computerSelection);
// main logic - scenarios
getWinnerLoser(playerSelection, computerSelection);
round.textContent = `Round ${roundCount}`;
}
// console.log(playRound(playerSelection, computerSelection));
/*
███████╗███╗░░░███╗░█████╗░░░░░░██╗██╗ ██████╗░██╗░██████╗██████╗░██╗░░░░░░█████╗░██╗░░░██╗
██╔════╝████╗░████║██╔══██╗░░░░░██║██║ ██╔══██╗██║██╔════╝██╔══██╗██║░░░░░██╔══██╗╚██╗░██╔╝
█████╗░░██╔████╔██║██║░░██║░░░░░██║██║ ██║░░██║██║╚█████╗░██████╔╝██║░░░░░███████║░╚████╔╝░
██╔══╝░░██║╚██╔╝██║██║░░██║██╗░░██║██║ ██║░░██║██║░╚═══██╗██╔═══╝░██║░░░░░██╔══██║░░╚██╔╝░░
███████╗██║░╚═╝░██║╚█████╔╝╚█████╔╝██║ ██████╔╝██║██████╔╝██║░░░░░███████╗██║░░██║░░░██║░░░
╚══════╝╚═╝░░░░░╚═╝░╚════╝░░╚════╝░╚═╝ ╚═════╝░╚═╝╚═════╝░╚═╝░░░░░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░
██████╗░░█████╗░██╗░░██╗
██╔══██╗██╔══██╗╚██╗██╔╝
██████╦╝██║░░██║░╚███╔╝░
██╔══██╗██║░░██║░██╔██╗░
██████╦╝╚█████╔╝██╔╝╚██╗
╚═════╝░░╚════╝░╚═╝░░╚═╝
*/
let roundCountDisplay = document.querySelector(".roundCountDisplay");
function addRoundCount(){
roundCount +=1;
roundCountDisplay.textContent = `round ${roundCount}`;
}
let emojiDisplayArray = [];
let emojiDisplayBox = document.querySelector(".emoji-display-box");
function emojiDisplayBoxFunction (playerSelection, computerSelection) {
if (emojiDisplayArray.length < 10) {
emojiDisplayArray.unshift(roundCount+playerSelection+`⚔️`+computerSelection+"\n");
emojiDisplayBox.textContent = emojiDisplayArray;
} else {
emojiDisplayArray.unshift(roundCount+playerSelection+`⚔️`+computerSelection+"\n");
emojiDisplayArray.pop();
emojiDisplayBox.textContent = emojiDisplayArray;
}
}