Пример #1
0
        private void MoveRobot(MovementCommand move)
        {
            switch (move.MoveDirection)
            {
            case Direction.North:
                Position = new Location(Position.X, Position.Y + 1);
                break;

            case Direction.East:
                Position = new Location(Position.X + 1, Position.Y);
                break;

            case Direction.South:
                Position = new Location(Position.X, Position.Y - 1);
                break;

            case Direction.West:
                Position = new Location(Position.X - 1, Position.Y);
                break;
            }

            Position.Validate(_bottomLeftBound, _topRightBound);

            if (_reporter != null)
            {
                _reporter.RegisterNewPosition(Position);
            }
        }
Пример #2
0
        private MovementCommand ParseMovementCommand(string inputString)
        {
            MovementCommand moveCommand = new MovementCommand();

            string[] movementInputBits = inputString.Split(null);

            if (movementInputBits.Length > 1)
            {
                switch (movementInputBits[0].ToUpper())
                {
                case "N":
                    moveCommand.MoveDirection = Direction.North;
                    break;

                case "S":
                    moveCommand.MoveDirection = Direction.South;
                    break;

                case "E":
                    moveCommand.MoveDirection = Direction.East;
                    break;

                case "W":
                    moveCommand.MoveDirection = Direction.West;
                    break;

                default:
                    moveCommand.MoveDirection = Direction.Unknown;
                    break;
                }

                moveCommand.MoveSteps = int.Parse(movementInputBits[1]);
                if (moveCommand.MoveSteps > MaxNumberSteps)
                {
                    moveCommand.MoveSteps = MaxNumberSteps;
                }
                if (moveCommand.MoveSteps < MinNumberSteps)
                {
                    moveCommand.MoveSteps = MinNumberSteps;
                }
            }

            return(moveCommand);
        }
Пример #3
0
        private void MoveRobot(MovementCommand move)
        {
            switch (move.MoveDirection)
            {
                case Direction.North:
                    Position = new Location(Position.X, Position.Y + 1);
                    break;
                case Direction.East:
                    Position = new Location(Position.X + 1, Position.Y);
                    break;
                case Direction.South:
                    Position = new Location(Position.X, Position.Y - 1);
                    break;
                case Direction.West:
                    Position = new Location(Position.X - 1, Position.Y);
                    break;
            }

            Position.Validate(_bottomLeftBound, _topRightBound);

            if (_reporter != null) _reporter.RegisterNewPosition(Position);
        }
Пример #4
0
        private MovementCommand ParseMovementCommand(string inputString)
        {
            MovementCommand moveCommand = new MovementCommand();

            string[] movementInputBits = inputString.Split(null);

            if (movementInputBits.Length > 1)
            {
                switch (movementInputBits[0].ToUpper())
                {
                    case "N":
                        moveCommand.MoveDirection = Direction.North;
                        break;
                    case "S":
                        moveCommand.MoveDirection = Direction.South;
                        break;
                    case "E":
                        moveCommand.MoveDirection = Direction.East;
                        break;
                    case "W":
                        moveCommand.MoveDirection = Direction.West;
                        break;
                    default:
                        moveCommand.MoveDirection = Direction.Unknown;
                        break;
                }

                moveCommand.MoveSteps = int.Parse(movementInputBits[1]);
                if (moveCommand.MoveSteps > MaxNumberSteps)
                    moveCommand.MoveSteps = MaxNumberSteps;
                if (moveCommand.MoveSteps < MinNumberSteps)
                    moveCommand.MoveSteps = MinNumberSteps;
            }

            return moveCommand;
        }