Guest User

Untitled

a guest
Jul 15th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. class GuessingGame
  2. def initialize
  3. @upper_limit=100
  4. @lower_limit=1
  5. @guess=50
  6. @quit = false
  7. until self.quit_playing
  8. self.comp_guess
  9. self.input = gets.chomp.to_i
  10. end
  11. end
  12.  
  13. def guess_number
  14. ((@upper_limit + @lower_limit)/2)
  15. end
  16.  
  17. def too_low
  18. @lower_limit = @guess
  19. end
  20.  
  21. def too_high
  22. @upper_limit = @guess
  23. end
  24.  
  25. def input=(player_input)
  26. case player_input
  27. when 1
  28. self.too_low
  29. when 2
  30. self.too_high
  31. when 3
  32. self.win
  33. else
  34. puts "Please pick option 1, 2, or 3."
  35. end
  36.  
  37. @guess = self.guess_number
  38. end
  39.  
  40. def win
  41. @quit = true
  42. puts "\n\nYou win!!\nThanks for playing!\n\n"
  43. end
  44.  
  45. def comp_guess
  46. puts "\n\nPlease select one of the following:\n(1) Too Low\n(2) Too High\n(3) That's it!\n\nI guess #{@guess}"
  47. end
  48.  
  49. def quit_playing
  50. @quit
  51. end
  52. end
  53.  
  54. This_Game = GuessingGame.new
Add Comment
Please, Sign In to add comment