Beispiel #1
0
        /// <summary>
        /// SpinRight to change the direction of Rover based on input of Controller.
        /// Skips the action of controller if it finds another rover for the action.
        /// </summary>
        public void spinRight()
        {
            char currentDirection = getDirection();

            switch (currentDirection)
            {
            case 'N':
                if (!(MarsHelper.checkCollision(_xcoord, _ycoord, 'E')))
                {
                    setDirection('E');
                }
                break;

            case 'W':
                if (!(MarsHelper.checkCollision(_xcoord, _ycoord, 'N')))
                {
                    setDirection('N');
                }
                break;

            case 'S':
                if (!(MarsHelper.checkCollision(_xcoord, _ycoord, 'W')))
                {
                    setDirection('W');
                }
                break;

            case 'E':
                if (!(MarsHelper.checkCollision(_xcoord, _ycoord, 'S')))
                {
                    setDirection('S');
                }
                break;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Entry point of program
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            MarsHelper.readFromfile(args);
            List <string> printRovers = getFinalCoords(RoverQueue, ControllerQueue);

            foreach (string s in printRovers)
            {
                Console.WriteLine(s);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Advance method to change the co-ordinates based on controller input.
        /// Skips the action of controller if it finds another rover for the action,
        /// or crosses the boundary limits.
        /// </summary>
        public void advance()
        {
            char currentDirection = getDirection();

            switch (currentDirection)
            {
            case 'N':
                if ((_ycoord + 1 <= Plateau.getMaxy()) && (_ycoord + 1 >= 0) && (!(MarsHelper.checkCollision(_xcoord, _ycoord + 1, _direction))))
                {
                    _ycoord = _ycoord + 1;
                }

                break;

            case 'W':
                if ((_xcoord - 1 <= Plateau.getMaxx()) && (_xcoord - 1 >= 0) && (!(MarsHelper.checkCollision(_xcoord - 1, _ycoord, _direction))))
                {
                    _xcoord = _xcoord - 1;
                }
                break;

            case 'E':
                if ((_xcoord + 1 <= Plateau.getMaxx()) && (_xcoord + 1 >= 0) && (!(MarsHelper.checkCollision(_xcoord + 1, _ycoord, _direction))))
                {
                    _xcoord = _xcoord + 1;
                }
                break;

            case 'S':
                if ((_ycoord - 1 <= Plateau.getMaxy()) && (_ycoord - 1 >= 0) && (!(MarsHelper.checkCollision(_xcoord, _ycoord - 1, _direction))))
                {
                    _ycoord = _ycoord - 1;
                }
                break;
            }
        }