求解释C# 打字小游戏的代码!最好能够帮我弄上注释!
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DaZi
{
public partial class Form1 : Form
{
private int speed;
private int level;
private Random random;
private int right;
private DateTime startTime;
public Form1()
{
InitializeComponent();
level = 1;
speed = 10 * level;
random = new Random();//随机字母
right = 0;
}
private void Initialize(Label label)
{
label.Top = 0;
label.Text = GetRandomCharactor();
int red = random.Next(255);
int green = random.Next(255);
int blue = random.Next(255);
label.ForeColor = Color.FromArgb(red, green, blue);
}
private string GetRandomCharactor()
{
string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return s.Substring(random.Next(s.Length-1), 1);
//int ascii = random.Next(32, 64);
//char c = (char)ascii;
//return c.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
radioButton1.Enabled = false;
radioButton2.Enabled = false;
radioButton3.Enabled = false;
Initialize(label1);
Initialize(label2);
Initialize(label3);
Initialize(label4);
Initialize(label5);
right = 0;
label6.Text = "总分:0";
startTime = DateTime.Now;
}
private void timer1_Tick(object sender, EventArgs e)
{
MoveLabel(label1);
MoveLabel(label2);
MoveLabel(label3);
MoveLabel(label4);
MoveLabel(label5);
TimeSpan timeSpan = DateTime.Now - startTime; //计算移动位置的时间差 //TimeSpan 表示一个时间间隔
if (timeSpan.Seconds >= 30)
{
button2_Click(null, null);
}
}
private void MoveLabel(Label label)
{
label.Top += speed;
if (label.Top >= this.Height)
{
Initialize(label);
}
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
CompareLabel(label1, e.KeyValue);
CompareLabel(label2, e.KeyValue);
CompareLabel(label3, e.KeyValue);
CompareLabel(label4, e.KeyValue);
CompareLabel(label5, e.KeyValue);
}
private void CompareLabel(Label label, int KeyValue)
{
int ascii = (int)Char.Parse(label.Text.ToUpper());
if (KeyValue == ascii)
{
right++;
label6.Text = "总分:" + (right * 10).ToString();
Initialize(label);
}
}
private void radioButton_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
level = 1;
else if (radioButton2.Checked)
level = 2;
else if (radioButton3.Checked)
level = 3;
speed = 10 * level;
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
radioButton1.Enabled = true;
radioButton2.Enabled = true;
radioButton3.Enabled = true;
}
}
}