Guest User

Untitled

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