早些时候我问过为我创建的RPS游戏增加点数,问题是固定的,但现在我遇到了一个新问题。每次用户滚动他们的项目(摇滚,纸张或剪刀)时,都是平局。我已经尝试为数组添加一个百分比33.5%为2和33%为一个增加到100并且它仍然每次都作为平局。
def welcome
puts "Welcome to Rock, Paper, Scissors. To begin press 'S'.
To learn how to play press 'I'. To quit the game press 'Q'"
input = gets.chomp
if input =~ /s/i
start_game
elsif input =~ /i/i
instructions
else
exit
end
end
def start_game
start_points_P1 = 0
start_points_P2 = 0
choice = ['Rock', 'Paper', 'Scissors']
choice2 = ['Rock', 'Paper', 'Scissors']
player1 = choice.sample
player2 = choice2.sample
puts "Press 'R' to roll for Player 1"
input = gets.chomp!
puts "Player 1 has recieved #{player1}"
puts "Press 'E' to roll for Player 2!"
input = gets.chomp!
puts "Player 2 has recieved #{player2}"
if player1 == player2
puts "Draw!"
start_game
elsif player1 == 'Paper' && player2 == 'Scissors'
start_points_P2 += 10
puts "Player 2 has won with #{player2}. You now have #{start_points_P2} points and opponent has #{start_points_P1} points"
elsif player1 == 'Scissors' && player2 == 'Paper'
start_points_P1 += 10
puts "Player 1 has won with #{player1}. You know have #{start_points_P1} points and opponent has #{start_points_P2} points"
elsif player1 == 'Rock' && player2 == 'Paper'
start_points_P2 += 10
puts "Player 2 has won with #{player2}. You now have #{start_points_P2} points and opponent has #{start_points_P1} points"
elsif player1 == 'Paper' && player2 == 'Rock'
start_points_P1 += 10
puts "Player 1 has won with #{player1}. You know have #{start_points_P1} points and opponent has #{start_points_P2} points"
elsif player1 == 'Scissors' && player2 == 'Rock'
start_points_P2 += 10
puts "Player 2 has won with #{player2}. You now have #{start_points_P2} points and opponent has #{start_points_P1} points"
elsif player1 == 'Rock' && player2 == 'Scissors'
start_points_P1 += 10
puts "Player 1 has won with #{player1}. You know have #{start_points_P1} points and opponent has #{start_points_P2} points"
end
end
welcome
我在这里遗漏了什么,如果我将玩家设置为单独的数组并且只调用.sample
一次,为什么它会一直显示为平局?