/// <summary> /// Метод для проверки соблюдения рек. высоты /// </summary> /// <param name="sender">Объект самолета</param> /// <param name="e">Пустой</param> public void CalculRenalty(object sender, EventArgs e) { Airplane plane = (Airplane)sender; if (recHeight == 0) { recHeight = 7 * plane.Speed - kpu; // При добавлении диспетчера, рек. высота равна 0 что сразу вызывает исключение } if (plane.Speed > 1000) { countPenalty += 100; Console.WriteLine("Срочно снизьте скорость!!!"); } if (plane.Height == 0 || plane.Speed == 0) { throw new AirplaneException("Самолет разбился!"); } decimal sub = Math.Abs(recHeight - plane.Height); if (sub >= 300 && sub < 600) { countPenalty += 25; } else if (sub >= 600 && sub < 1000) { countPenalty += 50; } else if (sub >= 1000) { throw new AirplaneException("Самолет разбился из за нарушения высоты!"); } if (countPenalty >= 1000) { throw new AirplaneException("Непригоден к полетам!"); } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Диспетчер {name} насчитал штрафных баллов: {countPenalty}!"); }
private static void Main(string[] args) { var plane = new Airplane(); while (true) { Console.WriteLine("1.Начать полет\n2.Добавить диспетчера\n3.Показать результат"); var m = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException()); switch (m) { case 1: Console.Clear(); ConsoleKeyInfo cki; Console.TreatControlCAsInput = true; do { Console.WriteLine( "Нажмите Right: +50km\\h, Left: –50km\\h, Shift-Right: +150km\\h, Shift - Left: –150km\\h"); Console.WriteLine("Нажмите Up: +250 m, Down: –250 m, Shift-Up: +500 m, Shift-Down: –500m)."); Console.WriteLine("Нажмите Escape для выхода"); cki = Console.ReadKey(); // высота if (((cki.Modifiers & ConsoleModifiers.Shift) != 0) && cki.Key == ConsoleKey.UpArrow) { plane.Flying(0, 500); } if (((cki.Modifiers & ConsoleModifiers.Shift) != 0) && cki.Key == ConsoleKey.DownArrow) { plane.Flying(0, -500); } if (((cki.Modifiers & ConsoleModifiers.Shift) == 0) && cki.Key == ConsoleKey.UpArrow) { plane.Flying(0, 250); } if (((cki.Modifiers & ConsoleModifiers.Shift) == 0) && cki.Key == ConsoleKey.DownArrow) { plane.Flying(0, -250); } // скорость if (((cki.Modifiers & ConsoleModifiers.Shift) != 0) && cki.Key == ConsoleKey.RightArrow) { plane.Flying(150, 0); } if (((cki.Modifiers & ConsoleModifiers.Shift) != 0) && cki.Key == ConsoleKey.LeftArrow) { plane.Flying(-150, 0); } if (((cki.Modifiers & ConsoleModifiers.Shift) == 0) && cki.Key == ConsoleKey.RightArrow) { plane.Flying(50, 0); } if (((cki.Modifiers & ConsoleModifiers.Shift) == 0) && cki.Key == ConsoleKey.LeftArrow) { plane.Flying(-50, 0); } } while (cki.Key != ConsoleKey.Escape); break; case 2: Console.WriteLine("Введите имя диспетчера: "); plane.SetDispatcher(Console.ReadLine()); break; case 3: Console.Clear(); try { if (plane.GetPenPoint() > 0) { Console.WriteLine($"Штафные очки: \t {plane.GetPenPoint()}"); } else { throw new Exception("Нет штрафных очков!"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; } } }