コード例 #1
0
        /// <summary>
        /// Return gridcells group with id matched bubbles around free gridcell
        /// </summary>
        /// <param name="freeGCell"></param>
        /// <returns></returns>
        public MatchGroup GetIdArea(GridCell freeGCell, int id)
        {
            MatchGroup res        = new MatchGroup();
            MatchGroup equalNeigh = new MatchGroup();
            MatchGroup neighTemp;

            if (freeGCell)
            {
                NeighBors nCells = new NeighBors(freeGCell, id); // res.Add(freeGCell);
                equalNeigh.AddRange(nCells.EqualIDCells);        //equalNeigh.AddRange(gCell.EqualNeighBornCells());
                while (equalNeigh.Length > 0)
                {
                    res.AddRange(equalNeigh.cells);
                    neighTemp = new MatchGroup();
                    foreach (var item in equalNeigh.cells)
                    {
                        nCells = new NeighBors(item, id);
                        neighTemp.AddRange(nCells.EqualIDCells); // neighTemp.AddRange(item.EqualNeighBornCells());
                    }
                    equalNeigh = neighTemp;
                    equalNeigh.Remove(res.cells);
                }
            }
            res.Remove(freeGCell);
            return(res);
        }
コード例 #2
0
 public void CreateNeighBorns()
 {
     if (gCell == null)
     {
         return;
     }
     Neighbors = new NeighBors(gCell);
 }
コード例 #3
0
ファイル: BombCombiner.cs プロジェクト: dqchess/Tap-Match
        private List <DynamicClickBombObject> GetNeighBombs(GridCell gCell)
        {
            List <DynamicClickBombObject> res = new List <DynamicClickBombObject>();
            NeighBors nG = gCell.Neighbors;

            foreach (var item in nG.Cells) // search color bomb
            {
                if (item.DynamicClickBomb)
                {
                    res.Add(item.DynamicClickBomb);
                }
            }
            return(res);
        }
コード例 #4
0
ファイル: NeighBors.cs プロジェクト: dqchess/Tap-Match
        /// <summary>
        /// Create NeighBorns  cells
        /// </summary>
        /// <param name="main"></param>
        /// <param name="id"></param>
        public NeighBors(NeighBors nB)
        {
            Main   = nB.Main;
            Left   = nB.Left;
            Right  = nB.Right;
            Top    = nB.Top;
            Bottom = nB.Bottom;

            Cells = new List <GridCell>();

            TopLeft     = nB.TopLeft;
            BottomLeft  = nB.BottomLeft;
            TopRight    = nB.TopRight;
            BottomRight = nB.BottomRight;

            if (Top)
            {
                Cells.Add(Top);
            }
            if (TopLeft)
            {
                Cells.Add(TopLeft);
            }
            if (Left)
            {
                Cells.Add(Left);
            }
            if (BottomLeft)
            {
                Cells.Add(BottomLeft);
            }

            if (Bottom)
            {
                Cells.Add(Bottom);
            }
            if (BottomRight)
            {
                Cells.Add(BottomRight);
            }
            if (Right)
            {
                Cells.Add(Right);
            }
            if (TopRight)
            {
                Cells.Add(TopRight);
            }
        }
コード例 #5
0
ファイル: GridCell.cs プロジェクト: dqchess/Tap-Match
        /// <summary>
        ///  used by instancing for cache data
        /// </summary>
        internal void Init(int cellRow, int cellColumn, Column <GridCell> column, Row <GridCell> row, GameMode gMode)
        {
            IsDisabled = false;
            Row        = cellRow;
            Column     = cellColumn;
            GColumn    = column;
            GRow       = row;
            this.gMode = gMode;
#if UNITY_EDITOR
            name = ToString();
#endif
            sRenderer = GetComponent <SpriteRenderer>();
            sRenderer.sortingOrder = SortingOrder.Base;
            Neighbors = new NeighBors(this, false);
        }
コード例 #6
0
        public override CellsGroup GetArea(GridCell hitGridCell)
        {
            CellsGroup      cG   = new CellsGroup();
            List <GridCell> area = new NeighBors(hitGridCell, true).Cells;

            cG.Add(hitGridCell);
            foreach (var item in area)
            {
                if (hitGridCell.IsMatchObjectEquals(item) && item.IsMatchable)
                {
                    cG.Add(item);
                }
            }

            return(cG);
        }
