示例#1
0
    void CheckNeighborMine()
    {
        GameObject  gameController = GameObject.Find("GameController");
        GameControl gameControl    = gameController.GetComponent <GameControl>();

        int maxRow    = gameControl.mineArray.GetLength(0);
        int maxColumn = gameControl.mineArray.GetLength(1);

        bool[,] checkStatus = new bool[maxRow, maxColumn];

        for (int i = 0; i < maxRow; i++)
        {
            for (int j = 0; j < maxColumn; j++)
            {
                checkStatus[i, j] = false;
            }
        }

        Stack <MineControllor> mineStack = new Stack <MineControllor>();

        mineStack.Push(gameControl.mineArray[Row, Column]);

        while (mineStack.Count != 0)
        {
            MineControllor m = mineStack.Pop();
            if (checkStatus[m.Row, m.Column] != true)
            {
                checkStatus[m.Row, m.Column] = true;
                int mineNum = m.GetNeighborMineNum();

                if (mineNum == 0)
                {
                    m.CurrentMineStatus       = MineStatus.Clear;
                    m.renderer.material.color = Color.blue;
                    m.mineText.text           = mineNum.ToString();

                    int minX = m.Row - 1 > 0 ? m.Row - 1 : 0;
                    int maxX = m.Row + 1 < maxRow ? m.Row + 1 : maxRow - 1;
                    int minY = m.Column - 1 > 0 ? m.Column - 1 : 0;
                    int maxY = m.Column + 1 < maxColumn ? m.Column + 1 : maxColumn - 1;

                    for (int i = minX; i <= maxX; i++)
                    {
                        for (int j = minY; j <= maxY; j++)
                        {
                            mineStack.Push(gameControl.mineArray[i, j]);
                        }
                    }
                }
                else
                {
                    m.CurrentMineStatus       = MineStatus.Clear;
                    m.renderer.material.color = Color.blue;
                    m.mineText.text           = m.GetNeighborMineNum().ToString();
                }
            }
        }
    }
示例#2
0
    void DisableAllMine()
    {
        GameObject  gameController = GameObject.Find("GameController");
        GameControl gameControl    = gameController.GetComponent <GameControl>();

        for (int i = 0; i < gameControl.mineArray.GetLength(0); i++)
        {
            for (int j = 0; j < gameControl.mineArray.GetLength(1); j++)
            {
                MineControllor m = gameControl.mineArray[i, j];
                if (m.IsMine)
                {
                    m.renderer.material.color = Color.red;
                }
                else
                {
                    m.renderer.material.color = Color.blue;
                    m.mineText.text           = m.GetNeighborMineNum().ToString();
                }
                BoxCollider bc = m.GetComponent <BoxCollider>();
                bc.enabled = false;
            }
        }
    }