简体   繁体   English

我怎样才能提高分数?

[英]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. 第二个消息框(带分数)总是1,我不知道如何以其他方式增加它。 Could you please help me? 请你帮助我好吗?

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. 这意味着每次执行该功能时,都会创建一个新的“分数”,每次都从0开始。 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++)
   ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM