public Position() { Coordinates = new Coordinates(); }
public PositionValidator(Coordinates minCordinates, Coordinates maxCoordinates) { MinCordinates = minCordinates; MaxCoordinates = maxCoordinates; }
public Position(Coordinates coordinates, Direction direction) { Coordinates = coordinates; Direction = Direction; }
public Position Calculate(CommandPayload commandPayload) { switch (commandPayload.Action) { case Action.Place: bool isValid = positionValidator.IsValid(commandPayload.Position.Coordinates); if (isValid) { currentPosition.Coordinates = commandPayload.Position.Coordinates; currentPosition.Direction = commandPayload.Position.Direction; } break; case Action.Move: if (positionValidator.IsValid(currentPosition.Coordinates)) { Coordinates newCoordinates = new Coordinates(); newCoordinates.X = currentPosition.Coordinates.X; newCoordinates.Y = currentPosition.Coordinates.Y; switch (currentPosition.Direction) { case Direction.East: newCoordinates.X = newCoordinates.X + 1; break; case Direction.West: newCoordinates.X = newCoordinates.X - 1; break; case Direction.North: newCoordinates.Y = newCoordinates.Y + 1; break; case Direction.South: newCoordinates.Y = newCoordinates.Y + 1; break; default: break; } if (positionValidator.IsValid(newCoordinates)) { currentPosition.Coordinates = newCoordinates; } } break; case Action.Left: case Action.Right: if (positionValidator.IsValid(currentPosition.Direction)) { currentPosition.Direction = positions[currentPosition.Direction][commandPayload.Action]; } break; default: break; } return(currentPosition); }