private void Land() { inFlight = false; int totalPenalty = Dispatchers.Sum(disp => disp.PenaltyPoints) + removedPoints; MessageBox.Show("Penalty points: " + totalPenalty); FrmPlane.GetInstance().Close(); }
public void AnalyzeData(object sender, OnMoveEventArgs e) { if (e.Velocity > 1000) { PenaltyPoints += 100; MessageBox.Show($"Dispatcher {Name}: You have broken the speed limit! Slow down right now!"); } else if (e.InFlight && (e.Velocity == 0 || e.Height == 0)) { if (FrmPlane.GetInstance().lblGoal.Text.Contains("1000")) { FrmPlane.GetInstance().plane.Image = Properties.Resources.boom; throw new Exception("The plane has crashed!"); } else if (e.Velocity == 0 && e.Height == 0) { throw new Exception("You have successfully landed the plane!"); } } if (e.Velocity > 50) { int recommendedHeight = 7 * e.Velocity - weatherCorrection; int diff = Math.Abs(recommendedHeight - e.Height); if (e.InFlight) { if (diff > 300 && diff <= 600) { PenaltyPoints += 25; } else if (diff > 600 && diff <= 1000) { PenaltyPoints += 50; } } if (diff > 1000) { FrmPlane.GetInstance().plane.Image = Properties.Resources.boom; throw new Exception("The plane has crashed!"); } if (PenaltyPoints >= 1000) { throw new Exception("You are unsuitable to fly!"); } FrmPlane.GetInstance().listRecom.Items.Add($"{recommendedHeight} m"); } }
public void Move(PreviewKeyDownEventArgs e) { try { if (Dispatchers.Count >= 2) { PictureBox plane = FrmPlane.GetInstance().plane; switch (e.KeyCode) { case Keys.Right: { if (e.Shift) { Velocity += 100; } Velocity += 50; break; } case Keys.Left: if (Velocity >= 150 && e.Shift) { Velocity -= 150; } else if (Velocity >= 50) { Velocity -= 50; } break; case Keys.Up: if (Velocity > 50) { if (!inFlight) { inFlight = true; MessageBox.Show("The goal is reached!\nNext goal: reach velocity of 1000 km/h"); FrmPlane.GetInstance().lblGoal.Text = "Goal: reach velocity of 1000 km/h"; } if (e.Shift) { Height += 250; plane.Top -= 10; } Height += 250; plane.Top -= 10; plane.Left += Velocity / 50; } break; case Keys.Down: if (Height >= 500 && e.Shift) { Height -= 500; plane.Top += 20; plane.Left += Velocity / 50; } else if (Height >= 250) { Height -= 250; plane.Top += 10; plane.Left += Velocity / 50; } break; case Keys.Escape: FrmPlane.GetInstance().Close(); break; } if (Velocity == 1000 && FrmPlane.GetInstance().lblGoal.Text.Contains("1000")) { MessageBox.Show("The goal is reached!\nFinal goal: land the plane."); FrmPlane.GetInstance().lblGoal.Text = "Goal: land the plane."; } OnMove(this, new OnMoveEventArgs(Velocity, Height, inFlight)); } else { MessageBox.Show("You need at least 2 dispatchers to take off!"); } } catch (Exception ex) { MessageBox.Show("The flight is over. " + ex.Message); Land(); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(FrmPlane.GetInstance()); }
public static FrmPlane GetInstance() { return(instance = instance ?? new FrmPlane()); }