/// <summary> /// Processes the specified line by splitting it into characters, and then processing each one into a second command /// handler pipeline. /// </summary> /// <param name="battlefieldContext">The battlefield context.</param> /// <param name="line">The parsed line.</param> /// <exception cref="FormatException"></exception> public void Process(IBattlefieldCreationContext battlefieldContext, string line) { foreach (var key in line) { if (!_movementHandlers.TryGetValue(key, out IDroneMovementHandler droneMovementHandler)) { throw new FormatException($"Invalid character '{key}' in line '{line}': only the characters {{{string.Join(", ", _movementHandlers.Keys)}}} are permitted."); } droneMovementHandler.Process(battlefieldContext); } }
/// <summary> /// Processes the specified line and loads a drone at a position in the battlefield context. /// </summary> /// <param name="battlefieldContext">The battlefield context.</param> /// <param name="line">The parsed line.</param> /// <exception cref="FormatException"> /// </exception> public void Process(IBattlefieldCreationContext battlefieldContext, string line) { var elements = line .Split(' ') .Where(element => !string.IsNullOrEmpty(element)) .ToList(); ValidateElementsCount(line, elements); var x = ValidateIntegerParameter(line, elements[0], "first"); var y = ValidateIntegerParameter(line, elements[1], "second"); var orientation = ValidateOrientationParameter(line, elements[2]); var drone = Drone.FromPosition(x, y, orientation); battlefieldContext.AddDrone(drone); }
/// <summary> /// Processes the specified line and loads the appropriate resources in the battlefield context. /// </summary> /// <param name="battlefieldContext">The battlefield context.</param> /// <param name="line">The parsed line.</param> /// <exception cref="FormatException"> /// </exception> public void Process(IBattlefieldCreationContext battlefieldContext, string line) { var elements = line .Split(' ') .Where(element => !string.IsNullOrEmpty(element)) .ToList(); ValidateElementsCount(line, elements); var x = ValidateIntegerParameter(line, elements[0], "first"); ValidatePositiveInteger(line, x, "first"); var y = ValidateIntegerParameter(line, elements[1], "second"); ValidatePositiveInteger(line, y, "second"); var battlefield = RectangularBattlefieldArea.FromLTRB(0, 0, x, y); battlefieldContext.SetBattlefieldArea(battlefield); }
public void Process(IBattlefieldCreationContext battlefieldContext) { battlefieldContext.AddDroneCommand(new DroneTurnLeftCommand()); }