Guest User

Untitled

a guest
May 25th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. puts 'Rock, paper, scissors Start...'
  4.  
  5. hands = [:rock, :scissors, :paper]
  6. priority = {
  7. :rock => :paper,
  8. :scissors => :rock,
  9. :paper => :scissors
  10. }
  11.  
  12. loop do
  13. begin
  14. puts '=== New Game ==='
  15. puts 'Please input 1 (Rock) or 2 (Scissors) or 3 (Paper)'
  16.  
  17. input = gets.to_i
  18. raise IOError unless [1, 2, 3].include? input
  19.  
  20. player = hands[input - 1]
  21. cpu = hands.choice
  22.  
  23. res = "#{player} vs #{cpu} => "
  24.  
  25. res << case player
  26. when cpu : 'Drow'
  27. when priority[cpu] : 'You Win. Congratulation!'
  28. else 'You Lose...'
  29. end
  30.  
  31. puts res
  32. rescue IOError
  33. puts 'Input Error. retry...'
  34. retry
  35. end
  36. end
Add Comment
Please, Sign In to add comment