예제 #1
0
        /// <summary>
        /// Queue grouped up blocks
        /// Remove all blocks in from from pending blocks
        /// Destroy all adjacent blocks that are the same color to the group
        /// </summary>
        /// <param name="block"></param>
        /// <param name="dir"></param>
        private void QueueGroup(Block block, Direction dir)
        {
            Group      group     = block.GetGroup();
            IBreakable breakable = group.breakable;

            if (group != null && !breakableList.Contains(breakable))
            {
                breakableList.Add(breakable);
                for (int i = 0; i < group.blocks.Count; i++)
                {
                    if (!pendingBlocks.Contains(group.blocks[i]))
                    {
                        pendingBlocks.Add(group.blocks[i]);

                        QueueAdjacentBlocks(group.blocks[i], dir);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Check if both corners are touching in another group, if so, combine groups
        /// </summary>
        /// <param name="dir"></param>
        /// <returns></returns>
        public bool CanCombine(Direction dir)
        {
            Block other1 = null;
            Block other2 = null;

            Group otherGroup = null;

            switch (dir)
            {
            case Direction.up:
                other1 = data.topLeft.SameAdjacent(Direction.up);
                other2 = data.topRight.SameAdjacent(Direction.up);
                break;

            case Direction.right:
                other1 = data.topRight.SameAdjacent(Direction.right);
                other2 = data.bottomRight.SameAdjacent(Direction.right);
                break;

            case Direction.down:
                other1 = data.bottomLeft.SameAdjacent(Direction.down);
                other2 = data.bottomRight.SameAdjacent(Direction.down);
                break;

            case Direction.left:
                other1 = data.topLeft.SameAdjacent(Direction.left);
                other2 = data.bottomLeft.SameAdjacent(Direction.left);
                break;

            default:
                return(false);
            }

            if (other1 == null || other2 == null)
            {
                return(false);
            }

            //If other1 and other 2 are grouped and if they're part of the same group
            if (other1.IsGrouped() == true && other2.IsGrouped() == true && other1.GetGroup().Equals(other2.GetGroup()))
            {
                //If other blocks are corner blocks, then it can expand
                otherGroup = other1.GetGroup();

                switch (dir)
                {
                case Direction.up:
                    if (other1.Equals(otherGroup.data.bottomLeft) && other2.Equals(otherGroup.data.bottomRight))
                    {
                        return(true);
                    }
                    break;

                case Direction.right:
                    if (other1.Equals(otherGroup.data.topLeft) && other2.Equals(otherGroup.data.bottomLeft))
                    {
                        return(true);
                    }
                    break;

                case Direction.down:
                    if (other1.Equals(otherGroup.data.topLeft) && other2.Equals(otherGroup.data.topRight))
                    {
                        return(true);
                    }
                    break;

                case Direction.left:
                    if (other1.Equals(otherGroup.data.topRight) && other2.Equals(otherGroup.data.bottomRight))

                    {
                        return(true);
                    }
                    break;

                default:

                    break;
                }
            }

            return(false);
        }