0
I’m making a game of colors, in it I have a Random that randomizes buttons in a certain sequence.
The value of these buttons are concatenated in the variavelX that sets my given sequence.
ex:
botão1 = "1";
botão2 = "2";
botão3 = "3";
botão4 = "4";
variavelX = 32131 // variavelX recebe a ordem da sequência randomizada, que no exemplo foi 32131
I need to make the user of my system press the buttons that were drawn, that is, in the same randomized order and if right, assigns 10 points in the label lblPontuacao
Example:
variavelX = 32131
// Jogador precisa clicar na seguinte sequência, 3 (botão3), 2 (botão2), 1 (botão1), 3 (botão3), 1 (botão1), e se ele acertar, é atruibuido 10 pontos
I have already debug and I have noticed that the variables are passing the values correctly but I am doubtful how I will compare these variables, and how will be the if to check if they are correct.
The logic I’m using is the following:
This is the comparison I’m using to see if the user hit the sequence, but it’s wrong
if (botao.Name == "btnAmarelo")
{
ordem1 = ordem;
if (ordem1 == ordem)
{
lblPontuacao.Text = "10";
}
}
This is the timer I use to blink colors (there is not the whole timer, only a part)
private void timerCores_Tick(object sender, EventArgs e)
{
Random random = new Random();
int rand = random.Next(1, 13);
if (rand == 1)
{
timerCores.Start();
Cores(btnAzul);
timerCores.Stop();
lblPreparado.Text = "Clique na sequência";
}
else if (rand == 2)
{
Cores(btnVermelho);
timerCores.Start();
}
else if (rand == 3)
{
Cores(btnVerde);
timerCores.Start();
}
}
And this is the method that assigns a value to the flashing colors.
public void Posicao(Button botao)
{
if (botao.Name == "btnAzul")
{
ordem = ordem + "a";
}
if (botao.Name == "btnVermelho")
{
ordem = ordem + "b";
}
if (botao.Name == "btnVerde")
{
ordem = ordem + "c";
}
if (botao.Name == "btnAmarelo")
{
ordem = ordem + "d";
}
}
The information is very loose, it’s hard to understand what you did and where you’re going. You should [Dit] the question including more details and mainly what you did. Give us as much relevant information as you can so we can help you.
– Maniero
My suggestion is to use something like a list (or array) to represent your sequence, not a number. You you can even encode a sequence into a number (eg.:
1243 = 1*1000 + 2*100 + 4*10 + 3
) and use module operations/rest to access individual items, but in my opinion this would complicate for nothing... (unless you are already doing this, of course - what kind ofvariavelX
?)– mgibsonbr