2017-07-15 16 views
-1

エラー:ロック、ペーパー、シザールビー

syntax error, unexpected tIDENTIFIER, expecting end-of-input end whlie continue == "N"

私はすべてのコードをチェックし、私はまだそれを得ることはありません。

while continue == "N"の後にエンドコードを追加する必要がありますか? whileため

begin 
     puts "|===============================================|" 
     puts "|Welcome to Rock Paper Scissors!!!    |" 
     puts "|===============================================|" 

     begin 
     puts "please choose one of the following: R/P/S" 
     user_input = gets.chomp.upcase 
     end while !["R", "P", "S"].include?(user_input) 


     com_input = ["R", "P", "S"].sample 

     puts "You:#{user_input} Com:#{com_input}" 

     if user_input = "R" && com_input = "S" || user_input = "S" && com_input = "P" || user_input = "P" && com_input = "R" 
     puts "Result:You win" 
     elsif com_input = "R" && user_input = "S" || com_input = "S" && user_input = "P" || com_input = "P" && user_input = "R" 
     puts "Result:You lose" 
     else 
     puts "Result:Draw" 
     end 

     begin 
     puts "Play Again?: Y/N" 
     continue = gets.chomp.upcase 
     end while !["Y", "N"].include?(continue) 

    end whlie continue == "N" 
    puts "Good Bye! Thanks for playing!" 

答えて

0

変更whlie

また、whileは、Nを確認していますが、これはYである必要があります。

begin 
    puts "|===============================================|" 
    puts "|Welcome to Rock Paper Scissors!!!    |" 
    puts "|===============================================|" 

    choices = ['R', 'P', 'S'] 

    begin 
    puts 'please choose one of the following: R/P/S' 
    user_input = gets.chomp.upcase 
    end while !choices.include?(user_input) 

    com_input = choices.sample 

    puts "You: #{user_input} Com: #{com_input}" 

    regex = /rs|sp|pr/i 
    choice = "#{user_input}#{com_input}" 

    if choice =~ regex 
    puts 'Result:You win' 
    elsif choice.reverse =~ regex 
    puts 'Result:You lose' 
    else 
    puts 'Result:Draw' 
    end 

    puts 'Play Again?: Y/N' 
    continue = gets.chomp.upcase 

end while continue == 'Y' 

puts 'Good Bye! Thanks for playing!' 
:あなたは少し usercom入力検証を低減し、かつDRYのビットを適用できる場合

begin 
    ... 
end while continue == 'Y' 

puts "Good Bye! Thanks for playing!" 

関連する問題