目前,点击按钮后,骰子图像会发生变化"点击滚动模具"。
我还想更新标签"播放器的总数"当我点击"点击滚动骰子"底部。
我如何实现这一目标?
private void rollDieBotton_Click(object sender, EventArgs e)
{
RollDice();
}
private void RollDice()
{
for (int i = 0; i < dice.Length; i++)
dice[i] = roll.Next(1, 6);
dicePictureBox.Image = diceImages[dice[0]];
}
private void PigForm_Load(object sender, EventArgs e)
{
diceImages = new Image[6];
diceImages[0] = Properties.Resources.Alea_1;
diceImages[1] = Properties.Resources.Alea_2;
diceImages[2] = Properties.Resources.Alea_3;
diceImages[3] = Properties.Resources.Alea_4;
diceImages[4] = Properties.Resources.Alea_5;
diceImages[5] = Properties.Resources.Alea_6;
dice = new int[1] { 0 };
roll = new Random();
}
答案 0 :(得分:1)
您可以使用dice
值对滚动进行求和,而不是仅存储当前滚动并执行以下操作:
private void RollDice()
{
for (int i = 0; i < dice.Length; i++)
{
var currenRoll = roll.Next(1, 6);
dice[i] += currentRoll;
dicePictureBox.Image = diceImages[currentRoll];
playerTotalLabel.Text = String.Format("Total: {0}", dice[i]);
}
}