Skip to content

Instantly share code, notes, and snippets.

@lrlucena
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lrlucena/67bc0510435c4b418556 to your computer and use it in GitHub Desktop.
Save lrlucena/67bc0510435c4b418556 to your computer and use it in GitHub Desktop.
class MaiorMenor
def initialize()
@numero = rand(100) + 1
@fim_de_jogo = false
end
def palpite(valor)
if valor < @numero then
resposta = "O numero eh maior do que #{valor}: "
elsif valor > @numero then
resposta = "O numero eh menor do que #{valor}: "
else
resposta = "Parabens, voce ganhou!"
@fim_de_jogo = true
end
return resposta
end
def fim?
return @fim_de_jogo
end
end
puts "Jogo Maior - Menor"
puts ""
jogo = MaiorMenor.new()
print "Eu escolhi um numero entre 1 e 100. Tente adivinhar: "
while not jogo.fim?
p = gets.to_i
print jogo.palpite(p)
end
puts "Parabens, voce ganhou!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment