Exemplo n.º 1
0
    void RevealConjunctiveEmptyBlocks(int x, int y)
    {
        for (int i = -1; i < 2; i++)
        {
            for (int j = -1; j < 2; j++)
            {
                if (i == 0 && j == 0)
                {
                    continue;
                }
                int bx = x + i;
                int by = y + j;

                if (bx < 0 || bx >= width || by < 0 || by >= height)
                {
                    continue;
                }

                if (status[by, bx] == 0)
                {
                    int mines = CalculateMines(bx, by);
                    if (mines == 0)
                    {
                        status[by, bx] = 1;
                        blocks[by, bx].gameObject.SetActive(false);
                        Instantiate(revealedBlockPrefab, blocks[by, bx].transform.position, Quaternion.identity);
                        RevealConjunctiveEmptyBlocks(bx, by);
                    }
                    else
                    {
                        status[by, bx] = 1;
                        blocks[by, bx].gameObject.SetActive(false);
                        GameObject    revealedBlockObj = Instantiate(revealedBlockPrefab, blocks[by, bx].transform.position, Quaternion.identity) as GameObject;
                        RevealedBlock revealedBlock    = revealedBlockObj.GetComponent <RevealedBlock>();
                        revealedBlock.SetImage(numberSprites[mines], Color.Lerp(color1, color2, mines / 8f));
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    void RevealBlocks()
    {
        int x = selectedBlock.x;
        int y = selectedBlock.y;

        if (board[y, x] == true)
        {
            // game over
            ExplodeAllMines();
            gameOver = true;
            gameOverText.SetActive(true);
        }
        else if (status[y, x] == 2 || status[y, x] == 1)
        {
            // flagged or revealed, do not do anything
            return;
        }
        else
        {
            // calculate number of mines on conjunctive blocks
            int mines = CalculateMines(x, y);
            // reveal conjunctive blocks if no mines
            if (mines == 0)
            {
                status[y, x] = 1;
                blocks[y, x].gameObject.SetActive(false);
                Instantiate(revealedBlockPrefab, blocks[y, x].transform.position, Quaternion.identity);
                for (int i = -1; i < 2; i++)
                {
                    for (int j = -1; j < 2; j++)
                    {
                        if (i == 0 && j == 0)
                        {
                            continue;
                        }
                        int bx = x + i;
                        int by = y + j;

                        if (bx < 0 || bx >= width || by < 0 || by >= height)
                        {
                            continue;
                        }

                        if (status[by, bx] == 0 && CalculateMines(bx, by) == 0)
                        {
                            status[by, bx] = 1;
                            blocks[by, bx].gameObject.SetActive(false);
                            Instantiate(revealedBlockPrefab, blocks[by, bx].transform.position, Quaternion.identity);
                            RevealConjunctiveEmptyBlocks(bx, by);
                        }
                    }
                }
            }
            else
            {
                status[y, x] = 1;
                blocks[y, x].gameObject.SetActive(false);
                GameObject    revealedBlockGameObject = Instantiate(revealedBlockPrefab, selectedBlock.transform.position, Quaternion.identity) as GameObject;
                RevealedBlock revealedBlock           = revealedBlockGameObject.GetComponent <RevealedBlock>();
                revealedBlock.SetImage(numberSprites[mines], Color.Lerp(color1, color2, mines / 8f));
            }
        }
    }