标题:C#打字游戏
只看楼主
ordinary逗比
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-3-15
 问题点数:0 回复次数:2 
C#打字游戏
namespace Desktop_progran7
{
    public partial class Form1 : Form
    {
        Random random = new Random();
        Stats stats = new Stats();

        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            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_KeyDown(object sender, KeyEventArgs e)
        {
            if (listBox1.Items.Contains(e.KeyCode))
            {
                listBox1.Items.Remove(e.KeyCode);
                listBox1.Refresh();
                if (timer1.Interval > 400)
                    timer1.Interval -= 10;
                if (timer1.Interval > 250)
                    timer1.Interval -= 7;
                if (timer1.Interval > 100)
                    timer1.Interval -= 2;
                difficultyProgressBar.Value = 800 - timer1.Interval;

                stats.Update(true);
            }
            else
            {
                stats.Update(false);
            }

            correctLabel.Text = "Correct: " + stats.Correct;
            missedLabel.Text = "Missed: " + stats.Missed;
            totalLabel.Text = "Total: " + stats.Total;
            accuracyLabel.Text = "Accuracy: " + stats.Accuracy + "%";
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}


namespace Desktop_progran7
{
    class Stats
    {
        public int Total = 0;
        public int Missed = 0;
        public int Correct = 0;
        public int Accuracy = 0;

        public void Update(bool correctKey)
        {
            Total++;

            if (!correctKey )
            {
                Missed++;
            }
            else
            {
                Correct++;
            }
            Accuracy = 100 * Correct / (Missed + Correct);
        }
    }
}
搜索更多相关主题的帖子: 打字游戏 private public Random 
2017-03-23 18:41
daluji
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-1-13
得分:0 
有教程就好了
2017-05-20 23:33
MTT
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2017-5-18
得分:0 
有压缩包就好了
2017-05-21 21:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-475426-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.862693 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved