Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. puts 'Play Paper Rock Scissors!'
  2. def play
  3. begin
  4. puts 'Choose one: (P/R/S)'
  5. choice = gets.chomp.downcase
  6. end until choice == 'p' || choice == 'r' || choice == 's'
  7. if choice == 'p'
  8. choice = 0
  9. elsif choice == 'r'
  10. choice = 1
  11. elsif choice == 's'
  12. choice = 2
  13. end
  14. # generate a random number ranging from 0,1,2
  15. computer_choice_number = rand(3)
  16. return [choice, computer_choice_number]
  17. end
  18. def play_again_check()
  19. begin
  20. puts "Play again? (Y/N)"
  21. answer = gets.chomp.downcase
  22. end until answer == 'y' || answer == 'n'
  23. if answer == 'y'
  24. 'y'
  25. elsif answer == 'n'
  26. puts "Thanks for playing!"
  27. end
  28. end
  29. begin
  30. answers_array = play
  31. case answers_array
  32. when [0, 0]
  33. puts "You picked Paper and computer picked Paper"
  34. puts "It's a tie"
  35. when [1, 1]
  36. puts "You picked Rock and computer picked Rock"
  37. puts "It's a tie"
  38. when [2, 2]
  39. puts "You picked Scissors and computer picked Scissors"
  40. puts "It's a tie"
  41. when [0, 1]
  42. puts "You picked Paper and computer picked Rock"
  43. puts "You win!"
  44. when [0, 2]
  45. puts "You picked Paper and computer picked Scissors"
  46. puts "You lose!"
  47. when [1, 0]
  48. puts "You picked Rock and computer picked Paper"
  49. puts "You lose!"
  50. when [1, 2]
  51. puts "You picked Rock and computer picked Scissors"
  52. puts "You win!"
  53. when [2, 0]
  54. puts "You picked Scissors and computer picked Paper"
  55. puts "You win!"
  56. when [2, 1]
  57. puts "You picked Scissors and computer picked Rock"
  58. puts "You lose!"
  59. else
  60. puts "A combination/possibility was not thought of, contact developer immediately!"
  61. end
  62. end while play_again_check == 'y'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement