| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4239 人关注过本帖, 1 人收藏
标题:做完没有多久的打字游戏
取消只看楼主 加入收藏
恋轩念伊人
Rank: 5Rank: 5
来 自:湖南衡阳
等 级:贵宾
威 望:19
帖 子:643
专家分:0
注 册:2008-2-23
结帖率:100%
收藏(1)
 问题点数:0 回复次数:4 
做完没有多久的打字游戏
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Threading;
namespace playee
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int number=0;
        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            this.Focus();
            foreach (Label lblzimu in this.Controls)
            {
                if (lblzimu.Text.Equals(e.KeyChar.ToString()))
                {
                    this.Controls.Remove(lblzimu);
                    number+=10;                    
                    //MessageBox.Show(rod.ToString());
                }
            }
            lblnumber.Text = number + "";
            //textBox1.Text = number + "";
            //最好用foreach,用for的时候循环过大,机器可能运行不过来
            //for (int i = 0; i < arr.Count; i++)
            //{
            //    if (((Label)arr[i]).Text == e.KeyChar.ToString())
            //    {
            //        this.Controls.Remove((Label)arr[i]);
            //        arr.Remove(arr[i]);
            //        break;
            //    }
            //}
        }

        Label lb = null;
        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Top = -2;
            label2.Top = -2;
            label3.Top = -2;
        }

        char rod=(char) new Random().Next(97, 122);        
        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Top += 10;
            label2.Top += 10;
            label3.Top += 10;
            if (label1.Top >= this.Height - 60)
            {
                timer1.Stop();
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            //this.Controls.Add(lb);
            //lb.Text = rod.ToString();
            //this.label1.ForeColor = System.Drawing.Color.Red;
            //Color[] col = { Red,Yellow,Green,Olive,Orange};
            //int shuzi = new Random().Next(0, 4);
            Col();//改变字体颜色的随便用法
            Chan();
         }

        //随机产生label控件
        ArrayList arr=null;
        public void Chan()
        {
            //this.label1.Font = new System.Drawing.Font("宋体", 20F);
            //this.Controls.Add(lb);
            lb = new Label();
            arr = new ArrayList();
            arr.Add(lb);
            //lb.Top = new Random().Next(10);
            //lb.Left = new Random().Next(455);
            lb.Font = new Font("宋体", 20F);
            lb.ForeColor = Color.Red;
            lb.AutoSize = true;//这个最好要写
            lb.Text = ""+(char)new Random().Next(97,122)+"";
            lb.Location = new Point(new Random().Next(600),new Random().Next(20));
            this.Controls.Add(lb);

            Star st = new Star(lb);
            Thread th = new Thread(new ThreadStart(st.retu));
            th.IsBackground = true;
            th.Start();
        }
        class Star
        {
            Label lbl;
            public Star(Label lbl)
            {
                this.lbl = lbl;
            }
            public void retu()
            {
                while (true)
                {
                    lbl.Top += 10;
                    if (lbl.Top >= 500)
                    {
                        Thread.CurrentThread.Abort();
                        break;
                    }
                    Thread.Sleep(50);
                }
            }
        }

        public void Col()
        {
            int i = new Random().Next(0, 10);
                if (i == 0)
                {
                    this.label1.ForeColor = System.Drawing.Color.Yellow;
                    this.label2.ForeColor = System.Drawing.Color.Yellow;
                    this.label3.ForeColor = System.Drawing.Color.Yellow;
                    //this.lb.ForeColor = System.Drawing.Color.Yellow;
                }
                else if (i == 1)
                {
                    this.label1.ForeColor = System.Drawing.Color.Tomato;
                    this.label2.ForeColor = System.Drawing.Color.Tomato;
                    this.label3.ForeColor = System.Drawing.Color.Tomato;
                    //this.lb.ForeColor = System.Drawing.Color.Tomato;
                }
                else if (i == 2)
                {
                    this.label1.ForeColor = System.Drawing.Color.Orange;
                    this.label3.ForeColor = System.Drawing.Color.Orange;
                    this.label2.ForeColor = System.Drawing.Color.Orange;
                    //this.lb.ForeColor = System.Drawing.Color.Orange;
                }
                else if (i == 3)
                {
                    this.label1.ForeColor = System.Drawing.Color.Green;
                    this.label2.ForeColor = System.Drawing.Color.Green;
                    this.label3.ForeColor = System.Drawing.Color.Green;
                    //this.lb.ForeColor = System.Drawing.Color.Green;
                }
                else if (i == 4)
                {
                    this.label1.ForeColor = System.Drawing.Color.Olive;
                    this.label2.ForeColor = System.Drawing.Color.Olive;
                    this.label3.ForeColor = System.Drawing.Color.Olive;
                    //this.lb.ForeColor = System.Drawing.Color.Olive;
                }
                else if (i == 5)
                {
                    this.label1.ForeColor = System.Drawing.Color.Purple;
                    this.label2.ForeColor = System.Drawing.Color.Purple;
                    this.label3.ForeColor = System.Drawing.Color.Purple;
                    //this.lb.ForeColor = System.Drawing.Color.Purple;
                }
                else if (i == 6)
                {
                    this.label1.ForeColor = System.Drawing.Color.Pink;
                    this.label3.ForeColor = System.Drawing.Color.Pink;
                    this.label2.ForeColor = System.Drawing.Color.Pink;
                    //this.lb.ForeColor = System.Drawing.Color.Pink;
                }
                else if (i == 7)
                {
                    this.label1.ForeColor = System.Drawing.Color.PapayaWhip;
                    this.label2.ForeColor = System.Drawing.Color.PapayaWhip;
                    this.label3.ForeColor = System.Drawing.Color.PapayaWhip;
                    //this.lb.ForeColor = System.Drawing.Color.PapayaWhip;
                }
                else if (i == 8)
                {
                    this.label1.ForeColor = System.Drawing.Color.SeaShell;
                    this.label2.ForeColor = System.Drawing.Color.SeaShell;
                    this.label3.ForeColor = System.Drawing.Color.SeaShell;
                    //this.lb.ForeColor = System.Drawing.Color.SeaShell;
                }
                else if (i ==9)
                {
                    this.label1.ForeColor = System.Drawing.Color.RosyBrown;
                    this.label2.ForeColor = System.Drawing.Color.RosyBrown;
                    this.label3.ForeColor = System.Drawing.Color.RosyBrown;
                    //this.lb.ForeColor = System.Drawing.Color.RosyBrown;
                }
                else if (i == 10)
                {
                    this.label1.ForeColor = System.Drawing.Color.MediumSpringGreen;
                    this.label2.ForeColor = System.Drawing.Color.MediumSpringGreen;
                    this.label3.ForeColor = System.Drawing.Color.MediumSpringGreen;
                    //this.lb.ForeColor = System.Drawing.Color.MediumSpringGreen;
                }
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }
    }
}
        
   
以上的游戏界面没有美观,不是很好看,所以来这里只是各位看看,如果运行的话,大家可能会发现一个问题,那个标签掉的路线总是估算的到,根本不是我想的那样,所以我很想那位告诉我一个很好解决随机数的方法:我做的随机数所产生的路线总的与界面成45度向下移动,相当不够水准。
汗颜啊!!!
搜索更多相关主题的帖子: using System 游戏 打字 public 
2008-03-02 20:45
恋轩念伊人
Rank: 5Rank: 5
来 自:湖南衡阳
等 级:贵宾
威 望:19
帖 子:643
专家分:0
注 册:2008-2-23
收藏
得分:0 
哎,这个打字游戏太逊啦,都没有人来光顾[bc02]

