Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- puts 'Rock, paper, scissors Start...'
- hands = [:rock, :scissors, :paper]
- priority = {
- :rock => :paper,
- :scissors => :rock,
- :paper => :scissors
- }
- loop do
- begin
- puts '=== New Game ==='
- puts 'Please input 1 (Rock) or 2 (Scissors) or 3 (Paper)'
- input = gets.to_i
- raise IOError unless [1, 2, 3].include? input
- player = hands[input - 1]
- cpu = hands.choice
- res = "#{player} vs #{cpu} => "
- res << case player
- when cpu : 'Drow'
- when priority[cpu] : 'You Win. Congratulation!'
- else 'You Lose...'
- end
- puts res
- rescue IOError
- puts 'Input Error. retry...'
- retry
- end
- end
Add Comment
Please, Sign In to add comment