private int             check_connect_recurse(int x, int y, BlockControl.COLOR previous_color, int connect_count)
    {
        BlockIndex block_index;

        do
        {
            // 如果已经和其他方块连结则忽略跳过
            //
            if (this.connect_status[x, y] == CONNECT_STATUS.CONNECTED)
            {
                break;
            }

            //

            block_index.x = x;
            block_index.y = y;

            // 如果本次已经检测过则忽略跳过

            bool is_checked = false;

            for (int i = 0; i < connect_count; i++)
            {
                if (this.connect_block[i].Equals(block_index))
                {
                    is_checked = true;
                    break;
                }
            }
            if (is_checked)
            {
                break;
            }

            //

            if (previous_color == BlockControl.COLOR.NONE)
            {
                // 开始的第一个

                this.connect_block[0] = block_index;

                connect_count = 1;
            }
            else
            {
                // 从第2个开始,检测是否和前一个方块颜色相同

                if (this.blocks[x, y].color == previous_color)
                {
                    this.connect_block[connect_count] = block_index;

                    connect_count++;
                }
            }

            // 如果和前一个颜色相同,则继续检测旁边的方块

            if (previous_color == BlockControl.COLOR.NONE || this.blocks[x, y].color == previous_color)
            {
                // 左
                if (x > 0)
                {
                    connect_count = this.check_connect_recurse(x - 1, y, this.blocks[x, y].color, connect_count);
                }
                // 右
                if (x < BLOCK_NUM_X - 1)
                {
                    connect_count = this.check_connect_recurse(x + 1, y, this.blocks[x, y].color, connect_count);
                }
                // 上
                if (y > 0)
                {
                    connect_count = this.check_connect_recurse(x, y - 1, this.blocks[x, y].color, connect_count);
                }
                // 下
                if (y < BLOCK_NUM_Y - 1)
                {
                    connect_count = this.check_connect_recurse(x, y + 1, this.blocks[x, y].color, connect_count);
                }

                // 为了让方块按对角线排列时消除

                /*if(x > 0 && y > 0) {
                 *
                 *      connect_count = this.check_connect_recurse(x - 1, y - 1, this.blocks[x, y].color, connect_count);
                 * }
                 * if(x > 0 && y < BLOCK_NUM_Y - 1) {
                 *
                 *      connect_count = this.check_connect_recurse(x - 1, y + 1, this.blocks[x, y].color, connect_count);
                 * }
                 * if(x < BLOCK_NUM_X - 1 && y > 0) {
                 *
                 *      connect_count = this.check_connect_recurse(x + 1, y - 1, this.blocks[x, y].color, connect_count);
                 * }
                 * if(x < BLOCK_NUM_X - 1 && y < BLOCK_NUM_Y - 1) {
                 *
                 *      connect_count = this.check_connect_recurse(x + 1, y + 1, this.blocks[x, y].color, connect_count);
                 * }*/
            }
        } while(false);

        return(connect_count);
    }
Ejemplo n.º 2
0
    private int             check_connect_recurse(int x, int y, BlockControl.COLOR previous_color, int connect_count)
    {
        BlockIndex block_index;

        do
        {
            // すでにほかのブロックと連結していたらスキップ.
            //
            if (this.connect_status[x, y] == CONNECT_STATUS.CONNECTED)
            {
                break;
            }

            //

            block_index.x = x;
            block_index.y = y;

            // 今回すでにチェック済みならスキップ.

            bool is_checked = false;

            for (int i = 0; i < connect_count; i++)
            {
                if (this.connect_block[i].Equals(block_index))
                {
                    is_checked = true;
                    break;
                }
            }
            if (is_checked)
            {
                break;
            }

            //

            if (previous_color == BlockControl.COLOR.NONE)
            {
                // 最初の一個目.

                this.connect_block[0] = block_index;

                connect_count = 1;
            }
            else
            {
                // 2個目以降は、前のブロックと同じ色かチェックする.

                if (this.blocks[x, y].color == previous_color)
                {
                    this.connect_block[connect_count] = block_index;

                    connect_count++;
                }
            }

            // 同じ色が続いていたら、さらに隣もチェックする.

            if (previous_color == BlockControl.COLOR.NONE || this.blocks[x, y].color == previous_color)
            {
                // 左.
                if (x > 0)
                {
                    connect_count = this.check_connect_recurse(x - 1, y, this.blocks[x, y].color, connect_count);
                }
                // 右.
                if (x < BLOCK_NUM_X - 1)
                {
                    connect_count = this.check_connect_recurse(x + 1, y, this.blocks[x, y].color, connect_count);
                }
                // 上.
                if (y > 0)
                {
                    connect_count = this.check_connect_recurse(x, y - 1, this.blocks[x, y].color, connect_count);
                }
                // 下.
                if (y < BLOCK_NUM_Y - 1)
                {
                    connect_count = this.check_connect_recurse(x, y + 1, this.blocks[x, y].color, connect_count);
                }

                // ナナメ方向に並んだ時だけ消えるように.

                /*if(x > 0 && y > 0) {
                 *
                 *      connect_count = this.check_connect_recurse(x - 1, y - 1, this.blocks[x, y].color, connect_count);
                 * }
                 * if(x > 0 && y < BLOCK_NUM_Y - 1) {
                 *
                 *      connect_count = this.check_connect_recurse(x - 1, y + 1, this.blocks[x, y].color, connect_count);
                 * }
                 * if(x < BLOCK_NUM_X - 1 && y > 0) {
                 *
                 *      connect_count = this.check_connect_recurse(x + 1, y - 1, this.blocks[x, y].color, connect_count);
                 * }
                 * if(x < BLOCK_NUM_X - 1 && y < BLOCK_NUM_Y - 1) {
                 *
                 *      connect_count = this.check_connect_recurse(x + 1, y + 1, this.blocks[x, y].color, connect_count);
                 * }*/
            }
        } while(false);

        return(connect_count);
    }