コード例 #1
0
 public void ResetGame()
 {
     ClearAllBlocks();
     LeftColors = new List <int>();
     for (int i = 0; i < GameManager.Instance.ColorNum; i++)
     {
         LeftColors.Add(i);
     }
     NewLineGenerator.GenerateNewGrid();
     StartPosition = new Vector3(0f, GameManager.Instance.Height / 2 + 3, InitZ);
     creatNewBlockGroup();
 }
コード例 #2
0
ファイル: GameManager.cs プロジェクト: Biang2016/BiangBlock
    private void NewGame(HardLevel hardlevel)
    {
        GameState      = GameStates.Playing;
        Time.timeScale = 1f;
        initializeScoreCanvas();
        LevelSelectCanvas.SetActive(false);
        ScoreCanvas.SetActive(true);
        NewLineGenerator.Initialize();
        BlocksManager.Instance.ResetGame();
        switch (hardlevel)
        {
        case HardLevel.Easy:
            BlocksManager.Instance.AddLinesOfBlock(3); break;

        case HardLevel.Hard:
            BlocksManager.Instance.AddLinesOfBlock(4); break;

        case HardLevel.Nightmare:
            BlocksManager.Instance.AddLinesOfBlock(5); break;
        }
    }
コード例 #3
0
    public void AddLineOfBlock()
    {
        if (GameManager.Instance.GameState == GameManager.GameStates.GameOver)
        {
            return;
        }
        bool isGameOver = false;

        if (currentBlockGroup)
        {
            currentBlockGroup.down(false);
        }

        //整体上移
        for (int i = Grid.GetLength(0) - 1; i >= 0; i--)
        {
            for (int j = Grid.GetLength(1) - 1; j > 0; j--)
            {
                if (j == Grid.GetLength(1) - 1 && Grid[i, j] != -1)
                {
                    isGameOver = true;
                }
                Grid[i, j] = Grid[i, j - 1];
            }
        }

        int[] newline = NewLineGenerator.GetNewLine();
        //创建新的行
        for (int i = 0; i < Grid.GetLength(0); i++)
        {
            Grid[i, 0] = newline[i];
        }

        //整体上移
        for (int i = Grid.GetLength(0) - 1; i >= 0; i--)
        {
            for (int j = Grid.GetLength(1) - 1; j >= 0; j--)
            {
                if (Blocks[i, j])
                {
                    Blocks[i, j].RefreshGridPosition(new int[] { i, j + 1 });
                }
                if (j > 0)
                {
                    Blocks[i, j] = Blocks[i, j - 1];
                }
            }
        }

        //创建新的行
        for (int i = 0; i < Grid.GetLength(0); i++)
        {
            if (Grid[i, 0] != -1)
            {
                Blocks[i, 0] = GameObjectPoolManager.Instance.Pool_BlockPool[Grid[i, 0]].AllocateGameObject <Block>(transform);
                Blocks[i, 0].InitiateBlockByGridPosition(Grid[i, 0], new int[] { i, 0 });
            }
            else
            {
                Blocks[i, 0] = null;
            }
        }

        if (isGameOver)
        {
            GameManager.Instance.GameOver();
        }
    }
コード例 #4
0
    private void EliminateAColorOfBlocks(int colorIndex)
    {
        LeftColors.Remove(colorIndex);
        if (LeftColors.Count > 0)
        {
            NewLineGenerator.GenerateNewGrid();
            NewLineGenerator.IncreaseHardLevel(5);//生成方块的杂乱等级,随着游戏过程中某种颜色方块被清除而增加
        }

        AudioManager.Instance.SoundPlay("OnBreak");
        StartCoroutine(Co_TimeScaleSlow(0.3f));
        if (LeftColors.Count != 0)
        {
            GameManager.Instance.CongratulationTextFly();
        }

        List <Block> removeMegaBlocks = new List <Block>();

        foreach (Block b in MegaBlocks)
        {
            if (b && b.ColorIndex == colorIndex)
            {
                removeMegaBlocks.Add(b);
            }
        }
        foreach (Block b in removeMegaBlocks)
        {
            RemoveMegaBlockAndChildren(b);
        }

        List <Block> removeBlocks = new List <Block>();

        foreach (Block b in Blocks)
        {
            if (b && b.ColorIndex == colorIndex)
            {
                removeBlocks.Add(b);
            }
        }
        foreach (Block b in removeBlocks)
        {
            b.removeBlock();
        }

        if (currentBlockGroup != null)
        {
            List <Block> removeCurrentBlocks = new List <Block>();
            foreach (Block b in currentBlockGroup.bList)
            {
                removeCurrentBlocks.Add(b);
            }
            foreach (Block b in removeCurrentBlocks)
            {
                currentBlockGroup.RemoveBlockFromGroup(b);
                b.removeBlock();
            }
            currentBlockGroup.PoolRecycle();
            creatNewBlockGroup();
        }

        List <BlockGroup> removeCurrentBgs = new List <BlockGroup>();

        foreach (BlockGroup bg in currentBlockGroupPieces)
        {
            List <Block> removeCurrentBlocks = new List <Block>();
            foreach (Block b in bg.bList)
            {
                if (b.ColorIndex == colorIndex)
                {
                    removeCurrentBlocks.Add(b);
                }
            }
            foreach (Block b in removeCurrentBlocks)
            {
                bg.RemoveBlockFromGroup(b);
                b.removeBlock();
            }
            if (bg.bList.Count == 0)
            {
                removeCurrentBgs.Add(bg);
            }
        }

        foreach (BlockGroup bg in removeCurrentBgs)
        {
            currentBlockGroupPieces.Remove(bg);
            bg.PoolRecycle();
        }

        //进行一次全block核对,因为有bug还没修复
        for (int i = 0; i < Grid.GetLength(0); i++)
        {
            for (int j = 0; j < Grid.GetLength(1); j++)
            {
                if (Grid[i, j] == -1)
                {
                    if (Blocks[i, j] != null)
                    {
                        Blocks[i, j].PoolRecycle();
                    }
                }
                else
                {
                    if (Blocks[i, j] == null || Blocks[i, j].gridPosition[0] != i || Blocks[i, j].gridPosition[1] != j)
                    {
                        if (Blocks[i, j])
                        {
                            Blocks[i, j].PoolRecycle();
                        }
                        if (Grid[i, j] == -2)
                        {
                            Blocks[i, j] = GameObjectPoolManager.Instance.Pool_BreakBlockPool.AllocateGameObject <Block>(transform);
                        }
                        else
                        {
                            Blocks[i, j] = GameObjectPoolManager.Instance.Pool_BlockPool[Grid[i, j]].AllocateGameObject <Block>(transform);
                        }
                        Blocks[i, j].InitiateBlockByGridPosition(Grid[i, j], new int[] { i, j });
                    }
                }
            }
        }

        if (LeftColors.Count == 0)
        {
            GameManager.Instance.GameWin();
        }
        else
        {
            RefreshGrid();
        }
    }