我基本上想知道如何我可以增加Player.SetPoints();
1每次循環。我在我的課public void SetPoints(int p) { points = p; }
中得到了這個,只是認爲值得一提。到目前爲止,我得到這個工作的唯一方法是使用Player.SetPoints(+1);
,但只將1放到記分牌上,不再增加。對不起,如果我不夠清楚,我對編程很陌生。這是我的代碼示例,因此您可能會更多地瞭解它,我正在將tic tac toe遊戲作爲學校的作業。公共無效詮釋每增加1循環(初學者)
if (Btn1.Text != "" && Btn2.Text != "" && Btn3.Text != "")
{
if (Btn1.Text == Btn2.Text && Btn1.Text == Btn3.Text)
{
Btn1.BackColor = Color.Green;
Btn1.ForeColor = Color.White;
Btn2.BackColor = Color.Green;
Btn2.ForeColor = Color.White;
Btn3.BackColor = Color.Green;
Btn3.ForeColor = Color.White;
if (Btn1.Text == "X")
{
MessageBox.Show(lblpl1.Text + " Has Won!");
Player1.SetPoints(+0);
playerscore1.Text = Player1.GetPoints().ToString();
}
else
{
MessageBox.Show(lblpl2.Text + " Has Won!");
Player2.SetPoints(+0);
playerscore2.Text = Player2.GetPoints().ToString();
}
click1++;
click2++;
click3++;
click4++;
click5++;
click6++;
click7++;
click8++;
click9++;
restartbtn.Visible = true;
}
}
進行此更改 公共無效設定值(INT P){點+ = P; } 並通過SetPoint(); –
Reddy