Last active
August 29, 2015 14:15
-
-
Save egrueter-dev/499ad013aac35e2b32c9 to your computer and use it in GitHub Desktop.
Guess-the-number
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 characters
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