Advance game logic to be player vs bot instead of bot vs bot.
This commit is contained in:
parent
74d5d4d6d9
commit
0926d5a0fc
1 changed files with 7 additions and 13 deletions
20
rps.js
20
rps.js
|
@ -14,30 +14,24 @@ function playRPS() {
|
||||||
player1Choice = "Scissors";
|
player1Choice = "Scissors";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Math.abs(player2 - 1) < Math.abs(player2 - 2) && Math.abs(player2 - 1) < Math.abs(player2 - 3)) {
|
player2Choice = prompt("Rock, Paper, or Scissors?")
|
||||||
player2Choice = "Rock";
|
|
||||||
} else if (Math.abs(player2 - 2) < Math.abs(player2 - 1) && Math.abs(player2 - 2) < Math.abs(player2 - 3)) {
|
|
||||||
player2Choice = "Paper";
|
|
||||||
} else {
|
|
||||||
player2Choice = "Scissors";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine the winner based on game logic
|
// Determine the winner based on game logic
|
||||||
let winner;
|
let winner;
|
||||||
if (player1Choice === player2Choice) {
|
if (player1Choice === player2Choice) {
|
||||||
winner = "Tie";
|
winner = "Tie";
|
||||||
} else if (player1Choice === "Rock") {
|
} else if (player1Choice === "Rock") {
|
||||||
winner = player2Choice === "Scissors" ? "Player 1" : "Player 2";
|
winner = player2Choice === "Scissors" ? "Bot" : "Player";
|
||||||
} else if (player1Choice === "Paper") {
|
} else if (player1Choice === "Paper") {
|
||||||
winner = player2Choice === "Rock" ? "Player 1" : "Player 2";
|
winner = player2Choice === "Rock" ? "Bot" : "Player";
|
||||||
} else { // player1Choice === "Scissors"
|
} else { // player1Choice === "Scissors"
|
||||||
winner = player2Choice === "Paper" ? "Player 1" : "Player 2";
|
winner = player2Choice === "Paper" ? "Bot" : "Player";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the results
|
// Print the results
|
||||||
console.log(`Player 1: ${player1Choice}`);
|
alert(`Bot: ${player1Choice}
|
||||||
console.log(`Player 2: ${player2Choice}`);
|
Player: ${player2Choice}
|
||||||
console.log(`Winner: ${winner}`);
|
Winner: ${winner}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Play the game twice (once per player)
|
// Play the game twice (once per player)
|
||||||
|
|
Loading…
Reference in a new issue