Created
November 27, 2010 23:27
-
-
Save willluongo/718383 to your computer and use it in GitHub Desktop.
Revisions
-
willluongo revised this gist
Nov 27, 2010 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,8 +4,8 @@ def initialize @lower_limit=1 @guess=50 @quit = false until self.quit_playing self.comp_guess self.input = gets.chomp.to_i end end @@ -35,15 +35,15 @@ def input=(player_input) 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 -
willluongo created this gist
Nov 27, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ class GuessingGame def initialize @upper_limit=100 @lower_limit=1 @guess=50 @quit = false puts self.comp_guess until self.quit_playing 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 puts self.comp_guess end def win @quit = true end def comp_guess @quit == true ? "You win!!\nThanks for playing!\n\n" : "Please 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