| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4239 人关注过本帖, 1 人收藏
标题:做完没有多久的打字游戏
只看楼主 加入收藏
恋轩念伊人
Rank: 5Rank: 5
来 自:湖南衡阳
等 级:贵宾
威 望:19
帖 子:643
专家分:0
注 册:2008-2-23
结帖率:100%
收藏(1)
 问题点数:0 回复次数:13 
做完没有多久的打字游戏
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: 4
来 自:福建平和
等 级:贵宾
威 望:13
帖 子:1910
专家分:0
注 册:2007-5-11
收藏
得分:0 
我来看看~

我清高和我骄傲的倔强,在风中大声的唱:我不听,我不听~~做我自己最特别,呼呼~~啦啦~~~
我的博客园地址: [url]http://[/url]
2008-03-07 14:26
nodeadbird520
Rank: 1
来 自:湖南永州
等 级:新手上路
帖 子:25
专家分:0
注 册:2008-3-7
收藏
得分:0 
怎么我运行你的程序,总提示有错误,public partial class Form1 : Form这行,说partial有错,
不知道怎么改,所以想请教下.

吃得苦,耐得烦,不怕死,霸得蛮。
2008-03-08 07:35
恋轩念伊人
Rank: 5Rank: 5
来 自:湖南衡阳
等 级:贵宾
威 望:19
帖 子:643
专家分:0
注 册:2008-2-23
收藏
得分:0 
我给你只是主代码,并没有全部复制到这里来。
你可以删除哪个看可以不咯
我是用vs05写的

我不是一个随便的人,我随便起来不是人我哦。信不?
2008-03-09 04:36
cjlgood
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-8-28
收藏
得分:0 
初来乍到
学习新知识啊
2008-03-16 11:13
hoodlum1980
Rank: 2
来 自:浙江大学
等 级:论坛游民
威 望:2
帖 子:289
专家分:23
注 册:2008-2-24
收藏
得分:0 
[bo]以下是引用 [un]nodeadbird520[/un] 在 2008-3-8 07:35 的发言:[/bo]

怎么我运行你的程序,总提示有错误,public partial class Form1 : Form这行,说partial有错,
不知道怎么改,所以想请教下.

在vs2005开始把用户逻辑和窗体设计器代码分离到不同文件之中了,所以多了个关键字partial,你把这个关键字去掉即可。
2008-03-16 22:19
hoodlum1980
Rank: 2
来 自:浙江大学
等 级:论坛游民
威 望:2
帖 子:289
专家分:23
注 册:2008-2-24
收藏
得分:0 
总体来说数据都放到控件属性里了因此效率较低。真正实际应用时不可能这样做。
2008-03-16 22:23
恋轩念伊人
Rank: 5Rank: 5
来 自:湖南衡阳
等 级:贵宾
威 望:19
帖 子:643
专家分:0
注 册:2008-2-23
收藏
得分:0 
回复 8# 的帖子
以前没有感觉,那是初学的时候,现在明白这其中的道理

我不是一个随便的人,我随便起来不是人我哦。信不?
2008-03-27 14:10
andey
Rank: 2
等 级:新手上路
威 望:4
帖 子:938
专家分:0
注 册:2007-7-18
收藏
得分:0 
建议搞成附件...
代码看着眼晕

msdn == 葵花宝典!!!
QQ:122768959
2008-03-27 15:34
快速回复:做完没有多久的打字游戏
数据加载中...
 
   



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

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