【发布时间】:2014-04-02 21:56:37
【问题描述】:
我有这个猜数字游戏。用户想出一个数字,计算机就会猜出来。我有这段代码,但问题是,计算机所做的每一次尝试都有随机数重复的机会。我想知道如何创建一个随机列表,计算机将从列表中选择一个数字,如果不正确,我想删除该数字,这样就不会再被选中。我是这个领域的新手,所以我非常感谢任何帮助。
private void btnStartTheGame_Click(object sender, EventArgs e)
{
int guessTheNumber = Convert.ToInt32(txtNumberGuess.Text);
DialogResult dialogResult;
do
{
Random newNumberGenerator = new Random();
number = newNumberGenerator.Next(0, 10);
dialogResult = MessageBox.Show("Is number" + number.ToString() + " you are thinking about?", "Answer the question!", MessageBoxButtons.YesNo);
}while (dialogResult == DialogResult.No);
MessageBox.Show("Congratulation! You guessed the number!!");
}
【问题讨论】: