Esempio n. 1
0
        internal static LandSize ParseSize(string size)
        {
            var commantType = Parser.GetTypeOfCommand(size);

            if (commantType != Enums.CommandType.LandSizing)
            {
                throw new CommandException("Wrong command for the Land size!");
            }

            LandSize landSize = new LandSize()
            {
                Width  = byte.Parse(size.Split(Separator)[0]),
                Height = byte.Parse(size.Split(Separator)[1])
            };

            return(landSize);
        }
Esempio n. 2
0
        /// <summary>
        /// The Rover moves with instructions
        /// </summary>
        /// <param name="instructions">LMLMLMLMM</param>
        public void RePosition(string instructions)
        {
            var commantType = Parser.GetTypeOfCommand(instructions);

            if (commantType == CommandType.Instructions)
            {
                Moving moving;
                for (int i = 0; i < instructions.Length && IsLanded; i++)
                {
                    moving = Parser.GetMovement(instructions, i);
                    Move(moving);
                }
            }
            else
            {
                throw new Exceptions.InstructionException($"{instructions} is wrong command. The command only contains L,R,M characters!");
            }
        }
Esempio n. 3
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!");
                }
            }
        }