public void initialize(LunchHourGames lhg, int hexSize, int width, int height, int xOffset, int yOffset, int penWidth, bool isPointy, Color backgroundColor) { this.hexSize = hexSize; this.hexBoardWidth = width; this.hexBoardHeight = height; this.xOffset = xOffset; this.yOffset = yOffset; this.penWidth = penWidth; this.backgroundColor = backgroundColor; if (isPointy) { this.orientation = HexOrientation.Pointy; } else { this.orientation = HexOrientation.Flat; } // Create the board. Add all these createHexagonalBoard(); this.extents = get3DExtents(); // Go ahead and draw the hex board to the grid this.hexDraw.Draw(grid); }
/// <summary> /// Sets internal fields and calls CalculateVertices() /// </summary> private void Initialize(float x, float y, float side, Hexagonal.HexOrientation orientation) { this.x = x; this.y = y; this.side = side; this.orientation = orientation; this.hexState = new HexState(); CalculateVertices(); }
/// <summary> /// Sets internal fields and calls CalculateVertices() /// </summary> private void Initialize(float x, float y, float side, int col, int row, Hexagonal.HexOrientation orientation) { this.id = ((1000000 + ((int)x * 1000)) + (int)y); this.x = x; this.y = y; this.side = side; this.col = col; this.row = row; this.orientation = orientation; this.hexState = new HexState(); CalculateVertices(); }
/// <summary> /// Sets internal fields and calls CalculateVertices() /// </summary> private void Initialize(float x, float y, int i, int j, float side, Hexagonal.HexOrientation orientation, Color hexColor) { this.x = x; this.y = y; this.i = i; this.j = j; this.side = side; this.orientation = orientation; this.hexState = new HexState(); this.hexState.BackgroundColor = hexColor; this.astar = new AStar(); CalculateVertices(); }
/// <param name="width">Board width</param> /// <param name="height">Board height</param> /// <param name="side">Hexagon side length</param> /// <param name="orientation">Orientation of the hexagons</param> /// <param name="xOffset">X coordinate offset</param> /// <param name="yOffset">Y coordinate offset</param> public HexagonalMap(int width, int height, int side, Hexagonal.HexOrientation orientation, int xOffset, int yOffset) { Initialize(width, height, side, orientation, xOffset, yOffset); InitHexPos(); }
/// <param name="width">Board width</param> /// <param name="height">Board height</param> /// <param name="side">Hexagon side length</param> /// <param name="orientation">Orientation of the hexagons</param> public HexagonalMap(int width, int height, int side, Hexagonal.HexOrientation orientation) { Initialize(width, height, side, orientation, 0, 0); InitHexPos(); }
public Hex(float x, float y, int i, int j, float side, Hexagonal.HexOrientation orientation, Color hexColor) { Initialize(x, y, i, j, side, orientation, hexColor); }
/// <param name="side">length of one side of the hexagon</param> public Hex(int x, int y, int i, int j, int side, Hexagonal.HexOrientation orientation, Color hexColor) { Initialize(Hexagonal.HexMath.ConvertToFloat(x), Hexagonal.HexMath.ConvertToFloat(y), i, j, Hexagonal.HexMath.ConvertToFloat(side), orientation, hexColor); }
public Hex(float x, float y, float side, Hexagonal.HexOrientation orientation) { Initialize(x, y, side, orientation); }
public Board(int width, int height, int side, Hexagonal.HexOrientation orientation) { Initialize(width, height, side, orientation, 0, 0); }
private void Initialize(int width, int height, int side, Hexagonal.HexOrientation orientation, int xOffset, int yOffset, int row = 0, int col = 0) { this.width = width; this.height = height; this.xOffset = xOffset; this.yOffset = yOffset; this.side = side; this.orientation = orientation; hexes = new Hex[height, width]; //opposite of what we'd expect this.boardState = new BoardState(); float h = Hexagonal.MathUtil.CalculateH(side); // short side float r = Hexagonal.MathUtil.CalculateR(side); // long side int offsetRow = row - this.activeRow; int offsetCol = col - this.activeCol; // // Calculate pixel info..remove? // because of staggering, need to add an extra r/h float hexWidth = 0; float hexHeight = 0; switch (orientation) { case HexOrientation.Flat: hexWidth = side + h; hexHeight = r + r; this.pixelWidth = (width * hexWidth) + h; this.pixelHeight = (height * hexHeight) + r; break; case HexOrientation.Pointy: hexWidth = r + r; hexHeight = side + h; this.pixelWidth = (width * hexWidth) + r; this.pixelHeight = (height * hexHeight) + h; break; default: break; } bool inTopRow = false; bool inBottomRow = false; bool inLeftColumn = false; bool inRightColumn = false; bool isTopLeft = false; bool isTopRight = false; bool isBotomLeft = false; bool isBottomRight = false; // i = y coordinate (rows), j = x coordinate (columns) of the hex tiles 2D plane for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { // Set position booleans #region Position Booleans if (i == 0) { inTopRow = true; } else { inTopRow = false; } if (i == height - 1) { inBottomRow = true; } else { inBottomRow = false; } if (j == 0) { inLeftColumn = true; } else { inLeftColumn = false; } if (j == width - 1) { inRightColumn = true; } else { inRightColumn = false; } if (inTopRow && inLeftColumn) { isTopLeft = true; } else { isTopLeft = false; } if (inTopRow && inRightColumn) { isTopRight = true; } else { isTopRight = false; } if (inBottomRow && inLeftColumn) { isBotomLeft = true; } else { isBotomLeft = false; } if (inBottomRow && inRightColumn) { isBottomRight = true; } else { isBottomRight = false; } #endregion // // Calculate Hex positions // if (isTopLeft) { //First hex switch (orientation) { case HexOrientation.Flat: hexes[0, 0] = new Hex(0 + h + xOffset, 0 + yOffset, side, i + offsetCol, j + offsetRow, orientation); break; case HexOrientation.Pointy: hexes[0, 0] = new Hex(0 + r + xOffset, 0 + yOffset, side, i + offsetCol, j + offsetRow, orientation); break; default: break; } } else { switch (orientation) { case HexOrientation.Flat: if (inLeftColumn) { // Calculate from hex above hexes[i, j] = new Hex(hexes[i - 1, j].Points[(int)Hexagonal.FlatVertice.BottomLeft], side, i + offsetCol, j + offsetRow, orientation); } else { // Calculate from Hex to the left and need to stagger the columns if (j % 2 == 0) { // Calculate from Hex to left's Upper Right Vertice plus h and R offset float x = hexes[i, j - 1].Points[(int)Hexagonal.FlatVertice.UpperRight].X; float y = hexes[i, j - 1].Points[(int)Hexagonal.FlatVertice.UpperRight].Y; x += h; y -= r; hexes[i, j] = new Hex(x, y, side, i + offsetCol, j + offsetRow, orientation); } else { // Calculate from Hex to left's Middle Right Vertice hexes[i, j] = new Hex(hexes[i, j - 1].Points[(int)Hexagonal.FlatVertice.MiddleRight], side, i + offsetCol - (offsetRow % 2), j + offsetRow, orientation); } } break; case HexOrientation.Pointy: if (inLeftColumn) { // Calculate from hex above and need to stagger the rows if (i % 2 == 0) { hexes[i, j] = new Hex(hexes[i - 1, j].Points[(int)Hexagonal.PointyVertice.BottomLeft], side, i + offsetCol, j + offsetRow, orientation); } else { hexes[i, j] = new Hex(hexes[i - 1, j].Points[(int)Hexagonal.PointyVertice.BottomRight], side, i + offsetCol, j + offsetRow, orientation); } } else { // Calculate from Hex to the left float x = hexes[i, j - 1].Points[(int)Hexagonal.PointyVertice.UpperRight].X; float y = hexes[i, j - 1].Points[(int)Hexagonal.PointyVertice.UpperRight].Y; x += r; y -= h; hexes[i, j] = new Hex(x, y, side, i + offsetCol, j + offsetRow, orientation); } break; default: break; } } if (m_data != null) { Console.WriteLine("not null!"); int r1 = (int)hexes[i, j].Row; int c1 = (int)hexes[i, j].Col; if (r1 < m_data.width && r1 >= 0 && c1 < m_data.height && c1 >= 0) { int state = m_data.getGridStae(r1, c1); Console.WriteLine("state is" + state); switch (state) { case 0: hexes[i, j].HexState.setBackgroundColor(System.Drawing.Color.White); break; case 1: hexes[i, j].HexState.setBackgroundColor(System.Drawing.Color.Red); break; case 2: case 3: default: break; } } } if (i == coreY && j == coreX) { this.BoardState.ActiveHex = hexes[i, j]; this.activeRow = j; this.activeCol = i; } } } }
public Hex(float x, float y, float side, int col, int row, Hexagonal.HexOrientation orientation) { Initialize(x, y, side, col, row, orientation); }
/// <param name="side">length of one side of the hexagon</param> public Hex(int x, int y, int side, int col, int row, Hexagonal.HexOrientation orientation) { Initialize(Hexagonal.MathUtil.ConvertToFloat(x), Hexagonal.MathUtil.ConvertToFloat(y), Hexagonal.MathUtil.ConvertToFloat(side), col, row, orientation); }
private void Initialize(int width, int height, int side, Hexagonal.HexOrientation orientation, int xOffset, int yOffset, Color boardColor) { this.width = width; this.height = height; this.xOffset = xOffset; this.yOffset = yOffset; this.side = side; this.orientation = orientation; hexes = new Hex[height, width]; //opposite of what we'd expect this.boardState = new BoardState(); this.boardColor = boardColor; float h = Hexagonal.HexMath.CalculateH(side); // short side float r = Hexagonal.HexMath.CalculateR(side); // long side // // Calculate pixel info..remove? // because of staggering, need to add an extra r/h float hexWidth = 0; float hexHeight = 0; switch (orientation) { case HexOrientation.Flat: hexWidth = side + h; hexHeight = r + r; this.pixelWidth = (width * hexWidth) + h; this.pixelHeight = (height * hexHeight) + r; break; case HexOrientation.Pointy: hexWidth = r + r; hexHeight = side + h; this.pixelWidth = (width * hexWidth) + r; this.pixelHeight = (height * hexHeight) + h; break; default: break; } bool inTopRow = false; bool inBottomRow = false; bool inLeftColumn = false; bool inRightColumn = false; bool isTopLeft = false; bool isTopRight = false; bool isBotomLeft = false; bool isBottomRight = false; // i = y coordinate (rows), j = x coordinate (columns) of the hex tiles 2D plane for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { // Set position booleans if (i == 0) { inTopRow = true; } else { inTopRow = false; } if (i == height - 1) { inBottomRow = true; } else { inBottomRow = false; } if (j == 0) { inLeftColumn = true; } else { inLeftColumn = false; } if (j == width - 1) { inRightColumn = true; } else { inRightColumn = false; } if (inTopRow && inLeftColumn) { isTopLeft = true; } else { isTopLeft = false; } if (inTopRow && inRightColumn) { isTopRight = true; } else { isTopRight = false; } if (inBottomRow && inLeftColumn) { isBotomLeft = true; } else { isBotomLeft = false; } if (inBottomRow && inRightColumn) { isBottomRight = true; } else { isBottomRight = false; } // // Calculate Hex positions // if (isTopLeft) { //First hex switch (orientation) { case HexOrientation.Flat: hexes[0, 0] = new Hex(0 + h + xOffset, 0 + yOffset, 0, 0, side, orientation, boardColor); break; case HexOrientation.Pointy: hexes[0, 0] = new Hex(0 + r + xOffset, 0 + yOffset, 0, 0, side, orientation, boardColor); break; default: break; } } else { switch (orientation) { case HexOrientation.Flat: if (inLeftColumn) { // Calculate from hex above hexes[i, j] = new Hex(hexes[i - 1, j].Points[(int)Hexagonal.FlatVertice.BottomLeft], i, j, side, orientation, boardColor); } else { // Calculate from Hex to the left and need to stagger the columns if (j % 2 == 0) { // Calculate from Hex to left's Upper Right Vertice plus h and R offset float x = hexes[i, j - 1].Points[(int)Hexagonal.FlatVertice.UpperRight].X; float y = hexes[i, j - 1].Points[(int)Hexagonal.FlatVertice.UpperRight].Y; x += h; y -= r; hexes[i, j] = new Hex(x, y, i, j, side, orientation, boardColor); } else { // Calculate from Hex to left's Middle Right Vertice hexes[i, j] = new Hex(hexes[i, j - 1].Points[(int)Hexagonal.FlatVertice.MiddleRight], i, j, side, orientation, boardColor); } } break; case HexOrientation.Pointy: if (inLeftColumn) { // Calculate from hex above and need to stagger the rows if (i % 2 == 0) { hexes[i, j] = new Hex(hexes[i - 1, j].Points[(int)Hexagonal.PointyVertice.BottomLeft], i, j, side, orientation, boardColor); } else { hexes[i, j] = new Hex(hexes[i - 1, j].Points[(int)Hexagonal.PointyVertice.BottomRight], i, j, side, orientation, boardColor); } } else { // Calculate from Hex to the left float x = hexes[i, j - 1].Points[(int)Hexagonal.PointyVertice.UpperRight].X; float y = hexes[i, j - 1].Points[(int)Hexagonal.PointyVertice.UpperRight].Y; x += r; y -= h; hexes[i, j] = new Hex(x, y, i, j, side, orientation, boardColor); } break; default: break; } } } } }
/// <param name="width">Board width</param> /// <param name="height">Board height</param> /// <param name="side">Hexagon side length</param> /// <param name="orientation">Orientation of the hexagons</param> /// <param name="xOffset">X coordinate offset</param> /// <param name="yOffset">Y coordinate offset</param> public Board(int width, int height, int side, Hexagonal.HexOrientation orientation, int xOffset, int yOffset) { Initialize(width, height, side, orientation, xOffset, yOffset); }
/// <param name="width">Board width</param> /// <param name="height">Board height</param> /// <param name="side">Hexagon side length</param> /// <param name="orientation">Orientation of the hexagons</param> /// <param name="xOffset">X coordinate offset</param> /// <param name="yOffset">Y coordinate offset</param> public HexBoard(int width, int height, int side, Hexagonal.HexOrientation orientation, int xOffset, int yOffset, Color boardColor) { Initialize(width, height, side, orientation, xOffset, yOffset, boardColor); }
/// <param name="side">length of one side of the hexagon</param> public Hex(int x, int y, int side, Hexagonal.HexOrientation orientation) { Initialize(Hexagonal.CalcUtil.ConvertToFloat(x), Hexagonal.CalcUtil.ConvertToFloat(y), Hexagonal.CalcUtil.ConvertToFloat(side), orientation); }