コード例 #1
0
        public List <IRover> Execute(string[] commandList)
        {
            List <IRover> rovers = new List <IRover>();
            ILand         land   = new Land(commandList[0]);

            IRover rover = new Rover(land, commandList[1]);

            rover.RePosition(commandList[2]);
            rovers.Add(rover);

            IRover rover2 = new Rover(land, commandList[3]);

            rover2.RePosition(commandList[4]);
            rovers.Add(rover2);
            return(rovers);
        }
コード例 #2
0
        private void SetLocation(string coordinate)
        {
            var commantType = Parser.GetTypeOfCommand(coordinate);

            if (commantType == CommandType.RoverCoordinate)
            {
                var location = new Position(coordinate);
                Direction = Parser.GetDirection(coordinate);

                IsLanded = Land.SetRoverLocation(location);
                if (IsLanded)
                {
                    Location = location;
                }
                else
                {
                    throw new LandingException("The Rover can't land this coordinate!");
                }
            }
        }
コード例 #3
0
        private void Move(Moving moving)
        {
            switch (moving)
            {
            case Moving.L:
                switch (Direction)
                {
                case CompassDirection.N:
                    Direction = CompassDirection.W;
                    break;

                case CompassDirection.E:
                    Direction = CompassDirection.N;
                    break;

                case CompassDirection.S:
                    Direction = CompassDirection.E;
                    break;

                case CompassDirection.W:
                    Direction = CompassDirection.S;
                    break;

                default:
                    break;
                }
                break;

            case Moving.R:
                switch (Direction)
                {
                case CompassDirection.N:
                    Direction = CompassDirection.E;
                    break;

                case CompassDirection.E:
                    Direction = CompassDirection.S;
                    break;

                case CompassDirection.S:
                    Direction = CompassDirection.W;
                    break;

                case CompassDirection.W:
                    Direction = CompassDirection.N;
                    break;

                default:
                    break;
                }
                break;

            case Moving.M:
                Position newLocation = new Position(Location);
                switch (Direction)
                {
                case CompassDirection.N:
                    newLocation.Y++;
                    break;

                case CompassDirection.E:
                    newLocation.X++;
                    break;

                case CompassDirection.S:
                    newLocation.Y--;
                    break;

                case CompassDirection.W:
                    newLocation.X--;
                    break;

                default:
                    break;
                }

                if (!Land.CheckCoordinate(newLocation))
                {
                    Location.X = newLocation.X;
                    Location.Y = newLocation.Y;
                }

                break;

            default:
                break;
            }
        }