Skip to content

Instantly share code, notes, and snippets.

@igmarin
Last active August 29, 2015 14:12
Show Gist options
  • Save igmarin/1be80fb7221613aad0c9 to your computer and use it in GitHub Desktop.
Save igmarin/1be80fb7221613aad0c9 to your computer and use it in GitHub Desktop.
This a Guess Game in Ruby just for fun and taking the Chap1 in Head First Ruby as a reference :)
class GuessGame
GUESS = 10
def initialize(player_name)
@player_name = player_name
@number = generate_number
@attempts = 1
play
end
def try_to_guess
puts "This is your attempt number #{@attempts}"
puts "Please enter number:"
@guess_number = gets.chomp.to_i
@attempts += 1
end
def check_guess?
@guess_number == @number
end
def check_if_less_or_greater
@guess_number < @number ? puts("Ooops is less than") : puts("Is bigger than")
end
def you_win
puts "Congrats! #{@player_name} you won!!!"
@attempts = 11
end
def exceded_attempts?
@attempts >= GUESS
end
def generate_number
rand(100)
end
def play
begin
try_to_guess
check_guess? ? you_win : check_if_less_or_greater
end while not exceded_attempts?
end
end
@igmarin
Copy link
Author

igmarin commented Jan 14, 2015

Cierto, no se por que puse tantos puts "fuchi" me encantan los comentarios mil gracias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment