B
Bruno Santana
Hi everybody,
My application isn't working well. Let me try to explain what's wrong.
When I run my program appears something like:
ruby pedrapapeltesoura.rb
Digite pedra, papel ou tesoura: pedra
1
tesoura
pedra
alguem ganhou
This 1 that appears above is the value of resultSorteio variable, the
content of this variable come from a method which random a number
between 1 to 3. tesoura is the value of the variable maquina, however if
the variable resultSorteio is 1 the variable maquina should be pedra and
not be tesoura, and sometimes the variable is empty...if you try to play
many times you can see where is the word tesoura above will appears
nothing. Does somebody help me please. Here is my code:
class Jogo
def sorteia
opcoes = ['pedra','papel','tesoura']
numero = 1 + rand(3)
return numero
end
def joga(usuario)
result = sorteia()
resultSorteio = result.to_i
puts(resultSorteio)
puts (('11' * 2).to_i/2)
if resultSorteio == 1 then
maquina = "pedra"
if resultSorteio == 2 then
maquina = "papel"
else
maquina = "tesoura"
end
end
puts(maquina)
puts(usuario)
usuario.chop
if usuario == maquina then
puts("empatou")
else
puts("alguem ganhou")
end
end
end
j = Jogo.new()
print "Digite pedra, papel ou tesoura: "
opcaoUsuario = gets()
j.joga(opcaoUsuario)
My application isn't working well. Let me try to explain what's wrong.
When I run my program appears something like:
ruby pedrapapeltesoura.rb
Digite pedra, papel ou tesoura: pedra
1
tesoura
pedra
alguem ganhou
This 1 that appears above is the value of resultSorteio variable, the
content of this variable come from a method which random a number
between 1 to 3. tesoura is the value of the variable maquina, however if
the variable resultSorteio is 1 the variable maquina should be pedra and
not be tesoura, and sometimes the variable is empty...if you try to play
many times you can see where is the word tesoura above will appears
nothing. Does somebody help me please. Here is my code:
class Jogo
def sorteia
opcoes = ['pedra','papel','tesoura']
numero = 1 + rand(3)
return numero
end
def joga(usuario)
result = sorteia()
resultSorteio = result.to_i
puts(resultSorteio)
puts (('11' * 2).to_i/2)
if resultSorteio == 1 then
maquina = "pedra"
if resultSorteio == 2 then
maquina = "papel"
else
maquina = "tesoura"
end
end
puts(maquina)
puts(usuario)
usuario.chop
if usuario == maquina then
puts("empatou")
else
puts("alguem ganhou")
end
end
end
j = Jogo.new()
print "Digite pedra, papel ou tesoura: "
opcaoUsuario = gets()
j.joga(opcaoUsuario)