コード例 #7
0
        /// <summary>
        /// Return all closed not intersected areas
        /// </summary>
        /// <returns></returns>
        public List <GridCell> GetDetacheCells()
        {
            CellsGroup main  = new CellsGroup(); // main group from 0 row
            CellsGroup neigh = new CellsGroup();
            CellsGroup neighTemp;

            main.AddRange(Rows[serviceRowsCount].GetNotEmptyCells()); // start at service rows
            NeighBors nCells;

            for (int i = 0; i < main.Length; i++)
            {
                nCells = new NeighBors(main.cells[i]);
                neigh.AddRange(nCells.NotEmptyCells);// neigh.AddRange(main.cells[i].NotEmptyNeighBornCells());
            }

            while (neigh.Length > 0) // find and add to group not empty neighborns
            {
                main.AddRange(neigh.cells);
                neighTemp = new CellsGroup();
                foreach (var item in neigh.cells)
                {
                    nCells = new NeighBors(item);
                    neighTemp.AddRange(nCells.NotEmptyCells);
                }
                neigh = neighTemp;
                neigh.Remove(main.cells);
            }

            CellsGroup all = new CellsGroup();

            all.AddRange(GetNotEmptyCells());

            all.Remove(main.cells);
            // Debug.Log("detouched: " + all.ToString());
            return(all.cells);
        }
