Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class GuessingGame
- def initialize
- @upper_limit=100
- @lower_limit=1
- @guess=50
- @quit = false
- until self.quit_playing
- self.comp_guess
- self.input = gets.chomp.to_i
- end
- end
- def guess_number
- ((@upper_limit + @lower_limit)/2)
- end
- def too_low
- @lower_limit = @guess
- end
- def too_high
- @upper_limit = @guess
- end
- def input=(player_input)
- case player_input
- when 1
- self.too_low
- when 2
- self.too_high
- when 3
- self.win
- else
- puts "Please pick option 1, 2, or 3."
- end
- @guess = self.guess_number
- end
- def win
- @quit = true
- puts "\n\nYou win!!\nThanks for playing!\n\n"
- end
- def comp_guess
- 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}"
- end
- def quit_playing
- @quit
- end
- end
- This_Game = GuessingGame.new
Add Comment
Please, Sign In to add comment