コード例 #1
0
ファイル: StackBlockControl.cs プロジェクト: hafewa/U3Dtest
    // すべてのブロックの色を選ぶ.
    public void             setColorToAllBlock()
    {
        // places ... 色を選ぶブロックの順番を格納するための配列.
        //
        // place[0] 最初に色を選ぶブロック(の場所).
        // place[1] 2番目に色を選ぶブロック.
        // place[2] 3番目に色を選ぶブロック.
        //            :
        //

        List <StackBlock.PlaceIndex> places = new List <StackBlock.PlaceIndex>();

        // とりあえず左上から順番に並べる.

        for (int y = GROUND_LINE; y < BLOCK_NUM_Y; y++)
        {
            for (int x = 0; x < BLOCK_NUM_X; x++)
            {
                StackBlock.PlaceIndex place;

                place.x = x;
                place.y = y;

                places.Add(place);
            }
        }
        #if true
        // 順番をシャッフルする.
        // ここをコメントアウトすると、スタート時のブロックの並びが
        // 左上から順番っぽくなってしまいます.
        for (int i = 0; i < places.Count - 1; i++)
        {
            int j = Random.Range(i + 1, places.Count);

            StackBlock.PlaceIndex tmp = places[i];

            places[i] = places[j];
            places[j] = tmp;
        }
        // 書籍のコードはこちら.

        /*for(int i = 0;i < places.size() - 1;i++) {
         *
         *      int j = Random.Range(i + 1, places.size());
         *
         *      places.swap(i, j);
         * }*/
        #endif
        this.block_feeder.connect_arrow_num = 1;

        foreach (StackBlock.PlaceIndex place in places)
        {
            StackBlock block = this.blocks[place.x, place.y];

            block.setColorType(this.block_feeder.getNextColorStart(place.x, place.y));
            block.setVisible(true);
        }
    }
コード例 #2
0
    // 选择所有的方块颜色
    public void             setColorToAllBlock()
    {
        // places ⋯⋯ 该数组用于存储选择了某种颜色的方块顺序
        //
        // place[0] 最开始选择了颜色的方块(的位置)
        // place[1] 第2个选择了颜色的方块
        // place[2] 第3个选择了颜色的方块
        //            :
        //

        List <StackBlock.PlaceIndex> places = new List <StackBlock.PlaceIndex>();

        // 暂时从左上开始按顺序排列

        for (int y = GROUND_LINE; y < BLOCK_NUM_Y; y++)
        {
            for (int x = 0; x < BLOCK_NUM_X; x++)
            {
                StackBlock.PlaceIndex place;

                place.x = x;
                place.y = y;

                places.Add(place);
            }
        }
        #if true
        // 随机打乱顺序
        // 如果将这里注释掉,开始时方块将
        // 从左上开始按顺序排列
        for (int i = 0; i < places.Count - 1; i++)
        {
            int j = Random.Range(i + 1, places.Count);

            StackBlock.PlaceIndex tmp = places[i];

            places[i] = places[j];
            places[j] = tmp;
        }
        // 书中的代码是这一段

        /*for(int i = 0;i < places.size() - 1;i++) {
         *
         *      int j = Random.Range(i + 1, places.size());
         *
         *      places.swap(i, j);
         * }*/
        #endif
        this.block_feeder.connect_arrow_num = 1;

        foreach (StackBlock.PlaceIndex place in places)
        {
            StackBlock block = this.blocks[place.x, place.y];

            block.setColorType(this.block_feeder.getNextColorStart(place.x, place.y));
            block.setVisible(true);
        }
    }
コード例 #3
0
ファイル: StackBlockControl.cs プロジェクト: hafewa/U3Dtest
    // 場所のインデックスから、座標を求める.
    public static Vector3   calcIndexedPosition(StackBlock.PlaceIndex place)
    {
        Vector3 position;

        position.x = (-(BLOCK_NUM_X / 2.0f - 0.5f) + place.x) * Block.SIZE_X;

        position.y = (-0.5f - (place.y - GROUND_LINE)) * Block.SIZE_Y;

        position.z = 0.0f;

        return(position);
    }
コード例 #4
0
    // 检测和(x, y)位置有连接的方块
    public int      checkConnect(int x, int y)
    {
        //

        int connect_num = this.check_connect_recurse(x, y, Block.COLOR_TYPE.NONE, 0);

        for (int i = 0; i < connect_num; i++)
        {
            StackBlock.PlaceIndex index = this.connect_block[i];

            this.connect_status[index.x, index.y] = CONNECT_STATUS.CONNECTED;
        }

        return(connect_num);
    }