コード例 #8
0
ファイル: BombCombiner.cs プロジェクト: dqchess/Tap-Match
        private DynamicClickBombObjectData sourceColorBombData; // need only for color bomb

        public void CombineAndExplode(GridCell gCell, DynamicClickBombObject bomb, Action completeCallBack)
        {
            if (!gCell || !bomb)
            {
                completeCallBack?.Invoke();
                return;
            }

            NeighBors   nG  = gCell.Neighbors;
            BombDir     bd1 = bomb.GetBombDir();
            BombCombine bC  = BombCombine.None;
            List <DynamicClickBombObject> nBs = GetNeighBombs(gCell);

            if (bomb.GetBombDir() == BombDir.Color)
            {
                sourceColorBombData = bomb.OData;
            }

            foreach (var item in nBs) // search color bomb
            {
                BombDir bd2 = item.GetBombDir();
                if (bd2 == BombDir.Color)
                {
                    if (sourceColorBombData == null)
                    {
                        sourceColorBombData = item.OData;
                    }
                    bC = GetCombineType(bd1, bd2);
                    break;
                }
            }

            if (bC == BombCombine.None) // search radial bomb
            {
                foreach (var item in nBs)
                {
                    BombDir bd2 = item.GetBombDir();
                    if (bd2 == BombDir.Radial)
                    {
                        bC = GetCombineType(bd1, bd2);
                        break;
                    }
                }
            }

            if (bC == BombCombine.None) // search hor or vert bomb
            {
                foreach (var item in nBs)
                {
                    BombDir bd2 = item.GetBombDir();
                    if (bd2 == BombDir.Horizontal || bd2 == BombDir.Vertical)
                    {
                        bC = GetCombineType(bd1, bd2);
                        break;
                    }
                }
            }

            switch (bC)
            {
            case BombCombine.ColorBombAndColorBomb:         // clean full board
                collectTween = new ParallelTween();
                nBs.Add(bomb);
                foreach (var item in nBs)
                {
                    item.transform.parent = null;
                    item.SetToFront(true);
                    Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1);
                    collectTween.Add((callBack) =>
                    {
                        item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject); callBack(); });
                    });
                }
                collectTween.Start(() =>
                {
                    MSound.SoundPlayMakeBomb(0.05f, null);
                    CombinedColorBombAndColorBomb bigBomb = Instantiate(colorBombAndColorBombPrefab);
                    bigBomb.transform.localScale          = gCell.transform.lossyScale;
                    bigBomb.transform.position            = gCell.transform.position;
                    bigBomb.ApplyToGrid(gCell, 0.2f, completeCallBack);
                });

                break;

            case BombCombine.BombAndBomb:                   // big bomb explode
                collectTween = new ParallelTween();
                nBs.Add(bomb);
                foreach (var item in nBs)
                {
                    item.transform.parent = null;
                    item.SetToFront(true);
                    Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1);
                    collectTween.Add((callBack) =>
                    {
                        item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject); callBack(); });
                    });
                }
                collectTween.Start(() =>
                {
                    MSound.SoundPlayMakeBomb(0.05f, null);
                    CombinedBombAndBomb bigBomb  = Instantiate(bombAndBombPrefab);
                    bigBomb.transform.localScale = gCell.transform.lossyScale;
                    bigBomb.transform.position   = gCell.transform.position;
                    bigBomb.ApplyToGrid(gCell, 0.2f, completeCallBack);
                });
                break;

            case BombCombine.RocketAndRocket:               // 2 rows or 2 columns
                collectTween = new ParallelTween();
                nBs.Add(bomb);
                foreach (var item in nBs)
                {
                    item.transform.parent = null;
                    item.SetToFront(true);
                    Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1);
                    collectTween.Add((callBack) =>
                    {
                        item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject, 0.2f); callBack(); });
                    });
                }
                collectTween.Start(() =>
                {
                    MSound.SoundPlayMakeBomb(0.05f, null);
                    CombinedRocketAndRocket bigBomb = Instantiate(rocketAndRocketPrefab);
                    bigBomb.transform.localScale    = gCell.transform.lossyScale;
                    bigBomb.transform.position      = gCell.transform.position;
                    bigBomb.ApplyToGrid(gCell, 0.2f, completeCallBack);
                });
                break;

            case BombCombine.ColorBombAndBomb:              // replace color match with bomb
                collectTween = new ParallelTween();
                nBs.Add(bomb);

                foreach (var item in nBs)
                {
                    item.transform.parent = null;
                    item.SetToFront(true);
                    Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1);
                    collectTween.Add((callBack) =>
                    {
                        item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject); callBack(); });
                    });
                }
                collectTween.Start(() =>
                {
                    MSound.SoundPlayMakeBomb(0.05f, null);
                    CombinedColorBombAndBomb colorBombAndBomb = Instantiate(colorBombAndBombPrefab);
                    colorBombAndBomb.transform.localScale     = gCell.transform.lossyScale;
                    colorBombAndBomb.transform.position       = gCell.transform.position;
                    colorBombAndBomb.OData = sourceColorBombData;
                    colorBombAndBomb.ApplyToGrid(gCell, 0.2f, completeCallBack);
                    colorBombAndBomb.GetComponent <SpriteRenderer>().sprite = sourceColorBombData.ObjectImage;
                });

                break;

            case BombCombine.BombAndRocket:                 // 3 rows and 3 columns
                collectTween = new ParallelTween();
                nBs.Add(bomb);
                foreach (var item in nBs)
                {
                    item.transform.parent = null;
                    item.SetToFront(true);
                    Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1);
                    collectTween.Add((callBack) =>
                    {
                        item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject); callBack(); });
                    });
                }
                collectTween.Start(() =>
                {
                    MSound.SoundPlayMakeBomb(0.05f, null);
                    CombinedBombAndRocket bombAndRocket = Instantiate(bombAndRocketPrefab);
                    bombAndRocket.transform.localScale  = gCell.transform.lossyScale;
                    bombAndRocket.transform.position    = gCell.transform.position;
                    bombAndRocket.ApplyToGrid(gCell, 0.2f, completeCallBack);
                });
                break;

            case BombCombine.ColorBombAndRocket:            // replace color bomb with rockets
                collectTween = new ParallelTween();
                nBs.Add(bomb);

                foreach (var item in nBs)
                {
                    item.transform.parent = null;
                    item.SetToFront(true);
                    Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1);
                    collectTween.Add((callBack) =>
                    {
                        item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject); callBack(); });
                    });
                }
                collectTween.Start(() =>
                {
                    MSound.SoundPlayMakeBomb(0.05f, null);
                    CombinedColorBombAndRocket colorBombAndRocket = Instantiate(colorBombAndRocketPrefab);
                    colorBombAndRocket.transform.localScale       = gCell.transform.lossyScale;
                    colorBombAndRocket.transform.position         = gCell.transform.position;
                    colorBombAndRocket.OData = sourceColorBombData;
                    colorBombAndRocket.ApplyToGrid(gCell, 0.2f, completeCallBack);
                    colorBombAndRocket.GetComponent <SpriteRenderer>().sprite = sourceColorBombData.ObjectImage;
                });
                break;

            case BombCombine.None:                          // simple explode
                gCell.ExplodeBomb(0.0f, true, true, bd1 == BombDir.Color, false, () =>
                {
                    completeCallBack?.Invoke();
                });
                break;

            default:
                completeCallBack?.Invoke();
                break;
            }
        }
