Guest User

Untitled

a guest
Feb 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace Hit_the_keys
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         Random random = new Random();
  15.         Stats stats = new Stats();
  16.  
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void timer1_Tick(object sender, EventArgs e)
  23.         {
  24.             // Add a random key to the ListBox
  25.             listBox1.Items.Add((Keys)random.Next(65, 90));
  26.             if (listBox1.Items.Count > 7)
  27.             {
  28.                 listBox1.Items.Clear();
  29.                 listBox1.Items.Add("Game over");
  30.                 timer1.Stop();
  31.             }
  32.         }
  33.  
  34.         private void Form1_KeyDown(object sender, KeyEventArgs e)
  35.         {
  36.             // If the user pressed a key that's in the ListBox, remove it
  37.             // and then make the game a little faster
  38.             if(listBox1.Items.Contains(e.KeyCode))
  39.             {
  40.                 listBox1.Items.Remove(e.KeyCode);
  41.                 listBox1.Refresh();
  42.                 if (timer1.Interval > 400)
  43.                     timer1.Interval -= 10;
  44.                 if (timer1.Interval > 250)
  45.                     timer1.Interval -= 7;
  46.                 if (timer1.Interval > 100)
  47.                     timer1.Interval -= 2;
  48.                 difficultyProgressBar.Value = 800 - timer1.Interval;
  49.  
  50.                 // The user pressed a correct key, so update the Stats object
  51.                 // by calling its Update() method with the argument true
  52.                 stats.Update(true);
  53.             }
  54.             else
  55.             {
  56.                 // The user pressed an incorrect key, so update the Stats object
  57.                 // by calling its Update() method with the argument false
  58.                 stats.Update(false);
  59.             }
  60.  
  61.             // Update the labels on the StatusStrip
  62.             correctLabel.Text = "Correct: " + stats.Correct;
  63.             missedLabel.Text = "Missed: " + stats.Missed;
  64.             totalLabel.Text = "Total: " + stats.Total;
  65.             accuracyLabel.Text = "Accuracy: " + stats.Accuracy + "%";
  66.         }
  67.  
  68.         private void Form1_Load(object sender, EventArgs e)
  69.         {
  70.  
  71.         }
  72.     }
  73. }
Add Comment
Please, Sign In to add comment