Last active
August 29, 2015 14:26
-
-
Save lrlucena/67bc0510435c4b418556 to your computer and use it in GitHub Desktop.
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 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