OneNightDuel/GlobalClassLib/GlobalTileConnector.cs

42 lines
1.4 KiB
C#
Raw Normal View History

namespace GlobalClassLib;
public abstract class GlobalTileConnector<TTile, TCon>
where TTile : GlobalMapTile<TCon,TTile>
where TCon : GlobalTileConnector<TTile, TCon> {
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.tile1 == tile ? Tiles.tile2 : Tiles.tile1;
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 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.IdAsString} -> {Tiles.Item2.IdAsString})";
public abstract TCon Clone();
}