Esempio n. 1
0
        public static void CallCommand(Ant ant, string operation, Controller controller)
        {
            AntLeftRotateCommand  antLeftRotateCommand  = new AntLeftRotateCommand(ant);
            AntRightRotateCommand antRightRotateCommand = new AntRightRotateCommand(ant);
            AntMoveForwardCommand antMoveForwardCommand = new AntMoveForwardCommand(ant);

            foreach (char c in operation)
            {
                if (c == 'L')
                {
                    controller.SetCommand(antLeftRotateCommand);
                    controller.ExecuteCommand();
                }
                else if (c == 'R')
                {
                    controller.SetCommand(antRightRotateCommand);
                    controller.ExecuteCommand();
                }
                else if (c == 'M')
                {
                    controller.SetCommand(antMoveForwardCommand);
                    controller.ExecuteCommand();
                }
            }
        }