Exemplo n.º 1
0
        public static Rover Create(int startPositionX, int startPostionY, LandscapeGrid landScapeGrid)
        {
            if (_rover == null)
            {
                _rover = new Rover(startPositionX, startPostionY, landScapeGrid);
            }

            return(_rover);
        }
Exemplo n.º 2
0
        //Constructor with paramenters and default value
        public static LandscapeGrid Create(int minCordinateX = 0, int minCordinateY = 0, int maxCordinateX = 4, int maxCordinateY = 4)
        {
            if (_landscapeGrid == null)
            {
                _landscapeGrid = new LandscapeGrid();
            }

            _landscapeGrid.minCordinateX = minCordinateX;
            _landscapeGrid.minCordinateY = minCordinateY;
            _landscapeGrid.maxCordinateX = maxCordinateX;
            _landscapeGrid.maxCordinateY = maxCordinateY;

            return(_landscapeGrid);
        }
Exemplo n.º 3
0
        public String Execute(string inputCommand)
        {
            //Read and parse command to char array
            char[] parsedCommand = inputCommand.ToUpper().ToCharArray();

            //Creating Rover, command and comman Invoker
            LandscapeGrid  landScapeGrid = LandscapeGrid.Create(0, 0, 4, 4);  //Create Singleton landScape for Rover to walk on
            Rover          rover         = Rover.Create(0, 0, landScapeGrid); //Create Singleton Rover and pass Land Scape Grid to walk over
            Command        command;
            CommandInvoker invoker = new CommandInvoker();                    //Invoker of command pattern to invoke command

            //Rover is on a Walk
            Console.WriteLine("Ahan! Rover is walking now..." + Environment.NewLine);
            for (int i = 0; i < parsedCommand.Length; i++)
            {
                switch (parsedCommand[i])
                {
                case 'R':
                    command = new RotateRightCommand(rover);     //Set appropiate command
                    InvokerExecuteCommand(invoker, command);     //Set and execute command on invoker
                    break;

                case 'L':
                    command = new RotateLeftCommand(rover);    //Set appropiate command
                    InvokerExecuteCommand(invoker, command);   //Set and execute command on invoker
                    break;

                case 'F':
                    command = new MoveForwardCommand(rover);    //Set appropiate command
                    InvokerExecuteCommand(invoker, command);    //Set and execute command on invoker
                    break;
                    //Case 'B': for application extension to move rover to backword
                }
            }

            return(rover.roverCurrentPosition.ToString());
        }
Exemplo n.º 4
0
 private Rover(int x, int y, LandscapeGrid landScapeGrid)
 {
     roverCurrentPosition = new structRoverCurrentPostion(0, 0, landScapeGrid.minCordinateX, landScapeGrid.minCordinateY, landScapeGrid.maxCordinateX, landScapeGrid.maxCordinateY);
 }