예제 #1
0
        public override List <Match> OnSwap(Tile other)
        {
            List <MatchElement> elements = new List <MatchElement>();
            var me = grid.FindPos(gameObject).Value;

            elements.Add(grid.MatchElementAt(me.x, me.y));

            for (int x = 0; x < grid.Width; x++)
            {
                for (int y = 0; y < grid.Height; y++)
                {
                    var cell = grid.cells[x, y];
                    if (cell.Child.CompareTag(other.tag))
                    {
                        elements.Add(grid.MatchElementAt(x, y));
                    }
                }
            }

            var elementsArray = elements.ToArray();

            onDestroyEffect?.SpawnEffect(elementsArray);


            var matches = new List <Match>();

            matches.Add(new Match(elementsArray, false, scoreMulitplier * elements.Count));
            return(matches);
        }
예제 #2
0
        public override List <Match> OnDestroyed()
        {
            var matches = new List <Match>();


            var elements = new List <MatchElement>();
            var maybePos = grid.FindPos(gameObject);

            if (maybePos == null)
            {
                Debug.LogError("Couldnt find SquareBomb on grid at " + transform.position);
                return(matches);
            }

            var pos = maybePos.Value;

            /*
             * -  -  -  -  -
             * -  x  x  x  -
             * -  x  o  x  -
             * -  x  x  x  -
             * -  -  -  -  -
             *
             * o = bomb
             * x = to be destroyed
             * - = dont care
             *
             */

            // top row
            if (pos.y < grid.Height - 1)
            {
                elements.Add(grid.MatchElementAt(pos.x, pos.y + 1));

                if (pos.x > 0)
                {
                    elements.Add(grid.MatchElementAt(pos.x - 1, pos.y + 1));
                }

                if (pos.x < grid.Width - 1)
                {
                    elements.Add(grid.MatchElementAt(pos.x + 1, pos.y + 1));
                }
            }

            // left center
            if (pos.x > 0)
            {
                elements.Add(grid.MatchElementAt(pos.x - 1, pos.y));
            }

            // right center
            if (pos.x < grid.Width - 1)
            {
                elements.Add(grid.MatchElementAt(pos.x + 1, pos.y));
            }

            // bottom row
            if (pos.y > 0)
            {
                elements.Add(grid.MatchElementAt(pos.x, pos.y - 1));

                if (pos.x > 0)
                {
                    elements.Add(grid.MatchElementAt(pos.x - 1, pos.y - 1));
                }

                if (pos.x < grid.Width - 1)
                {
                    elements.Add(grid.MatchElementAt(pos.x + 1, pos.y - 1));
                }
            }

            // dont blow up blockers!
            var passableElements = elements.Where(it => grid.cells[it.i, it.j].IsPassable).ToArray();


            onDestroyEffect?.SpawnEffect(passableElements);

            matches.Add(new Match(passableElements, false, squareBombScore));

            return(matches);
        }