Exemplo n.º 1
0
    void revelarBox()
    {
        position.changeMine(this);

        if (boxState == BoxState.Hidden)
        {
            if (mined)
            {
                sprite.color = Color.red;
                position.GameOver();
            }
            else
            {
                position.SumarDescubiertos();
                int minasRodeando = conocerCantidad();
                if (minasRodeando != 0)
                {
                    minesAround   = (byte)minasRodeando;
                    sprite.sprite = mineSprites[minasRodeando + 2];
                    boxState      = BoxState.Revealed;
                }
                else
                {
                    sprite.sprite = mineSprites[0];
                }
            }
        }
        else if (boxState == BoxState.Revealed)
        {
            byte          flagCount = 0;
            BoxController boxScript;
            Object[]      allBox = GameObject.FindGameObjectsWithTag("Box");
            foreach (GameObject boxGO in allBox)
            {
                boxScript = boxGO.GetComponent <BoxController>();
                for (int y = -1; y <= 1; y++)
                {
                    for (int x = -1; x <= 1; x++)
                    {
                        if (!(boxPositionHeight + y < 0 || boxPositionWidth + x < 0 || boxPositionHeight + y >= PositionController.heightMines || boxPositionWidth + x >= PositionController.widthMines) && (boxScript.boxPositionHeight == boxPositionHeight + y && boxScript.boxPositionWidth == boxPositionWidth + x && boxScript.boxState == BoxState.Flag))
                        {
                            flagCount++;
                        }
                    }
                }
            }

            if (flagCount == minesAround)
            {
                revealAroundBoxes();
            }
        }
    }