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 Get_Rhythm { public partial class Form1 : Form { public static List allNotes; public static int PERFECT_THRESHOLD = 20; public static int MISS_THRESHOLD = 150; public static int LABEL_REFRESH = 1500; public static uint GOAL_X = 200; public static uint TOP_Y; public static uint BOTTOM_Y; public static uint R = 30; public static int X_VELOCITY = 5; public static Random rng; public static int streak = 0; public static System.Windows.Forms.Timer moveTimer; public static System.Windows.Forms.Timer topLabelTimer; public static System.Windows.Forms.Timer bottomLabelTimer; public static System.Windows.Forms.Timer createNotes; public abstract class Note { protected int X_START; protected Boolean top; public Note(int _X, Boolean _top) { X_START = _X; top = _top; } public int X => X_START; public Boolean Top => top; public abstract void GoDrawYourself(Graphics g); public abstract void Move(); } public class Single : Note { public Single(int _X, Boolean _top) : base(_X, _top) { } public override void GoDrawYourself(Graphics g) { using (Brush myBrush = new SolidBrush(Color.Blue)) { if (top) g.FillCircle(myBrush, X_START, TOP_Y, R); else g.FillCircle(myBrush, X_START, BOTTOM_Y, R); } } public override void Move() { X_START -= X_VELOCITY; } } public Form1() { InitializeComponent(); TopScoreLabel.Text = ""; BottomScoreLabel.Text = ""; StreakScoreLabel.Text = ""; allNotes = new List(); rng = new Random(); //allNotes.Add(new Single(Canvas.Width, true)); //allNotes.Add(new Single(Canvas.Width, false)); TOP_Y = (uint)(Canvas.Height / 3); BOTTOM_Y = (uint)(2 * Canvas.Height / 3); moveTimer = new System.Windows.Forms.Timer(); moveTimer.Interval = 17; // 1000 / 60 ~= 17 moveTimer.Tick += new EventHandler(AdvanceNotes); moveTimer.Enabled = true; topLabelTimer = new System.Windows.Forms.Timer(); topLabelTimer.Interval = LABEL_REFRESH; topLabelTimer.Tick += new EventHandler(RemoveTopLabel); bottomLabelTimer = new System.Windows.Forms.Timer(); bottomLabelTimer.Interval = LABEL_REFRESH; bottomLabelTimer.Tick += new EventHandler(RemoveBottomLabel); // createNotes createNotes = new System.Windows.Forms.Timer(); createNotes.Interval = 2000; // 1000 / 60 ~= 17 createNotes.Tick += new EventHandler(AddAnotherNote); createNotes.Enabled = true; } public void AddAnotherNote(object sender, EventArgs args) { if (rng.Next(2) == 0) allNotes.Add(new Single(Canvas.Width, true)); else allNotes.Add(new Single(Canvas.Width, false)); } public void RemoveTopLabel(object sender, EventArgs args) { TopScoreLabel.Text = ""; topLabelTimer.Enabled = false; } public void RemoveBottomLabel(object sender, EventArgs args) { BottomScoreLabel.Text = ""; bottomLabelTimer.Enabled = false; } public void AdvanceNotes(object sender, EventArgs args) { foreach (Note i in allNotes.ToList()) { i.Move(); if (i.X < MISS_THRESHOLD) { allNotes.Remove(i); StreakScoreLabel.Text = ""; streak = 0; if (i.Top) { TopScoreLabel.Text = "Miss!!"; topLabelTimer.Enabled = true; } else { BottomScoreLabel.Text = "Miss!!"; bottomLabelTimer.Enabled = true; } } } Canvas.Refresh(); } public void DrawTheScale(Graphics g) { using (Pen myPen = new Pen(Color.White)) { g.DrawLine(myPen, GOAL_X, 0, GOAL_X, Canvas.Height); g.DrawLine(myPen, 0, TOP_Y, Canvas.Width, TOP_Y); g.DrawLine(myPen, 0, BOTTOM_Y, Canvas.Width, BOTTOM_Y); } } private void Canvas_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; DrawTheScale(g); foreach (Note i in allNotes) { i.GoDrawYourself(g); } } private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.S) // Clear a Note from the top bar { if (allNotes[0].Top) { if (Math.Abs(GOAL_X - allNotes[0].X) < PERFECT_THRESHOLD) { allNotes.RemoveAt(0); TopScoreLabel.Text = "Perfect!"; topLabelTimer.Enabled = true; streak++; StreakScoreLabel.Text = "x" + streak; } } } else if (e.KeyCode == Keys.K) // Clear a Note from the bottom bar { if (!allNotes[0].Top) { if (Math.Abs(GOAL_X - allNotes[0].X) < PERFECT_THRESHOLD) { allNotes.RemoveAt(0); BottomScoreLabel.Text = "Perfect!"; bottomLabelTimer.Enabled = true; streak++; StreakScoreLabel.Text = "x" + streak; } } } } } public static class GraphicsExtensions { public static void DrawCircle(this Graphics g, Pen pen, float centerX, float centerY, float radius) { g.DrawEllipse(pen, centerX - radius, centerY - radius, radius + radius, radius + radius); } public static void FillCircle(this Graphics g, Brush brush, float centerX, float centerY, float radius) { g.FillEllipse(brush, centerX - radius, centerY - radius, radius + radius, radius + radius); } } }