3

我正在制作游戏,我需要更改下面的代码,以便将 0.5 添加到正在运行的“playerScore++;”中 和“computerScore++;” 分别,当结果碰巧出现平局时。因此,如下所示,它不会再次滚动,而是继续播放。我想不通!会不会是:

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

        }
4

1 回答 1

2

你是对的,加法赋值运算符+=)会给你想要的效果。尝试这个:

if (compDiceNo == playerDiceNo)
{
    computerScore += 0.5;
    playerScore += 0.5;
    button5.Enabled = true;
    button1.Enabled = true;
}

它基本上是做的简写:

computerScore = computerScore + 0.5;
playerScore = playerScore + 0.5;
于 2013-05-14T14:29:50.393 回答