Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_user_input
- puts "Rock, Paper, or Scissors?"
- input = gets.chomp.upcase
- return 0 if input[0] == "R"
- return 1 if input[0] == "P"
- return 2
- end
- playing, d, w, l = true, 0, 0, 0
- while playing
- user = get_user_input()
- cpu = Random.rand(0..2)
- if user == cpu
- puts "You drew!"
- d += 1
- elsif (user == 1 && cpu == 0) || (user == 2 && cpu == 1) || (user == 0 && cpu == 2)
- puts "You won!"
- w += 1
- else
- puts "You lost!"
- l += 1
- end
- puts "Draws: #{d}\nWins: #{w}\nLosses: #{l}\nWould you like to play again?"
- playing = false unless gets.chomp.upcase[0] == "Y"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement