[英]How can I increase score?
我想做一個標志測驗。 如果玩家按下按鈕,則會顯示圖像。 然后他必須猜出圖中所示的標志。
如果他猜測分數會增加。
我不知道該怎么做。
我試過了
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,我不知道如何以其他方式增加它。 請你幫助我好嗎?
您的變量分數在函數范圍內。 這意味着每次執行該功能時,都會創建一個新的“分數”,每次都從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++)
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.