Created
October 5, 2015 12:26
-
-
Save guilhermesilveira/401c46f2bcc871f78314 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
# aqui estao as definicoes de funcoes | |
def da_boas_vindas | |
puts "Bem-vindo ao jogo de adivinhação" | |
puts "Qual é o seu nome?" | |
nome = gets | |
puts "\n\n\n\n\n\n" | |
puts "Começaremos o jogo para você, #{nome}" | |
end | |
def sorteia_numero_secreto | |
puts "Escolhendo um número secreto entre 0 e 200..." | |
sorteado = 175 | |
puts "Escolhido... que tal adivinhar hoje nosso número secreto?" | |
end | |
def pede_um_numero (tentativa,limite_de_tentativas) | |
puts "\n\n\n\n\ " | |
puts "Tentativa:" + tentativa.to_s + " de " + limite_de_tentativas.to_s | |
puts "Entre com o número" | |
chute = gets | |
puts "Será que acertou? Você chutou: + #{chute}" | |
chute.to_i | |
end | |
def verifica_se_acertou (numero_secreto,chute) | |
acertou = numero_secreto == chute | |
if acertou | |
puts "Acertou!" | |
return true | |
else | |
maior = numero_secreto > chute | |
if maior | |
puts "O número secreto é maior!" | |
return true | |
else | |
puts "O número secreto é menor!" | |
end | |
return false | |
end | |
end | |
# aqui é o inicio do seu programa | |
da_boas_vindas | |
numero_secreto = sorteia_numero_secreto | |
limite_de_tentativas = 5 | |
for tentativa in 1..limite_de_tentativas | |
chute = pede_um_numero(tentativa, limite_de_tentativas) | |
verifica_se_acertou(numero_secreto, chute) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment