Ejemplo n.º 1
0
        private void DestroyOrActivateBlock(int row, int column, List <BlockRemoval> removedBlocks, BlockRemovalReason blockRemovalReason)
        {
            if (row < 0 || row >= rowCount || column < 0 || column >= columnCount)
            {
                return;
            }

            var block = blocks[row, column];

            if (block.type != BlockType.Normal && block.type != BlockType.Mega)
            {
                var blockAndPosition = new BlockAndPosition(block, row, column);
                if (!activatedBlocks.Contains(blockAndPosition))
                {
                    newActivatedBlocks.Add(blockAndPosition);
                    removedBlocks.Add(new BlockRemoval(block, blockRemovalReason, row, column));
                }
                else
                {
                    Console.WriteLine("Already contains");
                }
            }
            else if (block.color != BlockColor.Empty)
            {
                removedBlocks.Add(new BlockRemoval(block, blockRemovalReason, row, column));
                blocks[row, column] = EmptyBlock;
            }
        }
Ejemplo n.º 2
0
        private void ApplyEffect(BlockAndPosition activatedBlock, List <SpecialBlockActivation> blockActivations, List <BlockRemoval> removedBlocks)
        {
            int row    = activatedBlock.row;
            int column = activatedBlock.column;

            var blockType = activatedBlock.block.type;

            switch (blockType)
            {
            case BlockType.Mega:
                DestroyActivatedBlock(row, column, blockActivations, blockType);
                blocks[row, column].color = colorToDestroy;
                for (int i = 0; i < rowCount; i++)
                {
                    for (int j = 0; j < columnCount; j++)
                    {
                        if (blocks[i, j].color == colorToDestroy)
                        {
                            DestroyOrActivateBlock(i, j, removedBlocks, BlockRemovalReason.DestroyedByLaserBurst);
                        }
                    }
                }

                break;

            case BlockType.Cross:
                DestroyActivatedBlock(row, column, blockActivations, blockType);
                for (int i = 0; i < columnCount; i++)
                {
                    DestroyOrActivateBlock(row, i, removedBlocks, BlockRemovalReason.DestroyedByMatching);
                }
                for (int i = 0; i < rowCount; i++)
                {
                    DestroyOrActivateBlock(i, column, removedBlocks, BlockRemovalReason.DestroyedByCrossExplosion);
                }

                break;

            case BlockType.Bomb:
                DestroyActivatedBlock(row, column, blockActivations, blockType);
                for (int i = row - 1; i <= row + 1; i++)
                {
                    for (int j = column - 1; j <= column + 1; j++)
                    {
                        DestroyOrActivateBlock(i, j, removedBlocks, BlockRemovalReason.DestroyedByBombExplosion);
                    }
                }
                break;
            }
        }
Ejemplo n.º 3
0
        public bool TrySwapBlocks(int row1, int column1, int row2, int column2)
        {
            if ((Math.Abs(row1 - row2) == 1 && column1 == column2) || (row1 == row2 && Math.Abs(column1 - column2) == 1))
            {
                var block1 = blocks[row1, column1];
                var block2 = blocks[row2, column2];

                if (block1.color == block2.color)
                {
                    return(false);
                }

                blocks[row1, column1] = block2;
                blocks[row2, column2] = block1;

                if (block1.color == BlockColor.Rainbow || block2.color == BlockColor.Rainbow)
                {
                    playerJustUsedMegaBlock = true;
                    if (block1.color == BlockColor.Rainbow)
                    {
                        colorToDestroy    = block2.color;
                        megaBlockPosition = new BlockAndPosition(block1, row2, column2);
                    }
                    else
                    {
                        colorToDestroy    = block1.color;
                        megaBlockPosition = new BlockAndPosition(block2, row1, column1);
                    }

                    return(true);
                }

                if (HasMatches())
                {
                    swapRow1    = row1;
                    swapColumn1 = column1;
                    swapRow2    = row2;
                    swapColumn2 = column2;
                    return(true);
                }

                blocks[row1, column1] = block1;
                blocks[row2, column2] = block2;
            }
            return(false);
        }