Esempio n. 1
0
    public void moveUp()
    {
        if (getNewBricks(Move.down) == null)
        {
            moveCurrentBricks(Move.down);
        }

        // Change row eat
        if (listEatingRows.Count > 0)
        {
            foreach (List <int> eatingRows in listEatingRows)
            {
                for (int i = eatingRows.Count - 1; i >= 0; i--)
                {
                    eatingRows[i]--;
                }
            }
        }

        // Copy Brick
        for (int i = 1; i < row; i++)
        {
            for (int j = 0; j < column; j++)
            {
                BrickController brick = bricks[i, j];
                if (brick.isShow && !currentBricks.Contains(brick))
                {
                    brick.setShow(false);
                    if (!usingSprite)
                    {
                        bricks[i - 1, j].setShow(true, brick.color);
                    }
                    else
                    {
                        bricks[i - 1, j].setShow(true, brick.sprite);
                    }
                }
            }
        }

        // Create Last Row
        for (int j = 0; j < column; j++)
        {
            bool isShow = Random.Range(0, 3) < 2 ? true : false;
            if (!usingSprite)
            {
                bricks[row - 1, j].setShow(isShow, colors[Random.Range(0, 7)]);
            }
            else
            {
                bricks[row - 1, j].setShow(isShow, sprites[Random.Range(0, 7)]);
            }
        }

        if (checkEat(row - 1))
        {
            bricks[row - 1, Random.Range(0, column)].setShow(false);
        }
    }
Esempio n. 2
0
    IEnumerator moveDown(List <int> rows, Action action, bool runWhenNotRunning)
    {
        yield return(new WaitForSeconds(deltaTimeClear));

        // Clear Row
        for (int j = 0; j < column; j++)
        {
            if (!running && !runWhenNotRunning)
            {
                yield break;
            }
            BrickController brick = bricks[rows[0], j];
            if (brick.isShow)
            {
                brick.setShow(false);
                yield return(new WaitForSeconds(deltaTimeClear));
            }
        }

        // Copy Brick
        for (int i = rows[0] - 1; i >= 0; i--)
        {
            for (int j = 0; j < column; j++)
            {
                BrickController brick = bricks[i, j];

                if (brick.isShow && !currentBricks.Contains(brick))
                {
                    brick.setShow(false);
                    if (!usingSprite)
                    {
                        bricks[i + 1, j].setShow(true, brick.color);
                    }
                    else
                    {
                        bricks[i + 1, j].setShow(true, brick.sprite);
                    }
                }
            }
        }

        // Change row eat
        int rowEat = rows[0];

        rows.RemoveAt(0);
        foreach (List <int> eatingRows in listEatingRows)
        {
            for (int i = eatingRows.Count - 1; i >= 0; i--)
            {
                if (eatingRows[i] < rowEat)
                {
                    eatingRows[i]++;
                }
                else
                {
                    break;
                }
            }
        }

        // Score
        if (running)
        {
            addScore(1);
        }

        if (rows.Count > 0)
        {
            StartCoroutine(moveDown(rows, action, runWhenNotRunning));
        }
        else
        {
            listEatingRows.Remove(rows);
            if (listEatingRows.Count == 0)
            {
                eating = false;
            }
            if (action != null)
            {
                action();
            }
        }
    }