/// <summary> /// Creates a new hexgrid with the default map width and height and fills it with hexagons. /// </summary> public HexGrid() { mGrid = new Hexagon[DEFAULT_MAP_WIDTH, DEFAULT_MAP_HEIGHT]; for (int i = 0; i < DEFAULT_MAP_WIDTH; i++) { for (int j = 0; j < DEFAULT_MAP_HEIGHT; j++) { mGrid[i, j] = new Hexagon(); } } }
private void HexSelected(Hexagon newHex) { if (mSelectedHex != null) mSelectedHex.SetDefaultColorScheme(); newHex.SetSelectedColorScheme(); mSelectedHex = newHex; tbDepth.Text = mSelectedHex.Depth.ToString(); }
/// <summary> /// Gets an array of Hexagons surronding the specified hex. /// Null hexes ARE in to the array! /// /// They are in this order: /// 0: Bottom, 1: Bottom Right, 2: Top Right, 3: Top, 4: Top Left, 5: Bottom Left /// </summary> /// <returns>An array of hexagons surronding the given hex, including null hexes.</returns> public static Hexagon[] SurrondingHexes(HexGrid grid, int x, int y) { Hexagon[] surrounding = new Hexagon[6]; bool even = x % 2 == 0; Hexagon[,] mGrid = grid.Grid; if (y > 0) surrounding[0] = mGrid[x, y - 1]; // Bottom if (y < DEFAULT_MAP_HEIGHT - 1) surrounding[3] = mGrid[x, y + 1]; // Top if (!even) { if (x < DEFAULT_MAP_WIDTH - 1) surrounding[1] = mGrid[x + 1, y]; // Bottom Right if (x < DEFAULT_MAP_WIDTH - 1 && y < DEFAULT_MAP_HEIGHT - 1) surrounding[2] = mGrid[x + 1, y + 1]; // Top Right if (x > 0 && y < DEFAULT_MAP_HEIGHT - 1) surrounding[4] = mGrid[x - 1, y + 1]; // Top Left if (x > 0) surrounding[5] = mGrid[x - 1, y]; // Bottom Left } else { if (x < DEFAULT_MAP_WIDTH - 1 && y > 0) surrounding[1] = mGrid[x + 1, y - 1]; // Bottom Right if (x < DEFAULT_MAP_WIDTH - 1 && y < DEFAULT_MAP_HEIGHT) surrounding[2] = mGrid[x + 1, y]; // Top Right if (x > 0 && y < DEFAULT_MAP_HEIGHT) surrounding[4] = mGrid[x - 1, y]; // Top Left if (x > 0 && y > 0) surrounding[5] = mGrid[x - 1, y - 1]; // Bottom Left } return surrounding; }