Skip to content

Instantly share code, notes, and snippets.

@egrueter-dev
Last active August 29, 2015 14:15
Show Gist options
  • Save egrueter-dev/499ad013aac35e2b32c9 to your computer and use it in GitHub Desktop.
Save egrueter-dev/499ad013aac35e2b32c9 to your computer and use it in GitHub Desktop.
Guess-the-number
class GuessingGame
def initialize(guess)
$user_choice = guess
$comp_selection = rand(1...1000)
end
def numeric?(user_choice)
true if Float(user_choice) rescue false
end
def check_number
while true
if numeric?($user_selection) == false
puts "please select again"
$user_selection = gets.chomp
elsif numeric?($user_selection) == true
$user_selection = gets.chomp.to_i
if $user_selection < $comp_selection
puts "go higher"
elsif $user_selection > $comp_selection
puts "Go Lower"
else
puts "Got it"
return false
end
end
end
end
def run_game
check_number
end
end
game1 = GuessingGame.new("p")
game1.run_game
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment