21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/rps/game.rb', line 21
def winner(choice)
player2_choice = ["r", "p", "s"].sample
puts "Player 2 chooses #{player2_choice}"
if choice == player2_choice
puts "It's a tie!"
elsif choice == "r" && player2_choice == "p"
puts "Player 2 wins"
elsif choice == "r" && player2_choice == "s"
puts "Player 1 wins"
elsif choice == "p" && player2_choice == "s"
puts "Player 2 wins"
elsif choice == "p" && player2_choice == "r"
puts "Player 1 wins"
elsif choice == "s" && player2_choice == "p"
puts "Player 1 wins"
elsif choice == "s" && player2_choice == "r"
puts "Player 2 wins"
end
end
|