private Dictionary<Tile, object> paintTilesAdjacentTo(Tile startTile) { Dictionary<Tile, object> visitedTiles = new Dictionary<Tile, object>(); Stack<Tile> tileStack = new Stack<Tile>(); tileStack.Push(startTile); visitedTiles.Add(startTile, null); while (tileStack.Count > 0) { Tile tile = tileStack.Pop(); addIfPossible(visitedTiles, tileStack, tile.Position.X - 1, tile.Position.Y); addIfPossible(visitedTiles, tileStack, tile.Position.X + 1, tile.Position.Y); addIfPossible(visitedTiles, tileStack, tile.Position.X, tile.Position.Y - 1); addIfPossible(visitedTiles, tileStack, tile.Position.X, tile.Position.Y + 1); } return visitedTiles; }
private Tile getExpandingTile(int x, int y) { tileGrid.containCoordinate(x, y); Tile t = tileGrid.get(x, y); if (t == null) { t = new Tile(water); t.Position = new Point(x, y); tileGrid.set(x, y, t); } return t; }
private bool isWalkableTerrain(Tile t) { return isWalkableTerrain(t.Terrain); }
public Tile getTile(int x, int y) { if (!tileGrid.containsCoordinate(x, y)) { Tile t = new Tile(water); t.Position = new Point(x, y); return t; } return getExpandingTile(x, y); }