Exemplo n.º 1
0
 /// <summary>
 /// 初始UI
 /// </summary>
 private void InitUI()
 {
     return_button.onClick.Set(OnReturnClick);
     GameManager.Instance.Sweets = new GameSweet[PlayerInfo.Instance.xColumn, PlayerInfo.Instance.yRow];
     for (int x = 0; x < PlayerInfo.Instance.xColumn; x++)
     {
         for (int y = 0; y < PlayerInfo.Instance.yRow; y++)
         {
             GameSweet gameSweet = PoolsManager.Instance.GetSweetObj();
             gameSweet.InitSweet(parents_com);
             gameSweet.SetXY(x, y);
             GameManager.Instance.Sweets[x, y] = gameSweet;
         }
     }
     GameManager.Instance.StartFill();
 }
Exemplo n.º 2
0
        public void ExchangeSweet(GameSweet sweet1, GameSweet sweet2)
        {
            if (sweet1.IsMove && sweet2.IsMove)
            {
                _sweets[sweet1.X, sweet1.Y] = sweet2;
                _sweets[sweet2.X, sweet2.Y] = sweet1;

                List <GameSweet> clearList1 = MatchSweets(sweet1, sweet2.X, sweet2.Y);
                List <GameSweet> clearList2 = MatchSweets(sweet2, sweet1.X, sweet1.Y);
                if ((clearList1.Count > 2) || (clearList2.Count > 2) || sweet1.Type == SweetsType.RAINBOWCANDY || sweet2.Type == SweetsType.RAINBOWCANDY)
                {
                    int tempX = sweet1.X;
                    int tempY = sweet1.Y;

                    sweet1.SetXY(sweet2.X, sweet2.Y);
                    sweet2.SetXY(tempX, tempY);

                    if (clearList1.Count > 2)
                    {
                        ClearSweetList(clearList1);
                    }
                    if (clearList2.Count > 2)
                    {
                        ClearSweetList(clearList2);
                    }


                    StartFill();
                    _pressSweet = null;
                    _enterSweet = null;
                }
                else
                {
                    _sweets[sweet1.X, sweet1.Y] = sweet1;
                    _sweets[sweet2.X, sweet2.Y] = sweet2;
                }
            }
        }
Exemplo n.º 3
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);
        }