-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.js
34 lines (34 loc) · 1.17 KB
/
game.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
class Game {
constructor(){
this.id = Date.now()
this.playerOne = new Player("human", "./assets/human.png")
this.playerTwo = new Player("computer", "./assets/robot.png")
this.gameMode
this.playerOneChoice
this.playerTwoChoice
this.winMsg
this.winStates = {
rock: ['scissors', 'lizard'],
paper: ['rock', 'alien'],
scissors: ['paper', 'lizard'],
lizard: ['paper','alien'],
alien: ['scissors', 'rock']
}
}
checkWinStates(playerOneChoice, gameMode){
this.playerTwoChoice = this.playerTwo.takeTurn(gameMode)
if (this.winStates[this.playerTwoChoice].includes(this.playerOneChoice)) {
this.playerTwo.increaseWins()
this.winMsg = `Computer Wins!`
return
}
else if(this.winStates[playerOneChoice].includes(this.playerTwoChoice)){
this.playerOne.increaseWins()
this.winMsg = `Nice! You win!`
return
}
else
this.winMsg = `It's a draw!`
return
}
}