3
I was trying to check if a letter is included in an array without using the .include? but I can’t get the same result. Anyone has any idea how .include? from "inside"?
The code in question is a kind of hangman game. The player kicks a letter, the letter is included in a array which is shown at each kick in order to inform the kicks made. If the player kicks a letter that has already been kicked, the game must inform that the kick has already been made and ask for a new kick.Has a loop while
that repeats the request for kicks while the player does not miss 5 times.
chutes_ate_agora = ["a","b","c","d"] #chutes hipotéticos
novo_chute = gets.strip
for chute in chutes_ate_agora
if chute == novo_chute
puts "já chutou letra #{novo_chute}"
next #vai para o loop while para pedir um novo chute
else
chutes_ate_agora << novo_chute
end
end
To inform the specific problem, I can put the code here by comment or edit the question?
– Vitor Almeida
Edit the question if no one else answers before.
– Maniero
edition made, sorry if it has not been in the most appropriate way, I am new here.
– Vitor Almeida
And what is the goal? It seems to me that everything is ok.
– Maniero
The problem is that when I enter with a kick that has already been done, it warns that it has already been done, but still stores the repeated kick in the array of kicks, which should only happen if it was a shot that was not done.
– Vitor Almeida
Do you have any reason not to use the
include
?– Maniero
Just to see if I can get the same result without this "facilitator".
– Vitor Almeida
Anyway, the question has been answered, thank you very much!!
– Vitor Almeida
You get the same thing if you do it right. I posted it, but it doesn’t make sense.
– Maniero