コード例 #9
0
        internal override void PlayExplodeAnimation(GridCell gCell, float delay, Action completeCallBack)
        {
            if (!gCell || explodePrefab == null)
            {
                completeCallBack?.Invoke();
            }
            // Debug.Log(name + "play explode animation");
            TweenSeq anim = new TweenSeq();

            pT      = new ParallelTween();
            rockets = new List <DynamicClickBombObject>();

            anim.Add((callBack) => // delay
            {
                delayAction(gameObject, delay, callBack);
            });

            anim.Add((callBack) => // scale out
            {
                SimpleTween.Value(gameObject, 1, 1.5f, 0.2f).SetOnUpdate((float val) => { transform.localScale = gCell.transform.lossyScale * val; }).AddCompleteCallBack(callBack);
            });

            anim.Add((callBack) => // scale in and explode prefab
            {
                SimpleTween.Value(gameObject, 1.5f, 1.0f, 0.15f).SetOnUpdate((float val) => { transform.localScale = gCell.transform.lossyScale * val; }).AddCompleteCallBack(callBack);
                GameObject g           = Instantiate(explodePrefab);
                g.transform.position   = transform.position;
                g.transform.localScale = transform.localScale * .50f;
            });

            anim.Add((callBack) => // create rockets
            {
                NeighBors nB = gCell.Neighbors;
                if (nB.Left)
                {
                    DynamicClickBombObject rL = DynamicClickBombObject.Create(nB.Left, GOSet.GetDynamicClickBombObject(BombDir.Vertical, 0), false, false, MBoard.TargetCollectEventHandler);
                    rL.transform.parent       = null;
                    rL.SetToFront(true);
                    GridCell c1 = nB.Left;
                    pT.Add((cB) =>
                    {
                        ExplodeRocket(rL, c1, 0, cB);
                    });
                    rockets.Add(rL);
                }
                if (nB.Right)
                {
                    DynamicClickBombObject rR = DynamicClickBombObject.Create(nB.Right, GOSet.GetDynamicClickBombObject(BombDir.Vertical, 0), false, false, MBoard.TargetCollectEventHandler);
                    rR.transform.parent       = null;
                    rR.SetToFront(true);
                    GridCell c2 = nB.Right;
                    pT.Add((cB) =>
                    {
                        ExplodeRocket(rR, c2, 0, cB);
                    });
                    rockets.Add(rR);
                }
                if (nB.Top)
                {
                    DynamicClickBombObject rT = DynamicClickBombObject.Create(nB.Top, GOSet.GetDynamicClickBombObject(BombDir.Horizontal, 0), false, false, MBoard.TargetCollectEventHandler);
                    rT.transform.parent       = null;
                    rT.SetToFront(true);
                    GridCell c3 = nB.Top;
                    pT.Add((cB) =>
                    {
                        ExplodeRocket(rT, c3, 0, cB);
                    });
                    rockets.Add(rT);
                }
                if (nB.Bottom)
                {
                    DynamicClickBombObject rB = DynamicClickBombObject.Create(nB.Bottom, GOSet.GetDynamicClickBombObject(BombDir.Horizontal, 0), false, false, MBoard.TargetCollectEventHandler);
                    rB.transform.parent       = null;
                    rB.SetToFront(true);
                    GridCell c4 = nB.Bottom;
                    pT.Add((cB) =>
                    {
                        ExplodeRocket(rB, c4, 0, cB);
                    });
                    rockets.Add(rB);
                }

                DynamicClickBombObject r1 = DynamicClickBombObject.Create(gCell, GOSet.GetDynamicClickBombObject(BombDir.Horizontal, 0), false, false, MBoard.TargetCollectEventHandler);
                r1.transform.parent       = null;
                r1.SetToFront(true);
                pT.Add((cB) =>
                {
                    ExplodeRocket(r1, gCell, 0, cB);
                });
                rockets.Add(r1);
                DynamicClickBombObject r2 = DynamicClickBombObject.Create(gCell, GOSet.GetDynamicClickBombObject(BombDir.Vertical, 0), false, false, MBoard.TargetCollectEventHandler);
                r2.transform.parent       = null;
                r2.SetToFront(true);
                pT.Add((cB) =>
                {
                    ExplodeRocket(r2, gCell, 0, cB);
                });
                rockets.Add(r2);

                callBack();
            });

            anim.Add((callBack) => // explode wave
            {
                MBoard.ExplodeWave(0, transform.position, 5, null);
                callBack();
            });

            anim.Add((callBack) => // explode sound
            {
                MSound.PlayClip(0, explodeClip);
                callBack();
            });

            anim.Add((callBack) => // delay
            {
                delayAction(gameObject, 0, callBack);
            });

            anim.Add((callBack) =>
            {
                completeCallBack?.Invoke();
                callBack();
            });

            anim.Start();
        }
