public PointCounter(Tile[,] tiles, Station[] stations) { this.tiles = new PointCounterTile[tiles.Length, tiles.Length]; for (int y = 0; y < tiles.Length; y++) { for (int x = 0; x < tiles.Length; x++) { PointCounterTile[] neighbours = new PointCounterTile[4]; if (x > 0) { neighbours[(int)Direction.N] = this.tiles[x - 1, y]; } if (y > 0) { neighbours[(int)Direction.W] = this.tiles[x, y - 1]; } if (x < tiles.Length - 1) { neighbours[(int)Direction.E] = this.tiles[x + 1, y]; } if (y < tiles.Length - 1) { neighbours[(int)Direction.S] = this.tiles[x, y + 1]; } this.tiles[x, y] = new PointCounterTile(tiles[x, y], neighbours, x, y, this); } } this.stations = new Station[stations.Length]; for (int i = 0; i < stations.Length; i++) { this.stations[i] = stations[i].clone(); } }
public void UnlinkNeighbor(Direction d) { PointCounterTile pct = neighbors[d]; pct.UnlinkNeighbor(Utilities.oppositeDirection(d)); neighbors.Remove(d); }
public void UnlinkNeighbor(PointCounterTile t) { foreach (Direction d in Enum.GetValues(typeof(Direction))) { if (neighbors[d].Equals(t)) { neighbors.Remove(d); t.UnlinkNeighbor(this); } } }
public void Place(int x, int y, Tile t) { Dictionary <Direction, PointCounterTile> neighbors = new Dictionary <Direction, PointCounterTile>(4); if (x > 0) { neighbors[Direction.N] = tiles[x - 1, y]; } if (y > 0) { neighbors[Direction.W] = tiles[x, y - 1]; } if (x < tiles.Length - 1) { neighbors[Direction.E] = tiles[x + 1, y]; } if (y < tiles.Length - 1) { neighbors[Direction.W] = tiles[x, y + 1]; } tiles[x, y] = new PointCounterTile(t, neighbors, x, y, this); }
/// <summary> /// Sets the neighbour on the direction specified by the argument /// </summary> void SetNeighbor(PointCounterTile pointCounterTile, Direction direction) { neighbors[direction] = pointCounterTile; }