-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.js
141 lines (129 loc) · 5.94 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
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
const prompt = require("prompt-sync")();
let {Robot} = require("./ai");
let {HumanPlayer} = require("./human");
class Game {
constructor(){
this.playerOne;
this.playerTwo;
}
welcomeDisplay(){
console.log("Welcome to RPSLizardSpock!");
console.log("Before we begin, let's go over the rules. This is a variation of the classic rock, paper, scissors game but with a new twist.");
console.log("All you need to know is: Rock crushes scissors, scissors cuts paper, \n paper covers rock, rock smashes lizard, lizard poisons spock, spock smashes scissors, \n scissors decapitate lizard, lizard eats paper, paper disproves spock, spock vaporizes rock, \n and rock crushes scissors!");
this.playerOne = new HumanPlayer();
console.log("Would you like to play against another person or against AI? 1 for human or 2 for AI?");
let playOption = prompt();
switch(playOption){
case "1":
this.playerTwo = new HumanPlayer();
break;
case "2":
this.playerTwo = new Robot();
break;
default:
console.log("Invalid response, please try again!");
return
}
}
runRPSLS(){
console.log(`${this.playerOne.name} vs ${this.playerTwo.name}... BEGIN!`);
while(this.playerOne.pointTally < 3 && this.playerTwo.pointTally < 3){
let playerOneGesture = this.playerOne.selectHandGesture();
let playerTwoGesture = this.playerTwo.selectHandGesture();
this.compareGestures(playerOneGesture, playerTwoGesture)
}
}
compareGestures(playerOneChoice, playerTwoChoice){
//Rock Comparison
if(playerOneChoice === "Rock" && playerTwoChoice === "Scissors"){
this.playerOne.pointTally++;
console.log(`${this.playerOne.name} won this round!`);
} else if(playerTwoChoice === "Paper" && playerOneChoice === "Rock"){
this.playerTwo.pointTally++;
console.log(`${this.playerTwo.name} won this round`);
}
if(playerOneChoice === "Rock" && playerTwoChoice === "Lizard"){
this.playerOne.pointTally++;
console.log(`${this.playerOne.name} won this round!`);
} else if(playerTwoChoice === "Spock" && playerOneChoice === "Rock"){
this.playerTwo.pointTally++;
console.log(`${this.playerTwo.name} won this round`);
}
//Scissors Comparison
if(playerOneChoice === "Scissors" && playerTwoChoice === "Paper"){
this.playerOne.pointTally++;
console.log(`${this.playerOne.name} won this round!`);
} else if(playerTwoChoice === "Spock" && playerOneChoice === "Scissors"){
this.playerTwo.pointTally++;
console.log(`${this.playerTwo.name} won this round`);
}
if(playerOneChoice === "Scissors" && playerTwoChoice === "Lizard"){
this.playerOne.pointTally++;
console.log(`${this.playerOne.name} won this round!`);
} else if(playerTwoChoice === "Rock" && playerOneChoice === "Scissors"){
this.playerTwo.pointTally++;
console.log(`${this.playerTwo.name} won this round`);
}
//Paper Comparison
if(playerOneChoice === "Paper" && playerTwoChoice === "Rock"){
this.playerOne.pointTally++;
console.log(`${this.playerOne.name} won this round!`);
} else if(playerTwoChoice === "Scissors" && playerOneChoice === "Paper"){
this.playerTwo.pointTally++;
console.log(`${this.playerTwo.name} won this round`);
}
if(playerOneChoice === "Paper" && playerTwoChoice === "Spock"){
this.playerOne.pointTally++;
console.log(`${this.playerOne.name} won this round!`);
} else if(playerTwoChoice === "Lizard" && playerOneChoice === "Paper"){
this.playerTwo.pointTally++;
console.log(`${this.playerTwo.name} won this round`);
}
//Lizard Comparison
if(playerOneChoice === "Lizard" && playerTwoChoice === "Spock"){
this.playerOne.pointTally++;
console.log(`${this.playerOne.name} won this round!`);
} else if(playerTwoChoice === "Rock" && playerOneChoice === "Lizard"){
this.playerTwo.pointTally++;
console.log(`${this.playerTwo.name} won this round`);
}
if(playerOneChoice === "Lizard" && playerTwoChoice === "Paper"){
this.playerOne.pointTally++;
console.log(`${this.playerOne.name} won this round!`);
} else if(playerTwoChoice === "Scissors" && playerOneChoice === "Lizard"){
this.playerTwo.pointTally++;
console.log(`${this.playerTwo.name} won this round`);
}
//Spock Comparison
if(playerOneChoice === "Spock" && playerTwoChoice === "Rock"){
this.playerOne.pointTally++;
console.log(`${this.playerOne.name} won this round!`);
} else if(playerTwoChoice === "Paper" && playerOneChoice === "Spock"){
this.playerTwo.pointTally++;
console.log(`${this.playerTwo.name} won this round`);
}
if(playerOneChoice === "Spock" && playerTwoChoice === "Scissors"){
this.playerOne.pointTally++;
console.log(`${this.playerOne.name} won this round!`);
} else if(playerTwoChoice === "Lizard" && playerOneChoice === "Spock"){
this.playerTwo.pointTally++;
console.log(`${this.playerTwo.name} won this round`);
}
}
declareWinner(){
if (this.playerOne.pointTally > this.playerTwo.pointTally){
console.log(`The winner is ${this.playerOne.name}!`)
}
else {
console.log(`The winner is ${this.playerTwo.name}!`)
}
}
runGame(){
this.welcomeDisplay();
this.runRPSLS();
this.declareWinner();
}
}
module.exports = {
Game: Game,
}