我正在创建一个随机数猜测游戏,但我遇到了生成器生成相同数字的问题,除非我关闭它并重新打开它。我有“您的号码太小/太大”。这样可行。但是我希望在单击按钮以检查猜测后更改数字。知道什么是错的吗?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Guess_the_number_1
{
public partial class Form1 : Form
{
int randomNumber;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Random random = new Random();
randomNumber = random.Next(0, 10);
}
private void buttonCheckGuess_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(textboxGuess.Text) == randomNumber)
{
MessageBox.Show("Your Guessed Correctly! The Number Is: " + textboxGuess.Text);
}
else if (Convert.ToInt32(textboxGuess.Text) < randomNumber)
{
MessageBox.Show("The Number Is Larger Than: " + textboxGuess.Text);
}
else if (Convert.ToInt32(textboxGuess.Text) > randomNumber)
{
MessageBox.Show("The Number Is Smaller Than: " + textboxGuess.Text);
}
else
{
MessageBox.Show("Your Guessed Incorrectly. The Random Number Is Not: " + textboxGuess.Text);
}
}
}
}