我不是一个随便的人,我随便起来不是人我哦。信不?
2008-03-07 13:04
恋轩念伊人
Rank: 5Rank: 5
来 自:湖南衡阳
等 级:贵宾
威 望:19
帖 子:643
专家分:0
注 册:2008-2-23
收藏
得分:0 
我给你只是主代码,并没有全部复制到这里来。
你可以删除哪个看可以不咯
我是用vs05写的

我不是一个随便的人,我随便起来不是人我哦。信不?
2008-03-09 04:36
恋轩念伊人
Rank: 5Rank: 5
来 自:湖南衡阳
等 级:贵宾
威 望:19
帖 子:643
专家分:0
注 册:2008-2-23
收藏
得分:0 
回复 8# 的帖子
以前没有感觉,那是初学的时候,现在明白这其中的道理

我不是一个随便的人,我随便起来不是人我哦。信不?
2008-03-27 14:10
恋轩念伊人
Rank: 5Rank: 5
来 自:湖南衡阳
等 级:贵宾
威 望:19
帖 子:643
专家分:0
注 册:2008-2-23
收藏
得分:0 
回复 10# 的帖子
以后会这样的!!

我不是一个随便的人,我随便起来不是人我哦。信不?
2008-03-27 16:12
快速回复:做完没有多久的打字游戏
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021771 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved