示例#1
0
    void RemoveGrid()//
    {
        Debug.Log("开始消除");
        for (int x = 0; x < xl; x++)
        {
            for (int y = 0; y < yl; y++)
            {
                if (Comparator(GetGridID(x, y), GetGridID(x, y + 1), GetGridID(x, y + 2)) &&
                    DicGrid[GetGridID(x, y)].GridType <= 5)
                {
                    if (!RemoveGridList.Contains(DicGrid[GetGridID(x, y)]))
                    {
                        RemoveGridList.Add(DicGrid[GetGridID(x, y)]);
                    }
                    if (!RemoveGridList.Contains(DicGrid[GetGridID(x, y + 1)]))
                    {
                        RemoveGridList.Add(DicGrid[GetGridID(x, y + 1)]);
                    }
                    if (!RemoveGridList.Contains(DicGrid[GetGridID(x, y + 2)]))
                    {
                        RemoveGridList.Add(DicGrid[GetGridID(x, y + 2)]);
                    }
                }
                if (Comparator(GetGridID(x, y), GetGridID(x + 1, y), GetGridID(x + 2, y)) &&
                    DicGrid[GetGridID(x, y)].GridType <= 5)
                {
                    if (!RemoveGridList.Contains(DicGrid[GetGridID(x, y)]))
                    {
                        RemoveGridList.Add(DicGrid[GetGridID(x, y)]);
                    }
                    if (!RemoveGridList.Contains(DicGrid[GetGridID(x + 1, y)]))
                    {
                        RemoveGridList.Add(DicGrid[GetGridID(x + 1, y)]);
                    }
                    if (!RemoveGridList.Contains(DicGrid[GetGridID(x + 2, y)]))
                    {
                        RemoveGridList.Add(DicGrid[GetGridID(x + 2, y)]);
                    }
                }
            }
        }

        if (RemoveGridList.Count > 0)
        {
            Global.instance.SoundManager.PlayAudio("GridRemoveSound");

            Debug.Log("继续消除!");

            timeCounter.AddCombo();   //检查连击计数器

            numScore = RemoveGridList.Count * timeCounter.GetComboMultiple() + numScore;

            GameTime = GameTime + timeIncrement + 1 >= GameTimeAll ? GameTimeAll : GameTime + timeIncrement + 1;

            mScore.text = "积分:" + numScore;
            if (RemoveGridList.Count >= 4)
            {
                GridUnit bomb = RemoveGridList[0];
                bomb.SetBomb();
                RemoveGridList.RemoveAt(0);
            }
            for (int i = 0; i < RemoveGridList.Count; i++)
            {
                if (RemoveGridList[i].isBomb)
                {
                    bool b = System.Convert.ToBoolean(Random.Range(0f, 1f));
                    int  j = RemoveGridList[i].GridId;
                    if (b)
                    {
                        while (DicGrid.ContainsKey(GetUp(j)))
                        {
                            RemoveGridList.Add(DicGrid[GetUp(j)]);
                            j = GetUp(j);
                        }
                        j = RemoveGridList[i].GridId;
                        while (DicGrid.ContainsKey(GetDown(j)))
                        {
                            RemoveGridList.Add(DicGrid[GetDown(j)]);
                            j = GetDown(j);
                        }
                    }
                    else
                    {
                        while (DicGrid.ContainsKey(GetRight(j)))
                        {
                            RemoveGridList.Add(DicGrid[GetRight(j)]);
                            j = GetRight(j);
                        }
                        j = RemoveGridList[i].GridId;
                        while (DicGrid.ContainsKey(GetLeft(j)))
                        {
                            RemoveGridList.Add(DicGrid[GetLeft(j)]);
                            j = GetLeft(j);
                        }
                    }
                }

                if (RemoveGridList[i].GridId == 6)
                {
                    Debug.Log("跳过删除墙部分"); continue;
                }

                if (RemoveGridList[i].GridId != 8 && iceDicGrid.ContainsKey(RemoveGridList[i].GridId)) //如果消除的不是冰块
                {
                    iceDicGrid[RemoveGridList[i].GridId].MinusHp();
                    if (iceDicGrid[RemoveGridList[i].GridId].isDead())
                    {
                        Debug.Log(iceDicGrid[RemoveGridList[i].GridId].name);
                        Destroy(iceDicGrid[RemoveGridList[i].GridId].gameObject);
                        iceDicGrid.Remove(RemoveGridList[i].GridId);
                    }
                }
                if (RemoveGridList[i].GridType != 8 && RemoveGridList[i].GridType != 7)
                {
                    CheckIceColumn(RemoveGridList[i].GridId);   //检查冰柱
                }
                DicGrid.Remove(RemoveGridList[i].GridId);
                Destroy(RemoveGridList[i].gameObject);
            }//end for
            CurrentClickGrid = null;
            LastClickGrid    = null;
            RemoveGridList.Clear();
        }
        else
        {
            Debug.Log("循环结束!");
            if (LastClickGrid && CurrentClickGrid)
            {
                LastClickGrid.MoveGrid(LastClickGrid, CurrentClickGrid);
            }
            CurrentClickGrid = null;
            LastClickGrid    = null;
            return;
        }
        AllGridMoveDown();
    }