Beispiel #1
0
        static void Main()
        {
            Console.WriteLine("Hello. To start programm you need to add minimum two dispatchers.");
            FlightEventArgs parameters = new FlightEventArgs();
            Plane           plane      = new Plane();

            while (Plane.CountDispatchers != 2)
            {
                CreateDispatcher(plane);
            }
            Console.Clear();
            while (!parameters.IsPlaneLanded)
            {
                try
                {
                    Menu();
                    var key = Console.ReadKey(true);
                    Console.Clear();
                    if (key.Key == ConsoleKey.UpArrow)
                    {
                        if (parameters.Speed == 0)
                        {
                            throw new Exception(message: "You cant rise up, without acceleration.");
                        }
                        parameters.Higher(key.Modifiers.HasFlag(ConsoleModifiers.Shift));
                        plane.ReportToDispatcher(parameters);
                    }
                    else if (key.Key == ConsoleKey.DownArrow)
                    {
                        if (parameters.Speed == 0 && parameters.Hight == 0)
                        {
                            throw new Exception(message: "You realy want to go underground?");
                        }
                        parameters.Lower(key.Modifiers.HasFlag(ConsoleModifiers.Shift));
                        plane.ReportToDispatcher(parameters);
                    }
                    else if (key.Key == ConsoleKey.RightArrow)
                    {
                        parameters.Faster(key.Modifiers.HasFlag(ConsoleModifiers.Shift));
                        plane.ReportToDispatcher(parameters);
                    }
                    if (key.Key == ConsoleKey.LeftArrow)
                    {
                        parameters.Slower(key.Modifiers.HasFlag(ConsoleModifiers.Shift));
                        plane.ReportToDispatcher(parameters);
                    }
                    else if (parameters.Speed == 1000)
                    {
                        parameters.Landing();
                    }
                    else if (key.Key == ConsoleKey.D)
                    {
                        CreateDispatcher(plane);
                    }
                    else if (key.Key == ConsoleKey.Delete)
                    {
                        DeleteDispatcher(plane);
                    }
                    if (parameters.Speed == 0 && parameters.Hight == 0 && !parameters.Start)
                    {
                        parameters.PlaneLanded();
                    }
                    Console.WriteLine("Press any key to continue.");
                    Console.ReadKey();
                    Console.Clear();
                }
                catch (PlaneCrushException ex)
                {
                    Console.WriteLine($"{ex.Message}\tPress any key.");
                    Console.ReadKey();
                    Console.Clear();
                    Main();
                }
                catch (UnsuitableForFlightsException ex)
                {
                    Console.WriteLine($"{ex.Message}\tPress any key.");
                    Console.ReadKey();
                    Console.Clear();
                    Main();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{ex.Message}\tPress any key.");
                    Console.ReadKey();
                    Console.Clear();
                    Main();
                }
            }
            plane.CountAllPenaltiesPoints();
        }
        /// <summary>
        /// Защищённый виртуальный метод, который вызывает
        /// делегаты сохранённые в событии. Для безопасности потоков создаётся временная копия <temp></temp>
        /// </summary>
        /// <param name="e"></param>
        protected virtual void ChangeIndicators(FlightEventArgs e)
        {
            EventHandler <FlightEventArgs> temp = ChangingIndicators;

            temp?.Invoke(this, e);
        }