2021-05-26 21:16:20 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
|
|
|
|
namespace Catch_the_button {
|
|
|
|
|
class Game {
|
|
|
|
|
static internal int points;
|
|
|
|
|
static bool status = false;
|
|
|
|
|
static bool first = true;
|
|
|
|
|
static int miss;
|
|
|
|
|
static Random rng = new Random();
|
|
|
|
|
static Stopwatch stpwch = new Stopwatch();
|
|
|
|
|
static Timer timer;
|
|
|
|
|
static Timer etaUpdater;
|
|
|
|
|
static Timer formResetter;
|
|
|
|
|
static Label pts;
|
|
|
|
|
static Label hp;
|
|
|
|
|
static Panel menu;
|
|
|
|
|
static Label btn;
|
|
|
|
|
static Form frm;
|
|
|
|
|
static Label eta;
|
2021-05-27 10:41:00 +00:00
|
|
|
|
static Label milestone;
|
2021-05-27 09:44:39 +00:00
|
|
|
|
static int delay = 2000;
|
2021-05-27 10:41:00 +00:00
|
|
|
|
const int milestoneCount = 20;
|
|
|
|
|
const int delaydown = 200;
|
2021-05-26 21:16:20 +00:00
|
|
|
|
static internal void Init(Label opts, Label ohp, Panel omenu, Label obutton,
|
2021-05-27 10:41:00 +00:00
|
|
|
|
Form oform, Label oeta, Label omilestone) {
|
2021-05-26 21:16:20 +00:00
|
|
|
|
pts = opts;
|
|
|
|
|
hp = ohp;
|
|
|
|
|
menu = omenu;
|
|
|
|
|
btn = obutton;
|
|
|
|
|
frm = oform;
|
|
|
|
|
eta = oeta;
|
2021-05-27 10:41:00 +00:00
|
|
|
|
milestone = omilestone;
|
2021-05-26 21:16:20 +00:00
|
|
|
|
SetTimers();
|
|
|
|
|
}
|
|
|
|
|
static private void SetTimers() {
|
|
|
|
|
timer = new Timer();
|
|
|
|
|
timer.Interval = delay;
|
|
|
|
|
timer.Tick += Tmr_Tick;
|
|
|
|
|
timer.Enabled = true;
|
|
|
|
|
timer.Stop();
|
|
|
|
|
|
|
|
|
|
etaUpdater = new Timer();
|
|
|
|
|
etaUpdater.Interval = 20;
|
|
|
|
|
etaUpdater.Tick += Updater_Tick;
|
|
|
|
|
etaUpdater.Enabled = true;
|
|
|
|
|
etaUpdater.Stop();
|
|
|
|
|
|
|
|
|
|
formResetter = new Timer();
|
|
|
|
|
formResetter.Interval = 200;
|
|
|
|
|
formResetter.Tick += formResetter_Tick;
|
|
|
|
|
formResetter.Enabled = true;
|
|
|
|
|
formResetter.Stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static private void Tmr_Tick(object sender, EventArgs e) {
|
|
|
|
|
Hit(new System.Timers.Timer());
|
|
|
|
|
}
|
|
|
|
|
static private void Updater_Tick(object sender, EventArgs e) {
|
2021-05-27 09:44:39 +00:00
|
|
|
|
eta.Text = $"New Position in: {(delay - stpwch.ElapsedMilliseconds)}ms/{delay}ms";
|
2021-05-26 21:16:20 +00:00
|
|
|
|
}
|
|
|
|
|
static private void formResetter_Tick(object sender, EventArgs e) {
|
|
|
|
|
frm.BackColor = Color.FromArgb(240, 240, 240);
|
|
|
|
|
formResetter.Stop();
|
|
|
|
|
}
|
|
|
|
|
static internal void Start() { //pressed button start
|
|
|
|
|
points = miss = 0;
|
2021-05-27 09:44:39 +00:00
|
|
|
|
delay = 2000;
|
2021-05-26 21:16:20 +00:00
|
|
|
|
btn.Visible = btn.Enabled = true;
|
|
|
|
|
menu.Visible = menu.Enabled = false;
|
|
|
|
|
btn.Size = new Size(50, 50);
|
|
|
|
|
btn.Location = new Point((frm.Width - btn.Width) / 2, (frm.Height - btn.Height) / 2);
|
|
|
|
|
status = true;
|
|
|
|
|
timer.Interval = delay;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
static void Go() { //first button hit
|
|
|
|
|
timer.Start();
|
|
|
|
|
stpwch.Start();
|
|
|
|
|
etaUpdater.Start();
|
|
|
|
|
newPos();
|
|
|
|
|
}
|
|
|
|
|
static internal void Hit(object obj = null) {
|
|
|
|
|
if (!status) return;
|
|
|
|
|
if (first) {
|
|
|
|
|
Go();
|
|
|
|
|
first = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (stpwch.ElapsedMilliseconds < 500 && !(obj is Form || obj is System.Timers.Timer)) {
|
|
|
|
|
points += 2;
|
2021-05-27 10:41:00 +00:00
|
|
|
|
if (points % milestoneCount == 0 && delay > 400) {
|
|
|
|
|
delay -= delaydown;
|
2021-05-27 09:44:39 +00:00
|
|
|
|
}
|
2021-05-26 21:16:20 +00:00
|
|
|
|
}
|
|
|
|
|
else if (stpwch.ElapsedMilliseconds >= 500 && !(obj is Form || obj is System.Timers.Timer)) {
|
|
|
|
|
points++;
|
2021-05-27 10:41:00 +00:00
|
|
|
|
if (points % milestoneCount == 0 && delay > 400) {
|
|
|
|
|
delay -= delaydown;
|
2021-05-27 09:44:39 +00:00
|
|
|
|
}
|
2021-05-26 21:16:20 +00:00
|
|
|
|
}
|
|
|
|
|
else if (obj is System.Timers.Timer || obj is Form) {
|
|
|
|
|
points--;
|
|
|
|
|
miss++;
|
|
|
|
|
formResetter.Start();
|
|
|
|
|
frm.BackColor = Color.FromArgb(240, 200, 200);
|
|
|
|
|
}
|
|
|
|
|
UpdateText();
|
|
|
|
|
if (miss > 3) {
|
|
|
|
|
Stop();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
stpwch.Restart();
|
|
|
|
|
resetTimer();
|
|
|
|
|
newPos();
|
|
|
|
|
}
|
|
|
|
|
static internal void Stop() {
|
|
|
|
|
stpwch.Stop();
|
|
|
|
|
timer.Stop();
|
|
|
|
|
etaUpdater.Stop();
|
|
|
|
|
first = true;
|
|
|
|
|
status = false;
|
|
|
|
|
|
|
|
|
|
Leaderboard.Write();
|
|
|
|
|
Leaderboard.Output();
|
|
|
|
|
|
|
|
|
|
points = miss = 0;
|
2021-05-27 09:44:39 +00:00
|
|
|
|
delay = 2000;
|
2021-05-26 21:16:20 +00:00
|
|
|
|
UpdateText();
|
|
|
|
|
btn.Visible = btn.Enabled = false;
|
|
|
|
|
menu.Visible = menu.Enabled = true;
|
|
|
|
|
eta.Text = "New Position in: ...";
|
2021-05-27 10:41:00 +00:00
|
|
|
|
milestone.Text = "New Milestone in: ...";
|
2021-05-26 21:16:20 +00:00
|
|
|
|
}
|
|
|
|
|
static private void UpdateText() {
|
|
|
|
|
pts.Text = "Points: " + points;
|
|
|
|
|
hp.Text = "HP: "+(3 - miss).ToString();
|
2021-05-27 10:41:00 +00:00
|
|
|
|
int ml = points + (milestoneCount - (points - milestoneCount * ((points - points % milestoneCount) / milestoneCount)));
|
|
|
|
|
milestone.Text = "Next Milestone in: " + (ml-points);
|
2021-05-26 21:16:20 +00:00
|
|
|
|
}
|
|
|
|
|
static void newPos() {
|
|
|
|
|
btn.Location = new Point(
|
|
|
|
|
rng.Next(frm.ClientSize.Width - btn.Width),
|
|
|
|
|
rng.Next(40, frm.ClientSize.Height - btn.Height));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static private void resetTimer() {
|
|
|
|
|
timer.Stop();
|
2021-05-27 09:44:39 +00:00
|
|
|
|
timer.Interval = delay;
|
2021-05-26 21:16:20 +00:00
|
|
|
|
timer.Start();
|
|
|
|
|
|
|
|
|
|
etaUpdater.Stop();
|
|
|
|
|
etaUpdater.Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|