コード例 #5
0
    // 是否已经检测完成?
    private bool    is_checked(StackBlock.PlaceIndex place, int connect_count)
    {
        bool is_checked = false;

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

        return(is_checked);
    }
コード例 #6
0
    // 开始举起的动作
    public void             startCarry(int place_index_x)
    {
        // 放下过程中再举起方块时,执行和落地时一样的处理。
        // 如果不这样的话,最上部分的方块将一直保持隐藏状态
        // (因为在放下过程中直到手里的方块落地之前,最上部分的方块将保持隐藏)
        if (this.step == STEP.DROP_DOWN)
        {
            this.player.scene_control.stack_control.endDropBlockAction(this.place.x);
        }

        this.place.x = place_index_x;
        this.place.y = StackBlockControl.GROUND_LINE;

        this.org_place = this.place;

        this.next_step = STEP.CARRY_UP;
    }
コード例 #7
0
ファイル: CarryBlock.cs プロジェクト: hafewa/U3Dtest
    // 持ち上げ動作を始める。
    public void             startCarry(int place_index_x)
    {
        // ドロップ中にブロックを持ち上げられたときは、一旦着地したときの
        // 処理を行う.
        // そうしないと、最上段のブロックが非表示のままになっちゃうから.
        // (ドロップ中はキャリーブロックが着地するまで、最上段のブロックは
        //  非表示になっているから).
        if (this.step == STEP.DROP_DOWN)
        {
            this.player.scene_control.stack_control.endDropBlockAction(this.place.x);
        }

        this.place.x = place_index_x;
        this.place.y = StackBlockControl.GROUND_LINE;

        this.org_place = this.place;

        this.next_step = STEP.CARRY_UP;
    }
コード例 #8
0
ファイル: StackBlockControl.cs プロジェクト: hafewa/U3Dtest
    private bool    check_connect_sub()
    {
        bool is_connect = false;

        int connect_num = 0;

        this.connect_checker.clearAll();

        for (int y = GROUND_LINE; y < StackBlockControl.BLOCK_NUM_Y; y++)
        {
            for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++)
            {
                if (!this.blocks[x, y].isConnectable())
                {
                    continue;
                }

                // 同じ色が並んでいるブロックの数をチェックする.

                int connect_block_num = this.connect_checker.checkConnect(x, y);

                // 同じ色の並びが4つ以下だったら消えない.

                if (connect_block_num < 4)
                {
                    continue;
                }

                connect_num++;

                // つながっているブロックを消す.

                for (int i = 0; i < connect_block_num; i++)
                {
                    StackBlock.PlaceIndex index = this.connect_checker.connect_block[i];

                    this.blocks[index.x, index.y].beginVanishAction();
                }

                //

                this.eliminate_count += connect_block_num;
                is_connect            = true;

                //

                this.continuous_connect_num++;
                this.score += this.continuous_connect_num * connect_block_num;
            }
        }

        //

        if (is_connect)
        {
            if (this.combo.is_now_combo)
            {
                this.combo.combo_count_current++;

                // 連鎖したら、上からブロックを降らす.
                this.fall_request++;

                this.scene_control.playSe(SceneControl.SE.COMBO);
            }
            else
            {
                this.combo.is_now_combo        = true;
                this.combo.combo_count_current = 1;
            }

            this.scene_control.playSe(SceneControl.SE.DROP_CONNECT);

            // ブロックを一定個数消すごとに、ケーキを出現させる.
            //
            do
            {
                // ケーキが出現中、あるいは出現まち中はカウントダウンしない.
                if (this.block_feeder.isCakeAppeared())
                {
                    break;
                }
                if (this.block_feeder.isCakeRequested())
                {
                    break;
                }

                this.eliminate_to_cake -= connect_num;

                if (this.eliminate_to_cake <= 0)
                {
                    this.block_feeder.requestCake();
                    this.eliminate_to_cake = ELIMINATE_TO_CAKE_INIT_2ND;

                    // すぐにブロックが降ってくるようにする.
                    if (this.fall_request == 0)
                    {
                        this.fall_request++;
                    }
                }
            } while(false);

            this.eliminate_to_fall -= connect_num;
        }
        else
        {
            // 連鎖が終わった.

            // 連鎖しなくても、ブロックを一定数消したら上からブロックが降ってくる.
            if (this.combo.combo_count_current > 1)
            {
                // 連鎖した(=ブロックが降った)はずなので、残り個数をリセット.

                this.eliminate_to_fall = ELIMINATE_TO_FALL_INIT;
            }
            else
            {
                // 連鎖しなかった.


                // ブロックを一定数消したら上からブロックを降らせる.

                if (this.eliminate_to_fall <= 0)
                {
                    if (this.fall_request == 0)
                    {
                        this.fall_request++;
                    }

                    this.eliminate_to_fall = ELIMINATE_TO_FALL_INIT;
                }
            }

            this.combo.is_now_combo        = false;
            this.combo.combo_count_last    = this.combo.combo_count_current;
            this.combo.combo_count_current = 0;

            this.continuous_connect_num = 0;
        }

        // ゴールまでの残り以上には、降らせられない.
        if (SceneControl.MAX_HEIGHT_LEVEL - this.scene_control.height_level < this.fall_request)
        {
            this.fall_request = SceneControl.MAX_HEIGHT_LEVEL - this.scene_control.height_level;
        }

        return(is_connect);
    }
