예제 #1
0
        /// <summary>
        /// Adds a block to breakable list and pending blocks
        /// </summary>
        public bool QueueBlockToBreak(Block block)
        {
            bool status = false;

            if (block.IsGrouped() == false)
            {
                if (!breakableList.Contains(block.breakable))
                {
                    breakableList.Add(block.breakable);
                    status = true;
                }
            }
            else if (block.IsGrouped() == true)
            {
                QueueGroup(block, Direction.none);
                status = true;
            }

            if (!pendingBlocks.Contains(block))
            {
                pendingBlocks.Add(block);
                status = true;
            }

            return(status);
        }
예제 #2
0
        private void CompareAndBreak(Block block, Block other, Direction dir)
        {
            if (block.SameColor(other))
            {
                if (block.IsGrouped() == true)
                {
                    QueueGroup(block, Direction.none);
                }
                else
                {
                    //Queue original block
                    QueueBlock(block, Direction.none);
                }

                //Queue other block
                if (other.IsGrouped() == true)
                {
                    QueueGroup(other, dir);
                }
                else
                {
                    //Queue other
                    QueueBlock(other, dir);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Calculate area prioritizing vertically
        /// </summary>
        /// <param name="block"></param>
        /// <param name="vert"></param>
        /// <param name="hori"></param>
        public GroupData CalcAreaVert(Block block, Direction vert, Direction hori)
        {
            Block     place       = block;
            Block     current     = null;
            Block     cornerBlock = null;
            GroupData data        = new GroupData();

            int height        = 0;
            int currentHeight = 0;
            int width         = boundary.width + 1;
            int currentWidth  = 0;

            switch (hori)
            {
            case Direction.left:
                IterateHori = SameLeft;
                break;

            case Direction.right:
                IterateHori = SameRight;
                break;

            default:
                return(data);
            }

            switch (vert)
            {
            case Direction.up:
                IterateVert = SameUp;
                break;

            case Direction.down:
                IterateVert = SameDown;
                break;

            default:
                return(data);
            }

            //Iterate prioritizing vertical
            while (place != null && place.IsGrouped() == false)
            {
                currentWidth = 0;
                current      = place;

                //Check if current block is null,.IsGrouped(), or passed the width
                while (current != null && current.IsGrouped() == false && currentWidth < width)
                {
                    //This currently priorites vertical rectangles
                    if (currentWidth >= 2)
                    {
                        cornerBlock = current;
                    }

                    current = IterateHori(current);

                    currentWidth++;
                }

                //Iterate vertically
                place = IterateVert(place);

                if (currentWidth >= 2)
                {
                    height++;
                    //Set height to shortest height
                    if (width > currentWidth)
                    {
                        width = currentWidth;
                    }
                }
                else
                {
                    return(data);
                }


                currentHeight++;
            }

            if (width == boundary.width + 1 || width <= 1 || height <= 1)
            {
                return(data);
            }

            data.width  = width;
            data.height = height;

            width  = width - 1;
            height = height - 1;

            int x = block.X;
            int y = block.Y;

            //Corners will be opposite of the direction the data points (up and left means block is bottom right corner
            if (vert.Equals(Direction.up) && hori.Equals(Direction.left))
            {
                data.topLeft     = board.GetBlock(x - width, y + height);
                data.topRight    = board.GetBlock(x, y + height);
                data.bottomLeft  = board.GetBlock(x - width, y);
                data.bottomRight = block;
            }
            else if (vert.Equals(Direction.up) && hori.Equals(Direction.right))
            {
                data.topLeft     = board.GetBlock(x, y + height);
                data.topRight    = board.GetBlock(x + width, y + height);
                data.bottomLeft  = block;
                data.bottomRight = board.GetBlock(x + width, y);
            }
            else if (vert.Equals(Direction.down) && hori.Equals(Direction.left))
            {
                data.topLeft     = board.GetBlock(x - width, y);
                data.topRight    = block;
                data.bottomLeft  = board.GetBlock(x - width, y - height);
                data.bottomRight = board.GetBlock(x, y - height);
            }
            else if (vert.Equals(Direction.down) && hori.Equals(Direction.right))
            {
                data.topLeft     = block;
                data.topRight    = board.GetBlock(x + width, y);
                data.bottomLeft  = board.GetBlock(x, y - height);
                data.bottomRight = board.GetBlock(x + width, y - height);
            }

            return(data);
        }
예제 #4
0
        private bool SameColorLine(Block block, Direction dir, int length)
        {
            if (block == null || block.IsGrouped() == true)
            {
                return(false);
            }

            switch (dir)
            {
            case Direction.up:
                for (int i = 0; i < length; i++)
                {
                    block = block.SameAdjacent(Direction.up);

                    if (block == null || block.IsGrouped() == true)
                    {
                        return(false);
                    }
                }

                break;

            case Direction.right:
                for (int i = 0; i < length; i++)
                {
                    block = block.SameAdjacent(Direction.right);
                    if (block == null || block.IsGrouped() == true)
                    {
                        return(false);
                    }
                }
                break;

            case Direction.down:
                for (int i = 0; i < length; i++)
                {
                    block = block.SameAdjacent(Direction.down);
                    if (block == null || block.IsGrouped() == true)
                    {
                        return(false);
                    }
                }
                break;

            case Direction.left:
                for (int i = 0; i < length; i++)
                {
                    block = block.SameAdjacent(Direction.left);
                    if (block == null || block.IsGrouped() == true)
                    {
                        return(false);
                    }
                }
                break;

            default:
                return(false);
            }

            return(true);
        }
예제 #5
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);
        }
예제 #6
0
        public BlockPosition BlockPos(Block block)
        {
            bool up = false, right = false, down = false, left = false;
            bool upperLeft = false, upperRight = false, lowerLeft = false, lowerRight = false;

            int adjacentCount = 0;

            Block other = block.SameAdjacent(Direction.up);

            //Check directly adjacent blocks
            if (other != null && other.IsGrouped() == false)
            {
                adjacentCount++;
                up = true;
            }

            other = block.SameAdjacent(Direction.right);
            if (other != null && other.IsGrouped() == false)
            {
                adjacentCount++;
                right = true;
            }

            other = block.SameAdjacent(Direction.down);
            if (other != null && other.IsGrouped() == false)
            {
                adjacentCount++;
                down = true;
            }

            other = block.SameAdjacent(Direction.left);
            if (other != null && other.IsGrouped() == false)
            {
                adjacentCount++;
                left = true;
            }

            //If 3 or more adjacent, check diagonals too
            if (adjacentCount >= 3)
            {
                //check upper diagonals
                other = GetBlock(block.X - 1, block.Y + 1);
                if (block.SameColor(other) && other.IsGrouped() == false)
                {
                    upperLeft = true;
                }

                other = GetBlock(block.X + 1, block.Y + 1);
                if (block.SameColor(other) && other.IsGrouped() == false)
                {
                    upperRight = true;
                }

                //Check lower diagonals
                other = GetBlock(block.X - 1, block.Y - 1);
                if (block.SameColor(other) && other.IsGrouped() == false)
                {
                    lowerLeft = true;
                }

                other = GetBlock(block.X + 1, block.Y - 1);
                if (block.SameColor(other) && other.IsGrouped() == false)
                {
                    lowerRight = true;
                }
            }

            if (adjacentCount == 2)
            {
                //Corner block
                if (up && right)
                {
                    //bottom left
                    return(BlockPosition.bottomLeft);
                }
                else if (right && down)
                {
                    //top left
                    return(BlockPosition.topLeft);
                }
                else if (down && left)
                {
                    // top right
                    return(BlockPosition.topRight);
                }
                else if (left && up)
                {
                    //bottom right
                    return(BlockPosition.bottomRight);
                }

                //3 blocks in a row
            }
            else if (adjacentCount == 3)
            {
                //T shape

                //Edge of rect
                if (up && right && down)
                {
                    //left edge
                    if (upperRight && lowerRight)
                    {
                        return(BlockPosition.left);
                    }

                    //bottom left
                    if (upperRight)
                    {
                        return(BlockPosition.bottomLeft);
                    }

                    //top right
                    if (lowerRight)
                    {
                        return(BlockPosition.topLeft);
                    }
                }
                else if (right && down && left)
                {
                    //top edge
                    if (lowerLeft && lowerRight)
                    {
                        return(BlockPosition.top);
                    }

                    //top right
                    if (lowerLeft)
                    {
                        return(BlockPosition.topRight);
                    }

                    //top left
                    if (lowerRight)
                    {
                        return(BlockPosition.topLeft);
                    }
                }
                else if (down && left && up)
                {
                    //right edge
                    if (upperLeft && lowerLeft)
                    {
                        return(BlockPosition.right);
                    }

                    //bottom right
                    if (upperLeft)
                    {
                        return(BlockPosition.bottomRight);
                    }

                    //top right
                    if (lowerLeft)
                    {
                        return(BlockPosition.topRight);
                    }
                }
                else if (left && up && right)
                {
                    //bottom edge
                    if (upperLeft && upperRight)
                    {
                        return(BlockPosition.bottom);
                    }

                    //bottom left corner
                    if (upperRight)
                    {
                        return(BlockPosition.bottomLeft);
                    }

                    //bottom right corner
                    if (upperLeft)
                    {
                        return(BlockPosition.bottomRight);
                    }
                }
            }
            else if (adjacentCount == 4)
            {
                //+ shape
                //+ shape + 1 corner = group
                if (upperLeft || upperRight || lowerLeft || lowerRight)
                {
                    return(BlockPosition.middle);
                }


                //Middle block of group
                if (upperLeft && upperRight && lowerLeft && lowerRight)
                {
                    return(BlockPosition.middle);
                }
            }

            return(BlockPosition.original);
        }