cristi.gherghina
cristi.gherghina

Reputation: 321

How can I increase score?

I want to make a logo quiz. And if the player hits a button an image is shown. Then he must guess the logo shown in the picture.

if he guesses the score will increase.

I dont know how to do this.

I tried

private void nou_Click(object sender, EventArgs e)
        {
            int i, j;
            int score = 0;


        for (i = 0; i < 4; i++)
            for (j = 0; j < 4; j++)
            {
                if (verificabutton.BackgroundImage == logobutton[i, j].BackgroundImage)
                    if ((sender as Button) == nou)
                        if (logoText.Text == logoLabel[i, j].Text)
                        {
                            MessageBox.Show("bravo");
                            logobutton[i, j].Enabled = false;
                            logoLabelSubText[i, j].Text = logoLabel[i, j].Text;
                            score++;
                            MessageBox.Show(score.ToString());

                        }
                        else
                            MessageBox.Show("try again");
            }

    }

}

and the seccond messagebox(with the score) is always 1, and i don't know how to increase it in other way. Could you please help me?

Upvotes: 0

Views: 478

Answers (1)

nvoigt
nvoigt

Reputation: 77304

Your variable score is in the scope of the function. That means any time the function is executed, there is a new "score" created, which starts at 0 every time. If you want to keep "score" once the function ends, you need to declare it in an outer scope. On class level for example. Put the declaration of "score" in your class instead of in your function.

// add line here:
private int score = 0;

private void nou_Click(object sender, EventArgs e)
{
   int i, j;
   // remove line here

   for (i = 0; i < 4; i++)
   ...

Upvotes: 2

Related Questions