// 取得下一个方块的颜色(游戏开始时,全部设置后)
    public Block.COLOR_TYPE getNextColorStart(int x, int y)
    {
#if false
        Block.COLOR_TYPE color_type;

        color_type = (Block.COLOR_TYPE)Random.Range((int)Block.NORMAL_COLOR_FIRST, (int)Block.NORMAL_COLOR_LAST + 1);

        return(color_type);
#else
        StackBlock[,]           blocks = this.control.blocks;
        ConnectChecker   connect_checker = this.control.connect_checker;
        Block.COLOR_TYPE org_color;
        int sel;

        //

        org_color = blocks[x, y].color_type;

        // 初始化“出现时颜色的候选值列表”
        // (使列表包含所有的颜色)
        this.init_candidates();

        // 设置各个方块的颜色时,探测已经排列了几个同种颜色的方块

        for (int i = 0; i < (int)Block.NORMAL_COLOR_NUM; i++)
        {
            // 放置第i项颜色的方块
            blocks[x, y].setColorType((Block.COLOR_TYPE)i);

            connect_checker.clearAll();

            // 计算连结数
            this.connect_num[i] = connect_checker.checkConnect(x, y);
        }

        if (this.connect_arrow_num > 0)
        {
            // 生成好了初始的同色4方块组

            // connect_num[] 中的最大值(最大允许max_num 个同色方块排列)
            int max_num = this.get_max_connect_num();

            // 如果数量不是max_num 则删除(只保留适当对象作为候补)
            this.erase_candidate_if_not(max_num);

            sel = Random.Range(0, candidates.Count);

            // 如果同色4个方块排列后,初始连结好的4方块组的数量将减少1
            if (this.connect_num[(int)candidates[sel]] >= 4)
            {
                this.connect_arrow_num--;
            }
        }
        else
        {
            // 还没有生成初始的同色4方块组

            // 如果同种颜色已经有4个方块排列好了则从候补值中剔除
            for (int i = candidates.Count - 1; i >= 0; i--)
            {
                if (this.connect_num[(int)candidates[i]] >= 4)
                {
                    candidates.RemoveAt(i);
                }
            }

            if (candidates.Count == 0)
            {
                this.init_candidates();
                Debug.Log("give up");
            }

            // connect_num[] 中的最大值(最大允许max_num 个同色方块排列)
            int max_num = this.get_max_connect_num();

            // 如果数量不是max_num 则删除(只保留适当对象作为候补)
            this.erase_candidate_if_not(max_num);

            sel = Random.Range(0, candidates.Count);
        }


        //

        blocks[x, y].setColorType(org_color);

        return((Block.COLOR_TYPE)candidates[sel]);
#endif
    }
Beispiel #2
0
    // 次のブロックの色を取得する(ゲームスタート時に、全部を埋めるとき用).
    public Block.COLOR_TYPE getNextColorStart(int x, int y)
    {
#if false
        Block.COLOR_TYPE color_type;

        color_type = (Block.COLOR_TYPE)Random.Range((int)Block.NORMAL_COLOR_FIRST, (int)Block.NORMAL_COLOR_LAST + 1);

        return(color_type);
#else
        StackBlock[,]           blocks = this.control.blocks;
        ConnectChecker   connect_checker = this.control.connect_checker;
        Block.COLOR_TYPE org_color;
        int sel;

        //

        org_color = blocks[x, y].color_type;

        // 『出現する色の候補のリスト』を初期化する.
        // (リストにすべての色が含まれるようにする).
        this.init_candidates();

        // 各色を置いたとき、同じ色が何個並ぶかを調べておく.

        for (int i = 0; i < (int)Block.NORMAL_COLOR_NUM; i++)
        {
            // i 番目のカラーのブロックを置く
            blocks[x, y].setColorType((Block.COLOR_TYPE)i);

            connect_checker.clearAll();

            // 連結数をカウント
            this.connect_num[i] = connect_checker.checkConnect(x, y);
        }

        if (this.connect_arrow_num > 0)
        {
            // まだあがり目ができてもいい場合.

            // connect_num[] の中の最大値(最大で max_num 個同じ色のブロックが並ぶ).
            int max_num = this.get_max_connect_num();

            // max_num じゃないものを削除する(最大値をとるものだけを候補に残す).
            this.erase_candidate_if_not(max_num);

            sel = Random.Range(0, candidates.Count);

            // 同じ色が4つ並んだら、あがり目の残り数を減らしておく
            if (this.connect_num[(int)candidates[sel]] >= 4)
            {
                this.connect_arrow_num--;
            }
        }
        else
        {
            // もうあがり目を作れない場合.

            // 同じ色が4つならんでしまう色を候補から外す.
            for (int i = candidates.Count - 1; i >= 0; i--)
            {
                if (this.connect_num[(int)candidates[i]] >= 4)
                {
                    candidates.RemoveAt(i);
                }
            }

            if (candidates.Count == 0)
            {
                this.init_candidates();
                Debug.Log("give up");
            }

            // connect_num[] の中の最大値(最大で max_num 個同じ色のブロックが並ぶ).
            int max_num = this.get_max_connect_num();

            // max_num じゃないものを削除する(最大値をとるものだけを候補に残す).
            this.erase_candidate_if_not(max_num);

            sel = Random.Range(0, candidates.Count);
        }


        //

        blocks[x, y].setColorType(org_color);

        return((Block.COLOR_TYPE)candidates[sel]);
#endif
    }