Esempio n. 1
0
    void FindBlocksInAxis(ref List <BlockToMove> BlocksToMoveInDimension, int searchedDimLength, int constAxis, MovingBlocksOption option)
    {
        List <BlockToMove> blocksToMoveInDim = new List <BlockToMove>();
        BlockToMove        b = FindFreeBlockInAxis(searchedDimLength, constAxis, option);

        if (b != null)
        {
            blocksToMoveInDim.Add(b);
            FindAllBlocksInDimWithTheSameDirectionBehindBlock(b, ref blocksToMoveInDim, option);
            BlocksToMoveInDimension.AddRange(blocksToMoveInDim);
        }

        else
        {
            return;
        }
    }
Esempio n. 2
0
    void FindAllBlocksInDimWithTheSameDirectionBehindBlock(BlockToMove b, ref List <BlockToMove> BlocksInRow, MovingBlocksOption option)
    {
        bool keepLooking = true;
        int  dir         = -1 * ((int)dict[b.Block.direction].x + (int)dict[b.Block.direction].y);

        int j = 1;

        if (option == MovingBlocksOption.Horizontal)
        {
            int constAxis = b.Block.y;

            while (keepLooking)
            {
                if (board[b.Block.x + dir * j, constAxis] is Block && board[b.Block.x + dir * j, constAxis].direction == b.Block.direction)
                {
                    BlockToMove nextBlockToMove = new BlockToMove((Block)board[b.Block.x + dir * j, constAxis]);

                    if (CoordsAreOutOfBoard(b.EndCoords))
                    {
                        nextBlockToMove.EndCoords = b.EndCoords;
                    }
                    else
                    {
                        nextBlockToMove.EndCoords += b.EndCoords + new Vector2(dir * j, 0);
                    }
                    nextBlockToMove.OutOfBoard = CoordsAreOutOfBoard(nextBlockToMove.EndCoords);
                    BlocksInRow.Add(nextBlockToMove);
                    j++;
                }
                else
                {
                    return;
                }
            }
            return;
        }

        else if (option == MovingBlocksOption.Vertical)
        {
            int constAxis = b.Block.x;
            while (keepLooking)
            {
                if (board[constAxis, b.Block.y + dir * j] is Block && board[constAxis, b.Block.y + dir * j].direction == b.Block.direction)
                {
                    BlockToMove nextBlockToMove = new BlockToMove((Block)board[constAxis, b.Block.y + dir * j]);
                    if (CoordsAreOutOfBoard(b.EndCoords))
                    {
                        nextBlockToMove.EndCoords = b.EndCoords;
                    }
                    else
                    {
                        nextBlockToMove.EndCoords += b.EndCoords + new Vector2(0, dir * j);
                    }

                    nextBlockToMove.OutOfBoard = CoordsAreOutOfBoard(nextBlockToMove.EndCoords);
                    BlocksInRow.Add(nextBlockToMove);
                    j++;
                }
                else
                {
                    return;
                }
            }
            return;
        }
    }