Example #1
0
        /// <summary>
        /// Метод меняет состояние самолёта
        /// </summary>
        /// <param name="plane">Самолёт</param>
        /// <param name="receiver">Исполнитель команд</param>
        /// <returns></returns>
        private static int PlaneControl(Airplane plane, Invoker receiver)
        {
            Console.WriteLine("Что делать самолёту? ");
            int a = 1;

            try
            {
                a = Convert.ToInt32(Console.ReadLine());
                if (a != 1 && a != 2 && a != 3 && a != 4)
                {
                    throw new Exception("Неверная команда");
                }
            }
            catch (FormatException)
            {
                Console.WriteLine("Введите команду правильно");
                return(0);
            }
            catch (Exception)
            {
                Console.WriteLine("Такой команды нет");
                return(0);
            }

            switch (a)
            {
            case 1:
            {
                receiver.Command = new TakeOff(plane);
                receiver.Run();
            }
                ; break;

            case 2:
            {
                receiver.Command = new Landing(plane);
                receiver.Run();
            }
                ; break;

            case 3:
                receiver.Undo();
                ; break;
            }
            Console.WriteLine(plane.State);
            return(a);
        }
Example #2
0
        static void Main(string[] args)
        {
            Invoker         invoker  = new Invoker();
            Receiver        receiver = new Receiver();
            ConcreteCommand command  = new ConcreteCommand(receiver);

            invoker.SetCommand(command);
            invoker.Run();
        }
Example #3
0
        static void Main(string[] args)
        {
            Robot   robot   = new Robot();
            Invoker invoker = new Invoker();

            invoker.SetCommand(new MoveForvardCommand(robot, 3));
            invoker.SetCommand(new RotateCommand(robot, 25));
            invoker.SetCommand(new HandUpCommand(robot, 10));
            invoker.Run();
            invoker.Cancel(3);
        }
Example #4
0
 private void RunCommand(Core.Command cmd)
 {
     invoker.SetCommand(cmd);
     invoker.Run();
 }