//这是入口点
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace KEYGAME
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}//对数据的跟踪类
<pre name="code" class="csharp">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KEYGAME
{
class countStatus
{
public int correct = 0;
public int missed = 0;
public int total = 0;
public float Accuracy = 0;
public void Update(bool correctKey) {
if (correctKey) {
correct++;
Accuracy = ((float)correct) / total;
return;
}
missed++;
Accuracy = ((float)correct) / total;
return;
}
}
}
//窗体程序
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace KEYGAME
{
public partial class Form1 : Form
{
Random random = new Random();
countStatus status = new countStatus();
public Form1() {
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e) {
status.total++;
listBox1.Items.Add((Keys)(random.Next(65, 90)));
if (listBox1.Items.Count > 7) {
listBox1.Items.Clear();
listBox1.Items.Add("GAME OVER");
timer1.Stop();
}
}
private void Form1_Load(object sender, EventArgs e) {
progressBar1.Value = 100;
timer1.Stop();
}
private void btStart_Click(object sender, EventArgs e) {
timer1.Start();
}
private void Form1_KeyDown(object sender, KeyEventArgs e) {
if (listBox1.Items.Contains(e.KeyCode)) {
listBox1.Items.Remove(e.KeyCode);
listBox1.Refresh();
//this part will increse the difficult of the game by putting down the interval
if (timer1.Interval > 400) timer1.Interval -= 10;
if (timer1.Interval > 250) timer1.Interval -= 8;
if (timer1.Interval > 100) timer1.Interval -= 2;
status.Update(true);
} else {
status.Update(false);
}
progressBar1.Value = 800 - timer1.Interval;
labelCorrect.Text = "correct: "+status.correct;
LabelMiss.Text = "missed: "+status.missed;
labelTotal.Text = "total; "+status.total;
labelAccuracy.Text = "Accuracy: "+status.Accuracy;
}} }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/tabe123/article/details/47440129