注册 登录
编程论坛 ASP技术论坛

c#中的移动应用开发 猜字母游戏

qq1159924411 发布于 2012-03-01 19:53, 485 次点击
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DeviceApplication1
{
    public partial class Form1 : Form
    {
        public int mj;
        public int nj;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label3.Text = " ";
            label4.Text = " ";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label3.Text = "";
            label4.Text = "";
            textBox1.Text = "";
            textBox2.Text = "";

            Random r = new Random();
            int a = r.Next(97,122);
            textBox1.Text = Convert.ToString ((char)a);
            textBox2.Focus();
        mj = 60;
            label3.Text = "开始计时" + mj.ToString() + "秒";
            timer1.Enabled = true;
            nj = 0;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("初始字母为:"+textBox1 .Text );
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            textBox2.Text = Convert.ToString(e.KeyChar);
            nj++;
            int a = Convert.ToChar (textBox1 .Text);
            int c=(int) a;
            int b = (int)e.KeyChar ;
            if (a > b)
                label4.Text = "太小了!已经" + nj + "秒";
            else if (a < b)
                label4.Text = "太大了!已经" + nj + "秒";

            else
                label4.Text = " 恭喜你猜对了!你共用了" +nj+"秒";

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
                mj--;
                if (mj == 0)
                {
                    label3.Text = "时间到";

                    timer1.Enabled = false;
                }
                else
                    label3.Text = "开始计时" + mj.ToString() + "秒";

        }
    }
}
我在我textbox中输入我猜的数字,会出现两个这个数
0 回复
1