public BMap(int sideCellCount, float hexRadius) { SideCellCount = sideCellCount; ArraySize = sideCellCount * 2 - 1; HexOutRadius = hexRadius; // Fill all Cells = new BMapCell[ArraySize, ArraySize]; for (int row = 0; row < ArraySize; row++) for (int col = 0; col < ArraySize; col++) Cells[col, row] = new BMapCell(col, row); int notNullCellsCount = ArraySize * ArraySize; // Remove top-left corner for (int row = 0; row < (sideCellCount - 1); row++) for (int col = 0; col < (sideCellCount - row - 1); col++) { notNullCellsCount--; Cells[col, row] = null; } // Remove bottom-right corner for (int row = sideCellCount; row < ArraySize; row++) for (int col = (ArraySize - row + sideCellCount - 1); col < ArraySize; col++) { notNullCellsCount--; Cells[col, row] = null; } _notNullCells = new BMapCell[notNullCellsCount]; notNullCellsCount = 0; for (int row = 0; row < ArraySize; row++) for (int col = 0; col < ArraySize; col++) if (Cells[col, row] != null) { _notNullCells[notNullCellsCount] = Cells[col, row]; notNullCellsCount++; } // [X] [X] [ ] [ ] [ ] // [X] [ ] [ ] [ ] [ ] // [ ] [ ] [ ] [ ] [ ] // [ ] [ ] [ ] [ ] [X] // [ ] [ ] [ ] [X] [X] HexWidth = (float)Math.Sqrt(3) * HexOutRadius; HexInRadius = HexWidth / 2f; HexHeight = 2f * HexOutRadius; WidthSpacing = HexWidth; HeightSpacing = HexHeight * 3f / 4f; // Fill hexes List<BMapCell> neighs = new List<BMapCell>(); for (int row = 0; row < ArraySize; row++) { for (int col = 0; col < ArraySize; col++) { if (Cells[col, row] != null) { var hex = new Hex( new PointF( HexWidth + (col - (ArraySize - sideCellCount - 1)) * (WidthSpacing) + row * (HexInRadius), HexOutRadius + row * (HeightSpacing) ), HexOutRadius); Cells[col, row].Hex = hex; Cells[col, row].ModelSize = new RectangleF(hex.Center.X - (HexWidth * 0.9f) / 2f, hex.Center.Y - (HexWidth * 0.9f) / 2f, HexWidth * 0.9f, HexWidth * 0.9f); Cells[col, row].StepsSize = new RectangleF(hex.Center.X - (HexWidth * 0.4f) / 2f, hex.Center.Y - (HexWidth * 0.4f) / 2f, HexWidth * 0.4f, HexWidth * 0.4f); neighs.Clear(); if ((col + 1).Between(-1, ArraySize) && (row + 0).Between(-1, ArraySize)) neighs.Add(Cells[col + 1, row + 0]); else neighs.Add(null); if ((col + 1).Between(-1, ArraySize) && (row - 1).Between(-1, ArraySize)) neighs.Add(Cells[col + 1, row - 1]); else neighs.Add(null); if ((col + 0).Between(-1, ArraySize) && (row - 1).Between(-1, ArraySize)) neighs.Add(Cells[col + 0, row - 1]); else neighs.Add(null); if ((col - 1).Between(-1, ArraySize) && (row + 0).Between(-1, ArraySize)) neighs.Add(Cells[col - 1, row + 0]); else neighs.Add(null); if ((col - 1).Between(-1, ArraySize) && (row + 1).Between(-1, ArraySize)) neighs.Add(Cells[col - 1, row + 1]); else neighs.Add(null); if ((col + 0).Between(-1, ArraySize) && (row + 1).Between(-1, ArraySize)) neighs.Add(Cells[col + 0, row + 1]); else neighs.Add(null); Cells[col, row].Neighbors = neighs.ToArray(); } } } neighs = null; // Prepare layout Width = TMath.Round(HexWidth * ArraySize + 1 + (ArraySize*5)); Height = TMath.Round(HexHeight + HeightSpacing * (ArraySize - 1) + 1 + (ArraySize*5)); Bitmap b = new Bitmap(Width, Height); Graphics g = Graphics.FromImage(b); //g.FillRectangle(Brushes.White, new Rectangle(0, 0, b.Width, b.Height)); g.TextRenderingHint = TextRenderingHint.AntiAlias; for (int i = 0; i < _notNullCells.Length; i++) { g.FillPolygon(Brushes.Gainsboro, _notNullCells[i].Hex.K); var s = String.Format("{0}", _notNullCells[i].Axial); var w = g.MeasureString(s, _fnt).Width; g.DrawString(s, _fnt, _brush, _notNullCells[i].Hex.Center.X - w / 2, _notNullCells[i].Hex.Center.Y - 35, _drawFormat); s = String.Format("{0}", _notNullCells[i].Cube); w = g.MeasureString(s, _fnt).Width; g.DrawString(s, _fnt, _brush, _notNullCells[i].Hex.Center.X - w / 2, _notNullCells[i].Hex.Center.Y + 20, _drawFormat); } g.Flush(); GridLayout = new Bitmap(b); g = null; b = null; }
public int GetCurrentInt(CharType type) { return(TMath.Round(GetCurrentFloat(type))); }
public static Axial ToAxial(this Cube a) { return(new Axial(TMath.Round(a.X), TMath.Round(a.Z))); }
public int GetBaseInt(CharType type) { return(TMath.Round(GetBaseFloat(type))); }
public static int DistanceToI(this Cube a, Cube b) { return(TMath.Round(Math.Max(Math.Max(Math.Abs(a.X - b.X), Math.Abs(a.Y - b.Y)), Math.Abs(a.Z - b.Z)))); }