コード例 #9
0
    private bool    check_connect_sub()
    {
        bool is_connect = false;

        int connect_num = 0;

        this.connect_checker.clearAll();

        for (int y = GROUND_LINE; y < StackBlockControl.BLOCK_NUM_Y; y++)
        {
            for (int x = 0; x < StackBlockControl.BLOCK_NUM_X; x++)
            {
                if (!this.blocks[x, y].isConnectable())
                {
                    continue;
                }

                // 检测同种颜色方块的排列数量

                int connect_block_num = this.connect_checker.checkConnect(x, y);

                // 如果同种颜色方块的排列书小于4则不会消除

                if (connect_block_num < 4)
                {
                    continue;
                }

                connect_num++;

                // 消除连结好的方块

                for (int i = 0; i < connect_block_num; i++)
                {
                    StackBlock.PlaceIndex index = this.connect_checker.connect_block[i];

                    this.blocks[index.x, index.y].beginVanishAction();
                }

                //

                this.eliminate_count += connect_block_num;
                is_connect            = true;

                //

                this.continuous_connect_num++;
                this.score += this.continuous_connect_num * connect_block_num;
            }
        }

        //

        if (is_connect)
        {
            if (this.combo.is_now_combo)
            {
                this.combo.combo_count_current++;

                // 发生连锁后,从上方落下方块
                this.fall_request++;

                this.scene_control.playSe(SceneControl.SE.COMBO);
            }
            else
            {
                this.combo.is_now_combo        = true;
                this.combo.combo_count_current = 1;
            }

            this.scene_control.playSe(SceneControl.SE.DROP_CONNECT);

            // 消除的方块达到一定数量后,让蛋糕出现
            //
            do
            {
                // 蛋糕出现的过程中,或者等待出现的过程中计数器不减小
                if (this.block_feeder.isCakeAppeared())
                {
                    break;
                }
                if (this.block_feeder.isCakeRequested())
                {
                    break;
                }

                this.eliminate_to_cake -= connect_num;

                if (this.eliminate_to_cake <= 0)
                {
                    this.block_feeder.requestCake();
                    this.eliminate_to_cake = ELIMINATE_TO_CAKE_INIT_2ND;

                    // 使方块马上开始落下
                    if (this.fall_request == 0)
                    {
                        this.fall_request++;
                    }
                }
            } while(false);

            this.eliminate_to_fall -= connect_num;
        }
        else
        {
            // 连锁结束

            // 即时未发生连锁,当消除的方块达到一定数量后方块也会从上方落下
            if (this.combo.combo_count_current > 1)
            {
                // 肯定发生了连锁(=方块落下了),重置残留的个数

                this.eliminate_to_fall = ELIMINATE_TO_FALL_INIT;
            }
            else
            {
                // 未发生连锁


                // 消除的方块达到一定数量,新方块从上方落下

                if (this.eliminate_to_fall <= 0)
                {
                    if (this.fall_request == 0)
                    {
                        this.fall_request++;
                    }

                    this.eliminate_to_fall = ELIMINATE_TO_FALL_INIT;
                }
            }

            this.combo.is_now_combo        = false;
            this.combo.combo_count_last    = this.combo.combo_count_current;
            this.combo.combo_count_current = 0;

            this.continuous_connect_num = 0;
        }

        // 达到了通关标准后,将不再落下方块
        if (SceneControl.MAX_HEIGHT_LEVEL - this.scene_control.height_level < this.fall_request)
        {
            this.fall_request = SceneControl.MAX_HEIGHT_LEVEL - this.scene_control.height_level;
        }

        return(is_connect);
    }