一个简单的c#打字游戏。

//这是入口点
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;

        }
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-07-29 21:48:16

一个简单的c#打字游戏。的相关文章

一个简单的抽奖转盘游戏

在一个项目中要做一个游戏,在这个过程中做了一个简单的9宫格抽奖游戏.大体思路是,点击开始按钮,游戏开始.由一个逐步递增参数 drawStep 来控制格子的背景颜色的改变,游戏停止的位置参数 stopPosition 由随机函数生成,以此来控制格子停止的位置.游戏转动一圈是8个格子,5圈就是40.easeTime参数模拟格子转动的缓步启动和缓步停止. <!doctype html> <html> <head> <meta charset="gbk"

简单的Java打字游戏

原文:简单的Java打字游戏 源代码下载地址:http://www.zuidaima.com/share/1586973185674240.htm 仅供参考,很简单. swing实现 版权声明:本文为博主原创文章,未经博主允许不得转载.

C++编写的一个简单的猜数字游戏源码

将开发过程比较重要的一些内容段做个记录,下面内容段是关于C++编写的一个简单的猜数字游戏的内容. #include <iostream> #include <string> #include <cstdlib> #include <cctype> #include <ctime> #include <conio.h> using namespace std; int main () { int wins = 0; int losses

用C写一个简单的推箱子游戏(一)

我现在在读大二,我们有一门课程叫<操作系统>,课程考查要求我们可以写一段程序或者写Windows.iOS.Mac的发展历程.后面我结合网上的资料参考,就想用自己之前简单学过的C写一关的推箱子小程序. 这一程序主要用到了C语言中的二维数组,头文件#include<conio.h>(因为要调用getch()函数以记录输入内容),switch函数等. 一.     功能概述 a)   游戏规则概述 玩家通过键盘输入W.S.A.D四键或者“↑”.“↓”.“←”.“→”四个方向键推动箱子,而

用MFC完成一个简单的猜数字游戏: 输入的四位数中,位置和数字都正确为A,数字相同而位置不同的为B。

最近学习了MFC一些比较基础的知识,所以打算通过做一个简单的数字游戏来理解MFC的流程并进一步熟悉其操作. 在这里,我做了一个猜数字的小游戏.第一步当然是设计主界面,先给大家展示一下游戏界面: 主界面: 从这个主界面可以看到,它包含标题,菜单栏,工具栏. 标题是给人一个认识,这是什么游戏,标题设置为:“猜数游戏”: 而菜单栏和工具栏才是游戏的核心,它要保证能够完成游戏的基本功能. 菜单栏和工具栏是对应的,包含了”start“,"help","restart"这三个菜

使用Unity3D的设计思想实现一个简单的C#赛车游戏场景

最近看了看一个C#游戏开发的公开课,在该公开课中使用面向对象思想与Unity3D游戏开发思想结合的方式,对一个简单的赛车游戏场景进行了实现.原本在C#中很方便地就可以完成的一个小场景,使用Unity3D的设计思想(即一切游戏对象皆空对象,拖拽组件才使其具有了活力)来实现却需要花费大量时间与精力,究竟它神奇在什么地方?本文通过实现这个小例子来看看. 一.空对象与组件 在Unity3D最常见的就是GameObject,而一个GameObject被实例化后确啥特性与行为都没有,只有当我们往其中拖拽了一

一个简单的三子棋游戏(c语言实现)

题目是:在一个3*3大小的矩阵中下棋一方有连续三个子便获胜 代码如下: #include<stdio.h> #include<stdlib.h> #include<time.h>               char arr[3][3] = { 0 };            //直接定义外部变量所有的函数可以直接使用    因为考虑到棋盘大小是固定的 int size = 9;                   //棋盘大小固定  每下一个子都会使可以下子的容量-1

做一个简单的贪吃蛇游戏

这是一个贪吃蛇游戏,你可以忽略他的外表,好了,先上html代码 <style type="text/css"> * {margin: 0;padding: 0;} #container {width: 1000px;height: 550px;border: 1px solid #000;margin: 0 auto;} #container #ground {width: 1000px;height: 500px;background-color:#eeeeee;posi

shell脚本写出一个简单的猜价格游戏

[[email protected] ~]# vim game.sh #!/bin/bash a=$(expr ${RANDOM} % 1000) #$RANDOM是一个环境变量,每次都会输出一个不一样的数,并且小于2的16次方 count=0 echo "这个商品的价格是(0-999)元之间,猜猜具体价格?" while true do let count++ read -p " 请输入您猜到的具体价格,并按Enter键确认:" b if [ $b -eq $a