Visual C#_ Framework.猜数字小游戏

来源:互联网 发布:开票软件打不开没响应 编辑:程序博客网 时间:2024/05/21 12:47

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;

namespace WindowsFormsApplication2{    public partial class Form2 : Form

    {        Random r = new Random();        int count;        int num;        public Form2()        {            InitializeComponent();        }

        private void button2_Click(object sender, EventArgs e)        {            int num2 = Convert.ToInt32(this.textBox1.Text);            if (num2 > num)            {                MessageBox.Show("大了,再猜","提示",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);                count++;            }            else if (num2 < num)            {                MessageBox.Show("小了再猜", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);                count++;            }            else if(num2 == num)            {

                MessageBox.Show("恭喜你猜中了!!一种猜了"+count+"次", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);                count++;            }        }

        private void button1_Click(object sender, EventArgs e)        {            this.num = r.Next(1,100);            count = 0;            this.button2.Enabled=true;        }    }}

0 0
原创粉丝点击