平局时加0.5分
本文关键字:5分 平局 | 更新日期: 2023-09-27 18:13:23
我正在制作一款游戏,我需要更改下面的代码,以便在结果碰巧出现平局时分别为正在运行的"playerscodi++;"answers"computerscodi++;"添加0.5。所以它不会像下面演示的那样再次滚动,而是继续播放。我想不明白!会是:
playerScore += 0.5;
computerScore += 0.5;
而不是弹出消息框?
我希望这是有意义的,对不起!谢谢!
private void button5_Click_1(object sender, EventArgs e)
{
playerDice = new Dice();
int playerDiceNo = playerDice.FaceOfDie;
MessageBox.Show("Your roll: " + playerDiceNo);
compDice = new Dice();
int compDiceNo = compDice.FaceOfDie;
MessageBox.Show("Computers roll: " + compDiceNo);
if (compDiceNo == playerDiceNo)
{
MessageBox.Show("Draw - click Roll or Chance");
button5.Enabled = true;
button1.Enabled = true;
}
}
您是正确的,加法赋值运算符(+=
)将为您提供所需的效果。试试这个:
if (compDiceNo == playerDiceNo)
{
computerScore += 0.5;
playerScore += 0.5;
button5.Enabled = true;
button1.Enabled = true;
}
基本上是doing的简写:
computerScore = computerScore + 0.5;
playerScore = playerScore + 0.5;