예제 #1
0
파일: Hexes.cs 프로젝트: osblow/HexagonGame
        public static Hexagon CreateHexagon(HexType type, Hexagon sibling, HexDir dirToSibling, int index_x, int index_y)
        {
            Hexagon result = null;

            if (type == HexType.Game)
            {
                result = new GameHexagon(sibling.GetSiblingPos(dirToSibling), index_x, index_y);
            }
            else if (type == HexType.Solid)
            {
                result = new SolidHexagon(sibling.GetSiblingPos(dirToSibling), index_x, index_y);
            }

            return(result);
        }
예제 #2
0
        void Init()
        {
            LoadConf();



            m_hexagons = new Hexagon[m_size][];
            for (int r = 0; r < m_size; r++)
            {
                m_hexagons[r] = new Hexagon[m_size];
            }


            int i = 0, j = m_columnOffsetForRaws[i];

            m_hexagons[i][j] = new SolidHexagon(Vector3.zero, i, j);
            for (; i < m_hexagons.Length; i++)
            {
                j = m_columnOffsetForRaws[i];
                if (i > 0)
                {
                    m_hexagons[i][j] = HexFactory.CreateHexagon(HexType.Solid, m_hexagons[i - 1][j], HexDir.LeftBack, i, j);
                }
                ++j;

                for (; j < m_columnOffsetForRaws[i] + m_columnForRaws[i]; j++)
                {
                    if (i == 0 || i == m_hexagons.Length - 1 || j == 0 || j == m_columnOffsetForRaws[i] + m_columnForRaws[i] - 1)
                    {
                        m_hexagons[i][j] = HexFactory.CreateHexagon(HexType.Solid, m_hexagons[i][j - 1], HexDir.Right, i, j);
                    }
                    else
                    {
                        m_hexagons[i][j] = HexFactory.CreateHexagon(HexType.Game, m_hexagons[i][j - 1], HexDir.Right, i, j);
                    }
                }
            }

            for (int k = 0; k < m_hexagons.Length; k++)
            {
                for (int x = 0; x < m_hexagons[k].Length; x++)
                {
                    Hexagon theHex = m_hexagons[k][x];
                    if (theHex == null)
                    {
                        continue;
                    }

                    // left forward
                    if (k > 0 && x > 0 && m_hexagons[k - 1][x - 1] != null)
                    {
                        theHex.SetSibling(HexDir.LeftForward, m_hexagons[k - 1][x - 1]);
                    }

                    // right forward
                    if (k > 0 && m_hexagons[k - 1][x] != null)
                    {
                        theHex.SetSibling(HexDir.RightForward, m_hexagons[k - 1][x]);
                    }

                    // left
                    if (x > 0 && m_hexagons[k][x - 1] != null)
                    {
                        theHex.SetSibling(HexDir.Left, m_hexagons[k][x - 1]);
                    }

                    // right
                    if (x < m_hexagons.Length - 1 && m_hexagons[k][x + 1] != null)
                    {
                        theHex.SetSibling(HexDir.Right, m_hexagons[k][x + 1]);
                    }

                    // left back
                    if (k < m_hexagons.Length - 1 && m_hexagons[k + 1][x] != null)
                    {
                        theHex.SetSibling(HexDir.LeftBack, m_hexagons[k + 1][x]);
                    }

                    // right back
                    if (k < m_hexagons.Length - 1 && x < m_hexagons[k].Length - 1 && m_hexagons[k + 1][x + 1] != null)
                    {
                        theHex.SetSibling(HexDir.RightBack, m_hexagons[k + 1][x + 1]);
                    }
                }
            }
        }