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); }
/// <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!"); } }
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!"); } } }