我有两个问题,我不知道如何解决。
diceThrow()
应该随机掷骰子并多次得出1-6的答案,但只能得出一个1-6的答案,而且只能这样做。即(6、6、6、6、6、6等)
而对于rollDice()
,我不确定我是否只是定义不好“ i
”或maxRolls
,但应该是,i > maxRolls
程序应该结束并重置。
非常感谢有关如何解决其中任何一个问题的任何建议,谢谢!
//somewhere else in code
int maxRolls = RollsNumber();
int throwresult = diceThrow();
int i;
//*******************************
private void rollButton_Click(object sender, EventArgs e)
{
rollDice();
wagerTextBox.Text = null;
wagerTextBox.Text = scoreTextBox.Text;
diceThrow();
MessageBox.Show(Convert.ToString(throwresult));
if (maxRolls < i)
{
MessageBox.Show("You got too greedy.");
//reset the form
}
}
// Decides the maximum number of rolls before the player loses
static public int RollsNumber()
{
Random rolls = new Random();
return rolls.Next(1, 10);
}
// Throws the dice
static public int diceThrow()
{
Random dice = new Random();
return dice.Next(1, 7);
}
private void rollDice()
{
for (i = 0; i <= maxRolls; i++)
{
int wager = Convert.ToInt32(wagerTextBox.Text);
int score = wager * 100;
scoreTextBox.Text = Convert.ToString(score);
}
}
} }