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);//设置线程休眠时间 [可控制难度];
}
}
C#文字游戏
最新推荐文章于 2023-01-10 19:42:31 发布