private void MakeRobotMove(CommandToMove step)
        {
            switch (step.directionToMove)
            {
            case Direction.North:
                location = new Location(location.x, location.y + 1);
                break;

            case Direction.East:
                location = new Location(location.x + 1, location.y);
                break;

            case Direction.South:
                location = new Location(location.x, location.y - 1);
                break;

            case Direction.West:
                location = new Location(location.x - 1, location.y);
                break;
            }

            // make sure we still in the room
            location.Validate(bottomLeftLocation, topRightLocation);

            if (reporter != null)
            {
                reporter.RegisterNewPosition(location);
            }
        }
Пример #2
0
        private CommandToMove parsingCommand(string inputCoordinates)
        {
            CommandToMove commandToMove = new CommandToMove();

            string[] movementsArray = inputCoordinates.Split(null);

            if (movementsArray.Length > 1)
            {
                switch (movementsArray[0].ToUpper())
                {
                case "N":
                case "T":
                    commandToMove.directionToMove = Direction.North;
                    break;

                case "S":
                case "B":
                    commandToMove.directionToMove = Direction.South;
                    break;

                case "E":
                case "R":
                    commandToMove.directionToMove = Direction.East;
                    break;

                case "W":
                case "L":
                    commandToMove.directionToMove = Direction.West;
                    break;

                default:
                    commandToMove.directionToMove = Direction.Unknown;
                    break;
                }

                commandToMove.numberOfSteps = int.Parse(movementsArray[1]);

                if (commandToMove.numberOfSteps > MAX_NUMBER_OF_STEPS - 1)
                {
                    commandToMove.numberOfSteps = MAX_NUMBER_OF_STEPS;
                }
                if (commandToMove.numberOfSteps < MIN_NUMBER_OF_STEPS + 1)
                {
                    commandToMove.numberOfSteps = MIN_NUMBER_OF_STEPS;
                }
            }

            return(commandToMove);
        }