コード例 #10
0
ファイル: GridCell.cs プロジェクト: dqchess/Tap-Match
        public void CreateBorder()
        {
            if (Left && LeftBotCorner)
            {
                if (!Neighbors.Left || Neighbors.Left.IsDisabled)
                {
                    SpriteRenderer srL = Creator.CreateSprite(transform, Left, new Vector3(LeftBotCorner.position.x, transform.position.y, transform.position.z), 1);
                    srL.name = "Left border: " + ToString();
                }
            }
            if (Right && RightBotCorner)
            {
                if (!Neighbors.Right || Neighbors.Right.IsDisabled)
                {
                    SpriteRenderer srR = Creator.CreateSprite(transform, Right, new Vector3(RightBotCorner.position.x, transform.position.y, transform.position.z), 1);
                    srR.name = "Right border: " + ToString();
                }
            }
            if (Top && RightTopCorner)
            {
                if (!Neighbors.Top || Neighbors.Top.IsDisabled)
                {
                    SpriteRenderer srT = Creator.CreateSprite(transform, Top, new Vector3(transform.position.x, RightTopCorner.position.y, transform.position.z), 1);
                    srT.name = "Top border: " + ToString();
                }
            }
            if (Bottom && RightBotCorner)
            {
                if (!Neighbors.Bottom || Neighbors.Bottom.IsDisabled)
                {
                    SpriteRenderer srB = Creator.CreateSprite(transform, Bottom, new Vector3(transform.position.x, RightBotCorner.position.y, transform.position.z), 1);
                    srB.name = "Bottom border: " + ToString();
                }
            }

            if (OutTopLeft && LeftTopCorner)
            {
                if ((!Neighbors.Left || Neighbors.Left.IsDisabled) && (!Neighbors.Top || Neighbors.Top.IsDisabled))
                {
                    SpriteRenderer srTL = Creator.CreateSprite(transform, OutTopLeft, LeftTopCorner.position, 1);
                    srTL.name = "OutTopLeft border: " + ToString();
                }
            }

            if (OutBotLeft && LeftBotCorner)
            {
                if ((!Neighbors.Left || Neighbors.Left.IsDisabled) && (!Neighbors.Bottom || Neighbors.Bottom.IsDisabled))
                {
                    SpriteRenderer sr = Creator.CreateSprite(transform, OutBotLeft, LeftBotCorner.position, 1);
                    sr.name = "OutBotLeft border: " + ToString();
                }
            }

            if (OutBotRight && RightBotCorner)
            {
                if ((!Neighbors.Right || Neighbors.Right.IsDisabled) && (!Neighbors.Bottom || Neighbors.Bottom.IsDisabled))
                {
                    SpriteRenderer sr = Creator.CreateSprite(transform, OutBotRight, RightBotCorner.position, 1);
                    sr.name = "OutBotLeft border: " + ToString();
                }
            }
            if (OutTopRight && RightTopCorner)
            {
                if ((!Neighbors.Right || Neighbors.Right.IsDisabled) && (!Neighbors.Top || Neighbors.Top.IsDisabled))
                {
                    SpriteRenderer sr = Creator.CreateSprite(transform, OutTopRight, RightTopCorner.position, 1);
                    sr.name = "OutBotLeft border: " + ToString();
                }
            }

            NeighBors n = new NeighBors(this, true);

            if (InTopLeft && LeftTopCorner)
            {
                if ((!Neighbors.Left || Neighbors.Left.IsDisabled) && n.TopLeft && !n.TopLeft.IsDisabled)
                {
                    SpriteRenderer sr = Creator.CreateSprite(transform, InTopLeft, LeftTopCorner.position, 2);
                    sr.name = "InTopLeft border: " + ToString();
                }
            }

            if (InBotLeft && LeftBotCorner)
            {
                if ((!Neighbors.Left || Neighbors.Left.IsDisabled) && n.BottomLeft && !n.BottomLeft.IsDisabled)
                {
                    SpriteRenderer sr = Creator.CreateSprite(transform, InBotLeft, LeftBotCorner.position, 2);
                    sr.name = "InBotLeft border: " + ToString();
                }
            }

            if (InTopRight && RightTopCorner)
            {
                if ((!Neighbors.Right || Neighbors.Right.IsDisabled) && n.TopRight && !n.TopRight.IsDisabled)
                {
                    SpriteRenderer sr = Creator.CreateSprite(transform, InTopRight, RightTopCorner.position, 2);
                    sr.name = "InTopRight border: " + ToString();
                }
            }

            if (InBotRight && RightBotCorner)
            {
                if ((!Neighbors.Right || Neighbors.Right.IsDisabled) && n.BottomRight && !n.BottomRight.IsDisabled)
                {
                    SpriteRenderer sr = Creator.CreateSprite(transform, InBotRight, RightBotCorner.position, 2);
                    sr.name = "InBotRight border: " + ToString();
                }
            }
        }