我怎样才能提高分数?

时间:2013-11-16 15:29:36

标签: c#

我想做一个标志测验。如果玩家按下按钮,则会显示图像。然后他必须猜出图中所示的标志。

如果他猜测分数会增加。

我不知道该怎么做。

我试过

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");
            }

    }

}

和第二个消息框(带分数)总是1,我不知道如何以其他方式增加它。你能帮我吗?

1 个答案:

答案 0 :(得分:2)

您的变量分数在函数范围内。这意味着每次执行该功能时,都会创建一个新的“分数”,每次都从0开始。如果要在函数结束后保持“得分”,则需要在外部范围内声明它。例如,在班级。将“得分”声明放在您的班级而不是您的职能中。

// 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++)
   ...
相关问题