public static List <Block> GetTargetBlocksForRemoval(Cell cell, OnClickDestruction onDest, LevelData levelData, Cell[,] map)
        {
            List <Block> resBlocks = new List <Block>();

            if (onDest.TargetAllBoard)
            {
                DoForEachCell((c, x, y) =>
                {
                    BlockColor col = c.Block.BlockParams.Color;
                    if (col != null && col == onDest.OverrideTargetColor)
                    {
                        resBlocks.Add(c.Block);
                    }
                }, levelData, map);
            }

            if (onDest.TargetBlocks == null || onDest.TargetBlocks.Count <= 0)
            {
                return(resBlocks);
            }

            foreach (var cellPos in onDest.TargetBlocks)
            {
                var pos            = GetPosDueToTargetOffset(cell.BoardPos, cellPos);
                var cellWithTarget = GetCell(pos.x, pos.y,
                                             levelData, map, false);
                if (cellWithTarget != null && resBlocks.Contains(cellWithTarget.Block) == false)
                {
                    resBlocks.Add(cellWithTarget.Block);
                }
            }
            return(resBlocks);
        }
Exemple #2
0
        private List <Block> SearchColorLink(Block block, BlockColor useOtherColor = null)
        {
            List <Block> foundBlocks  = new List <Block>();
            List <Block> toSearchIn   = new List <Block>();
            BlockColor   currentColor = useOtherColor == null ? block.BlockParams.Color : useOtherColor;

            Block currentBlock = block;

            FindProperColorNeighbourBlocks(foundBlocks, currentBlock, currentColor, toSearchIn);

            while (toSearchIn.Count > 0)
            {
                currentBlock = toSearchIn[toSearchIn.Count - 1];
                FindProperColorNeighbourBlocks(foundBlocks, currentBlock, currentColor, toSearchIn);

                toSearchIn.Remove(currentBlock);
            }
            return(foundBlocks);
        }
Exemple #3
0
        private void FindProperColorNeighbourBlocks(List <Block> foundBlocks, Block currentBlock, BlockColor currentColor,
                                                    List <Block> toSearchIn)
        {
            foundBlocks.Add(currentBlock);
            foreach (var node in _graph[currentBlock.Cell.BoardX, currentBlock.Cell.BoardY].Neighbours)
            {
                if (GetCell(node.Pos).IsEmpty)
                {
                    continue;
                }

                if (GetCell(node.Pos).Block.BlockParams.Color == currentColor &&
                    toSearchIn.Contains(GetCell(node.Pos).Block) == false &&
                    foundBlocks.Contains(GetCell(node.Pos).Block) == false)
                {
                    toSearchIn.Add(GetCell(node.Pos).Block);
                }
            }
        }