我有兩個問題,我不知道如何解決。c#擲骰子(我<= maxRolls)
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);
}
}
}}
不要創建一個新的隨機。關於爲什麼閱讀隨機文檔。請搜索真正的問題**「[C#]複製隨機」**找到許多SO重複。 -1以鼓勵使用搜索功能。 – 2012-11-01 01:30:41
好吧,我會那樣做的,謝謝! –
繼續http://stackoverflow.com/questions/13168977/for-loop-dice-roll-and-textbox-text-updating-troubles-c-sharp – lboshuizen