Beispiel #1
0
 public MapStateManager(MapStateManager baseMgr)
 {
     _map         = baseMgr._map;
     _width       = baseMgr._width;
     _height      = baseMgr._height;
     _probability = (double[, ])baseMgr._probability.Clone();
     _entropy     = (double[, ])baseMgr._entropy.Clone();
 }
Beispiel #2
0
        /// <summary>
        /// Sets internal fields and creates board
        /// </summary>
        /// <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>

        private void Initialize(int width, int height, int side, HexOrientation orientation, int xOffset, int yOffset)
        {
            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.mapState    = new HexagonalMapState(width, height);

            float h = CalcUtil.CalculateH(side);             // short side
            float r = CalcUtil.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
                    #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, orientation);
                            break;

                        case HexOrientation.Pointy:
                            hexes[0, 0] = new Hex(0 + r + xOffset, 0 + yOffset, side, 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)FlatVertice.BottomLeft], side, 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)FlatVertice.UpperRight].X;
                                    float y = hexes[i, j - 1].Points[(int)FlatVertice.UpperRight].Y;
                                    x          += h;
                                    y          -= r;
                                    hexes[i, j] = new Hex(x, y, side, orientation);
                                }
                                else
                                {
                                    // Calculate from Hex to left's Middle Right Vertice
                                    hexes[i, j] = new Hex(hexes[i, j - 1].Points[(int)FlatVertice.MiddleRight], side, 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)PointyVertice.BottomLeft], side, orientation);
                                }
                                else
                                {
                                    hexes[i, j] = new Hex(hexes[i - 1, j].Points[(int)PointyVertice.BottomRight], side, orientation);
                                }
                            }
                            else
                            {
                                // Calculate from Hex to the left
                                float x = hexes[i, j - 1].Points[(int)PointyVertice.UpperRight].X;
                                float y = hexes[i, j - 1].Points[(int)PointyVertice.UpperRight].Y;
                                x          += r;
                                y          -= h;
                                hexes[i, j] = new Hex(x, y, side, orientation);
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            mapStateMgr = new MapStateManager(this);
        }