public PathElement GetPathEndAtDestination(IPathTile from, IPathTile destination, IPathTile[,] tiles) { if (from == destination) { return(new PathElement(from)); } if (!destination.CanPathGoThroughTile()) { return(null); } List <PathElement> checkAdjacentTilesOfTheseTilesNow = new List <PathElement> { new PathElement(from) }; for (int i = 0; i < checkAdjacentTilesOfTheseTilesNow.Count; i++) { List <PathElement> adjacentTiles = GetAdjacentTilesOfTile(checkAdjacentTilesOfTheseTilesNow[i], tiles); for (int j = 0; j < adjacentTiles.Count; j++) { if (adjacentTiles[j].Tile == destination) { return(adjacentTiles[j]); } if (adjacentTiles[j].Tile.CanPathGoThroughTile() && !HasTileBeenChecked(adjacentTiles[j], checkAdjacentTilesOfTheseTilesNow)) { checkAdjacentTilesOfTheseTilesNow.Add(adjacentTiles[j]); } } } return(null); }
public PathElement(IPathTile tile, PathElement previousElement = null) { Tile = tile; PreviousElement = previousElement; }