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 X variable that sets my particular 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 random order and if it hits, it 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 debugged and I have noticed that the variables are passing the values correctly but I am in doubt as to how I will compare those variables, and how will the if to verify that they are correct.
The logic I'm using is as follows:
This is the comparison I am using to see if the user has hit the sequence but is wrong
if (botao.Name == "btnAmarelo")
{
ordem1 = ordem;
if (ordem1 == ordem)
{
lblPontuacao.Text = "10";
}
}
This is the timer I use to flash the colors (not the whole timer, just 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 blinking 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";
}
}