C#文字游戏

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
private Label labwords;//定义个Lable;
Thread th = null;//定义一个线程;
string[] words ={“A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”, “I”, “J”, “K”, “L”, “M”, “N”, “O”, “P”, “Q”, “R”, “S”, “T”, “U”, “V”, “W”, “X”, “Y”, “Z”};
//先把26个字母定义为一个数组;
int count = 0;//得分计数器;
int H_E = 200;//线程休眠时间;
private void MainMethod()
{
if (labwords == null)//如果Lable为空;
{
Random R = new Random();//随机数;
labwords = new System.Windows.Forms.Label();//实例一个Lable;
labwords.Name = words[R.Next(26)];//这个Label的名字为26个字母中随机一个;
labwords.Text = labwords.Name;//这个Lable标签的内容就等于他的名字,即这个字母;
labwords.Location = new System.Drawing.Point(R.Next(20, this.Size.Width - labwords.Size.Width), 0);
//Drawing方法实例一个Lable; 并且随机Lable出现的位置在窗口之内;
this.Controls.Add(labwords);//把Lable添加到窗体;
th = new Thread(new ThreadStart(Method));//实例线程;
th.Start();//线程开始运作;
}
}
private void Method()
{
while (true)//无限循环;
{
labshow();
Thread.Sleep(H_E);//设置线程休眠时间 [可控制难度];
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值