From: steve ross Date: 2010-04-13T06:32:57+09:00 Subject: Re: My application doesn't work well Try this: def sorteia return ['pedra','papel','tesoura'][rand(3)] end def joga(usario) macina = sorteia puts usario.chop == macina ? empatou" : "alguem ganhou" end I'm don't read enough Portugese (?) to fully understand the intent of your code, but the above should do pretty much the same as what you've shown below, but should never give you randomly blank results. Hope this helps On Apr 12, 2010, at 2:16 PM, Bruno Santana wrote: > > 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)