-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.js
More file actions
53 lines (48 loc) · 2.16 KB
/
game.js
File metadata and controls
53 lines (48 loc) · 2.16 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
class Game {
constructor() {
this.playerOne = new Player('Human', '😎');
this.playerTwo = new Player('Computer', '💻');
this.gameType = null;
this.choicesEasy = [
{name: "rock", token: "💀", beats: "scissors", losesTo: "paper"},
{name: "paper", token: "🫀", beats: "rock", losesTo: "scissors"},
{name: "scissors", token: "🔪", beats: "paper", losesTo: "rock"}
];
this.choicesHard = [
{name: "final girl", token: "👩🏼🦰", beats: ['hunter', 'killer'], losesTo: ['jock', 'nerd']},
{name: "jock", token: "🏋🏿", beats: ['final girl', 'nerd'], losesTo: ['hunter', 'killer']},
{name: "hunter", token: "🕵🏾", beats: ['jock', 'killer'], losesTo: ['final girl', 'nerd']},
{name: "killer", token: "🧟♂️", beats: ['jock', 'nerd'], losesTo: ['final girl', 'hunter']},
{name: "nerd", token: "🤓", beats: ['final girl', 'hunter'], losesTo: ['jock', 'killer']}
];
};
checkForWinConditionsEasy() {
var p1Move = this.choicesEasy[this.playerOne.move];
var p2Move = this.choicesEasy[this.playerTwo.move];
if (this.playerOne.move === this.playerTwo.move) {
return "It's a tie!";
} else if (p1Move.name === p2Move.beats) {
this.playerTwo.wins++;
return `${this.playerTwo.name} wins!`
} else if (p2Move.name === p1Move.beats) {
this.playerOne.wins++;
return `${this.playerOne.name} wins!`
};
};
checkForWinConditionsHard() {
var p1Move = this.choicesHard[this.playerOne.move];
var p2Move = this.choicesHard[this.playerTwo.move];
if (this.playerOne.move === this.playerTwo.move) {
return "It's a tie!";
} else if(p1Move.beats.includes(p2Move.name)) {
this.playerOne.wins++;
return `${this.playerOne.name} wins!`
} else if (p2Move.beats.includes(p1Move.name)) {
this.playerTwo.wins++;
return `${this.playerTwo.name} wins!`
};
};
resetGame() {
this.gameType = null;
};
};