using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 猜数字
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Box1_TextChanged(object sender, EventArgs e)
{
}
private void btn_Click(object sender, EventArgs e)
{
int rndint = 50;
int n=0;
while (true)
{
if (Convert.ToInt32(Box1.Text) > rndint)
{
Label3.Text = ("第" + n + "次,大了");
n++;
return;
}
else if (Convert.ToInt32(Box1.Text) < rndint)
{
Label3.Text = ("第" + n + "次,小了");
n++;
return;
}
else if (Convert.ToInt32(Box1.Text) == rndint)
{
Label3.Text = ("恭喜你,猜中了!共尝试了" + n + "次");
break;
}
}
DialogResult result;
result = MessageBox.Show("再玩一次?","猜数字小游戏", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
return;
}
else
{
Application.Exit();
}
}
}
}