Exemplo n.º 1
0
        public List <GameSweet> MatchSweets(GameSweet sweet, int currentX, int currentY)
        {
            List <GameSweet> finishedList = new List <GameSweet>();

            if (!sweet.IsClear)
            {
                return(finishedList);
            }

            ColorType        color      = sweet.Color;
            List <GameSweet> columnList = new List <GameSweet>();
            List <GameSweet> rowList    = new List <GameSweet>();

            // 列匹配
            rowList = FindRowSameSweet(sweet, currentX, currentY, color);
            rowList.Add(sweet);

            if (rowList.Count == 3)
            {
                for (int count = 0; count < rowList.Count; count++)
                {
                    GameSweet tempSweet = rowList[count];
                    // L T性匹配
                    columnList.Clear();
                    columnList = FindColumnSameSweet(tempSweet, currentX, tempSweet.Y, color);
                    if (columnList.Count >= 2)
                    {
                        tempSweet.SetSweetsType(SweetsType.EXPLOSION);
                        for (int k = 0; k < columnList.Count; k++)
                        {
                            finishedList.Add(columnList[k]);
                        }
                    }
                    else
                    {
                        finishedList.Add(tempSweet);
                    }
                }
            }
            else if (rowList.Count == 4)
            {
                bool isSuccess = false;
                for (int count = 0; count < rowList.Count; count++)
                {
                    GameSweet tempSweet = rowList[count];
                    // L T性匹配
                    columnList.Clear();
                    columnList = FindColumnSameSweet(tempSweet, currentX, tempSweet.Y, color);
                    if (columnList.Count >= 2)
                    {
                        isSuccess = true;
                        tempSweet.SetSweetsType(SweetsType.EXPLOSION);
                        for (int k = 0; k < columnList.Count; k++)
                        {
                            finishedList.Add(columnList[k]);
                        }
                    }
                    else
                    {
                        finishedList.Add(tempSweet);
                    }
                }
                if (!isSuccess)
                {
                    finishedList.Remove(sweet);
                    sweet.SetSweetsType(SweetsType.COLUMN_CLEAR);
                }
            }
            else if (rowList.Count >= 5)
            {
                for (int count = 0; count < rowList.Count; count++)
                {
                    GameSweet tempSweet = rowList[count];
                    finishedList.Add(tempSweet);
                    // L T性匹配
                    columnList.Clear();
                    columnList = FindColumnSameSweet(tempSweet, currentX, tempSweet.Y, color);
                    if (columnList.Count >= 2)
                    {
                        for (int k = 0; k < columnList.Count; k++)
                        {
                            finishedList.Add(columnList[k]);
                        }
                    }
                    else
                    {
                        finishedList.Add(tempSweet);
                    }
                }
                finishedList.Remove(sweet);
                sweet.SetSweetsType(SweetsType.RAINBOWCANDY);
            }

            if (finishedList.Count >= 3)
            {
                return(finishedList);
            }
            columnList.Clear();
            rowList.Clear();
            finishedList.Clear();

            columnList = FindColumnSameSweet(sweet, currentX, currentY, color);
            columnList.Add(sweet);
            if (columnList.Count == 3)
            {
                for (int count = 0; count < columnList.Count; count++)
                {
                    GameSweet tempSweet = columnList[count];
                    rowList.Clear();
                    rowList = FindRowSameSweet(tempSweet, tempSweet.X, currentY, color);
                    if (rowList.Count >= 2)
                    {
                        tempSweet.SetSweetsType(SweetsType.EXPLOSION);
                        for (int k = 0; k < rowList.Count; k++)
                        {
                            finishedList.Add(rowList[k]);
                        }
                    }
                    else
                    {
                        finishedList.Add(tempSweet);
                    }
                }
            }
            else if (columnList.Count == 4)
            {
                bool isSuccess = false;
                for (int count = 0; count < columnList.Count; count++)
                {
                    GameSweet tempSweet = columnList[count];
                    rowList.Clear();
                    rowList = FindRowSameSweet(tempSweet, tempSweet.X, currentY, color);
                    if (rowList.Count >= 2)
                    {
                        isSuccess = true;
                        tempSweet.SetSweetsType(SweetsType.EXPLOSION);
                        for (int k = 0; k < rowList.Count; k++)
                        {
                            finishedList.Add(rowList[k]);
                        }
                    }
                    else
                    {
                        finishedList.Add(tempSweet);
                    }
                }
                if (!isSuccess)
                {
                    finishedList.Remove(sweet);
                    sweet.SetSweetsType(SweetsType.ROW_CLEAR);
                }
            }
            else if (columnList.Count >= 5)
            {
                for (int count = 0; count < columnList.Count; count++)
                {
                    GameSweet tempSweet = columnList[count];
                    rowList.Clear();
                    rowList = FindRowSameSweet(tempSweet, tempSweet.X, currentY, color);
                    if (rowList.Count >= 2)
                    {
                        for (int k = 0; k < rowList.Count; k++)
                        {
                            finishedList.Add(rowList[k]);
                        }
                    }
                    else
                    {
                        finishedList.Add(tempSweet);
                    }
                }
                finishedList.Remove(sweet);
                sweet.SetSweetsType(SweetsType.RAINBOWCANDY);
            }
            if (finishedList.Count <= 2)
            {
                finishedList.Clear();
            }
            return(finishedList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 分布填充
        /// </summary>
        /// <returns></returns>
        public bool Fill()
        {
            // 判断本次填充是否完成
            bool isFiledNotFinished = false;

            for (int y = PlayerInfo.Instance.yRow - 2; y >= 0; y--)
            {
                for (int x = 0; x < PlayerInfo.Instance.xColumn; x++)
                {
                    GameSweet sweet = _sweets[x, y];
                    if (sweet.IsMove)
                    {
                        GameSweet sweetBelow = _sweets[x, y + 1];
                        if (sweetBelow.Type == SweetsType.EMPTY) // 垂直填充
                        {
                            sweetBelow.Hide();
                            sweet.Move(x, y + 1, fillTime);
                            _sweets[x, y + 1] = sweet;
                            _sweets[x, y]     = PoolsManager.Instance.GetSweetObj();
                            _sweets[x, y].SetXY(x, y);
                            isFiledNotFinished = true;
                        }
                        //else //斜向填充
                        //{
                        //    for (int down = -1; down <= 1; down++)
                        //    {
                        //        if (down != 0)
                        //        {
                        //            if (down != 0)
                        //            {
                        //                int downX = x + down;
                        //                if (downX >= 0 && downX < PlayerInfo.xColumn)
                        //                {
                        //                    GameSweet downSweet = _sweets[downX, y - 1];
                        //                    if (downSweet.Type == SweetsType.EMPTY)
                        //                    {
                        //                        bool canfill = true;  // 用来判断垂直填充是否满足填充需求

                        //                        for (int belowY = y; belowY <= PlayerInfo.yRow; belowY++)
                        //                        {
                        //                            GameSweet sweetUnder = _sweets[downX, belowY];

                        //                            if (sweetUnder.IsMove)
                        //                            {
                        //                                break;
                        //                            }
                        //                            else if (sweet.IsMove == false && sweet.Type != SweetsType.EMPTY)
                        //                            {
                        //                                canfill = false;
                        //                                break;
                        //                            }
                        //                        }

                        //                        if (!canfill)
                        //                        {
                        //                            sweetBelow.Hide();
                        //                            sweet.Move(downX, y + 1, fillTime);
                        //                            _sweets[downX, y + 1] = sweet;
                        //                            _sweets[downX, y] = PoolsManager.Instance.GetSweetObj();
                        //                            isFiledNotFinished = true;
                        //                        }
                        //                    }
                        //                }
                        //            }
                        //        }
                        //    }
                        //}
                    }
                }
            }
            //最上排的特殊情况
            for (int x = 0; x < PlayerInfo.Instance.xColumn; x++)
            {
                GameSweet sweet = _sweets[x, 0];
                if (sweet.Type == SweetsType.EMPTY)
                {
                    sweet.SetSweetsType(SweetsType.NORMAL);
                    sweet.SetXY(x, -1);
                    sweet.Move(x, 0, fillTime);
                    isFiledNotFinished = true;
                }
            }
            return(isFiledNotFinished);
        }