我正在制作一个骰子滚动程序,我们假设有一个"总赚钱"标签框,显示滚轮掷骰子时所赚取的总金额.如果你滚动6你赚600美元,如果你赚5美元你赚500美元等等我可以得到美元价值出现在标签框上但是当我继续滚动时,这个数字将被替换为下一个值而不是总结为例如滚动5然后你赚500美元然后再次滚动你滚1然后它应该显示$ 600 = 500 + 100.
请帮助我使用代码
private void button1_Click(object sender, EventArgs e)
{
int roll1;
Random rand = new Random();
roll1 = rand.Next(6) + 1;
int value = 100;
int sum = (roll1 * value);
totalmoneyLabel.Text = sum.ToString("c");
if (roll1 == 1)
{
diceBox1.Image = drios1_Project2.Properties.Resources._1Die;
}
if (roll1 == 2)
{
diceBox1.Image = drios1_Project2.Properties.Resources._2Die;
}
if (roll1 == 3)
{
diceBox1.Image = drios1_Project2.Properties.Resources._3Die;
}
if (roll1 == 4)
{
diceBox1.Image = drios1_Project2.Properties.Resources._4Die;
}
if (roll1 == 5)
{
diceBox1.Image = drios1_Project2.Properties.Resources._5Die;
}
if (roll1 == 6)
{
diceBox1.Image = drios1_Project2.Properties.Resources._6Die;
}
}
Run Code Online (Sandbox Code Playgroud)
代替
int sum = (roll1 * value);
Run Code Online (Sandbox Code Playgroud)
和
sum = sum + (roll1 * value);
Run Code Online (Sandbox Code Playgroud)