namespace GlobalClassLib; public abstract class GlobalTileConnector where TTile : GlobalMapTile where TCon : GlobalTileConnector { // private readonly TTile _tile1; // private readonly TTile _tile2; public GlobalTileConnector(TTile tile1, TTile tile2, ConnectorType type) { Tiles.tile1 = tile1; Tiles.tile2 = tile2; Type = type; } public GlobalTileConnector(TTile tile2, ConnectorType type) { Tiles.tile2 = tile2; Type = type; } public (TTile tile1, TTile tile2) Tiles; public bool Blocked { get; set; } public (int, int) Id => (Tiles.tile1.Id, Tiles.tile2.Id); public ConnectorType Type { get; set; } public TTile OtherTile(TTile tile) => Tiles.Item1 == tile ? Tiles.Item2 : Tiles.Item1; public Direction GetDirection(TTile tile) { if (tile != Tiles.tile1 && tile != Tiles.tile2) return Direction.NONE; TTile other = OtherTile(tile); (int, int) dpos = (other.GridPosition.x - tile.GridPosition.x, other.GridPosition.y - tile.GridPosition.y); switch (dpos){ case (0, 1): return Direction.NORTH; case (1, 0): return Direction.EAST; case (0, -1): return Direction.SOUTH; case (-1, 0): return Direction.WEST; default: return Direction.NONE; } } public override string ToString() => $"Con ({Tiles.Item1.PositionAsString} -> {Tiles.Item2.PositionAsString})"; public abstract TCon Clone(); }