Пример #1
0
    void OnGUI()
    {
        GUILayout.BeginHorizontal();
        #region 麻将抽发测试  已完成 2016/12/28
        GUILayout.BeginVertical();
        if (GUILayout.Button("发牌顺序:R-F-L-H"))
        {
            GameAct.CardDirection(1);
        }

        if (GUILayout.Button("发牌顺序:H-R-F-L"))
        {
            GameAct.CardDirection(0);
        }

        if (GUILayout.Button("断开连接"))
        {
            GameAct.BreakAllLink();
        }

        if (GUILayout.Button("洗牌"))
        {
            StartCoroutine(GetTest(CardTest.group));
        }

        if (GUILayout.Button("掷色子"))
        {
            StartCoroutine(GetTest(CardTest.diceRoll));
        }

        if (GUILayout.Button("移除色子"))
        {
            StartCoroutine(GetTest(CardTest.displayDice));
        }

        if (GUILayout.Button("清空"))
        {
            GameAct.Reset();
        }
        GUILayout.EndVertical();
        #endregion

        #region 玩家牌测试 所有玩家测试完成 2016/12/28
        GUILayout.BeginVertical();
        if (GUILayout.Button("发牌"))
        {
            MahjongPrefab tran = new MahjongPrefab();
            if (GameAct.hostUser.handCard.IsNotFull)
            {
                tran = GameAct.group_H.GetMahjongCard(6);
            }
            if (tran.transform != null)
            {
                StartCoroutine(GetTest(CardTest.handCard, tran));
            }
        }

        if (GUILayout.Button("获取手牌"))
        {
            StartCoroutine(GetTest(CardTest.getCard));
        }

        if (GUILayout.Button("从最后获取手牌"))
        {
            MahjongPrefab tran = new MahjongPrefab();
            if (GameAct.hostUser.handCard.IsNotFull)
            {
                tran = GameAct.group_H.GetMahjongCard(5, 0);
            }
            if (tran.transform != null)
            {
                StartCoroutine(GetTest(CardTest.getCard, tran));
            }
            //mGameClientAction.GetCard(mGameClientAction.hostUser, tran);
        }

        if (GUILayout.Button("加入手牌"))
        {
            StartCoroutine(GetTest(CardTest.insertCard));
        }

        if (GUILayout.Button("打出第一张牌"))
        {
            MahjongPrefab tran = GameAct.hostUser.handCard.GetMahjongCard();
            StartCoroutine(GetTest(CardTest.outCard, tran));
        }

        if (GUILayout.Button("打出最后一张牌"))
        {
            MahjongPrefab tran = GameAct.hostUser.handCard.GetMahjongCard(0, 0);
            StartCoroutine(GetTest(CardTest.outCard, tran));
        }

        if (GUILayout.Button("明杠"))
        {
            //左边第2个开始 杠四个
            MahjongPrefab tran1 = GameAct.hostUser.handCard.GetMahjongCard(2, 0, false);
            MahjongPrefab tran2 = GameAct.hostUser.handCard.GetMahjongCard(2, 0, false);
            MahjongPrefab tran3 = GameAct.hostUser.handCard.GetMahjongCard(2, 0, false);
            MahjongPrefab tran4 = GameAct.hostUser.handCard.GetMahjongCard(2, 0, false);
            StartCoroutine(GameAct.AddGang(GameAct.hostUser, CardActType.MingGang, tran1, tran2, tran3, tran4, () => {
                GameAct.hostUser.handCard.ReSort();
            }));
        }

        if (GUILayout.Button("补杠"))
        {
            //左边第2个开始 杠四个
            MahjongPrefab tran1 = GameAct.hostUser.handCard.GetMahjongCard(2, 0, false);
            StartCoroutine(GameAct.InsertToAddGangCard(GameAct.hostUser, index, tran1));
        }

        if (GUILayout.Button("resort"))
        {
        }

        if (GUILayout.Button("暗杠"))
        {
            //左边第2个开始 杠四个
            MahjongPrefab tran1 = GameAct.hostUser.handCard.GetMahjongCard(2, 0, false);
            MahjongPrefab tran2 = GameAct.hostUser.handCard.GetMahjongCard(2, 0, false);
            MahjongPrefab tran3 = GameAct.hostUser.handCard.GetMahjongCard(2, 0, false);
            MahjongPrefab tran4 = GameAct.hostUser.handCard.GetMahjongCard(2, 0, false);
            StartCoroutine(GameAct.AddGang(GameAct.hostUser, CardActType.AnGang, tran1, tran2, tran3, tran4, () => {
                GameAct.hostUser.handCard.ReSort();
            }));
        }

        if (GUILayout.Button("碰"))
        {
            //出牌最后一个
            MahjongPrefab tran1 = GameAct.hostUser.outCardPoint.GetMahjongCard();
            //左边第1个开始  碰两个
            MahjongPrefab tran2 = GameAct.hostUser.handCard.GetMahjongCard(1, 0, false);
            MahjongPrefab tran3 = GameAct.hostUser.handCard.GetMahjongCard(1, 0, false);
            StartCoroutine(GameAct.AddPengChi(GameAct.hostUser, CardActType.Peng, tran1, tran2, tran3, () =>
            {
                GameAct.hostUser.handCard.ReSort();
            }));
        }

        if (GUILayout.Button("吃"))
        {
            //出牌最后一个
            MahjongPrefab tran1 = GameAct.hostUser.outCardPoint.GetMahjongCard();
            //左边第1个开始  手牌两个
            MahjongPrefab tran2 = GameAct.hostUser.handCard.GetMahjongCard(1, 0, false);
            MahjongPrefab tran3 = GameAct.hostUser.handCard.GetMahjongCard(1, 0, false);
            StartCoroutine(GameAct.AddPengChi(GameAct.hostUser, CardActType.Chi, tran1, tran2, tran3, () =>
            {
                GameAct.hostUser.handCard.ReSort();
            }));
        }

        if (GUILayout.Button("重排出牌区域"))
        {
            GameAct.hostUser.outCardPoint.ReSort();
        }

        if (GUILayout.Button("胡"))
        {
            StartCoroutine(GameAct.TurnOverCard(GameAct.hostUser));
        }

        if (GUILayout.Button("功能牌"))
        {
            MahjongPrefab tran = GameAct.hostUser.handCard.GetMahjongCard();
            StartCoroutine(GetTest(CardTest.spacialCard, tran));
        }

        GUILayout.EndVertical();
        GUILayout.BeginVertical();
        if (GUILayout.Button("洗牌"))
        {
            test = processorModel.RandCardData();
            string s = "[ ";
            foreach (byte item in test)
            {
                s += item + " : ";
            }
            s += " ]";
            Debug.Log(s);
        }
        if (GUILayout.Button("排序"))
        {
            processorModel.SelectSort(ref test);
            string s = "[ ";
            foreach (byte item in test)
            {
                s += item + " : ";
            }
            s += " ]";
            Debug.Log(s);
        }
        if (GUILayout.Button("插入"))
        {
            byte item = 10;
            Debug.Log(item);
            int index = processorModel.GetInsert(ref test, item);
            Debug.Log(index);
            string s = "[ ";
            foreach (byte it in test)
            {
                s += it + " : ";
            }
            s += " ]";
            Debug.Log(s);
        }
        GUILayout.EndVertical();
        #endregion
        GUILayout.EndHorizontal();
    }
Пример #2
0
    //手动逻辑
    IEnumerator LogicCprocessor(int userID = 0, MahjongPrefab mahjong = new MahjongPrefab())
    {
        switch (nextState)
        {
        //掷色子
        case Logic.turn_dice:
            previousState = nextState;
            nextState     = Logic.empty;
            //显示色子
            yield return(gameAct.DisplayDice());

            //掷色子
            yield return(gameAct.TurnDice(gameData.dice_num[0], gameData.dice_num[1]));

            //设置发牌起始位置
            index = 2 * Mathf.Min(gameData.dice_num[0], gameData.dice_num[1]);
            control.EndStatusFlag(userID, UserAction.turn_dice);
            break;

        //发牌
        case Logic.add_hand_card:
            previousState = nextState;
            nextState     = Logic.add_hand_card_end;
            //2秒后色子消失
            StartCoroutine(gameAct.DisapperDice(2f));
            //确定取牌次序
            int prio;
            //如果当前玩家不是庄家
            if (currentUserID != 0)
            {
                prio = (gameData.dice_num[0] + gameData.dice_num[1]) % gameData.player_priority;
            }
            else
            {
                //如果是庄家则除4
                prio = (gameData.dice_num[0] + gameData.dice_num[1]) % 4;
            }
            gameAct.CardDirection(prio);

            //临时牌 保存乱序后的手牌
            List <int> cardTemp = RandCard(handCard);
            //每个玩家抽取三轮
            for (int i = 0; i < 3; ++i)
            {
                //每轮玩家抽取四张
                for (int j = 0; j < 4; ++j)
                {
                    for (int k = 0; k < 4; ++k)
                    {
                        if (userPriority[j].handCard.IsNotFull)
                        {
                            yield return(gameAct.AddHandCard(userPriority[j], gameAct.group_H.GetMahjongCard(index)));
                        }
                        else
                        {
                            Debug.LogError("<MGameClient::LogicCprocessor>:玩家手牌已满." + userPriority[j].ToString());
                        }
                    }
                    //翻牌
                    if (j == currentUserID)
                    {
                        yield return(gameAct.DisplayCard(userPriority[j], cardTemp));
                    }
                    else
                    {
                        yield return(gameAct.DisplayCard(userPriority[j]));
                    }
                    //每次抽完牌稍微停滞一下
                    yield return(new WaitForSeconds(0.1f));
                }
            }
            //再各多发一张
            for (int i = 0; i < 4; ++i)
            {
                if (userPriority[i].handCard.IsNotFull)
                {
                    //使用函数内部延迟
                    yield return(gameAct.AddHandCard(userPriority[i], gameAct.group_H.GetMahjongCard(index)));
                }
                else
                {
                    Debug.LogError("<MGameClient::LogicCprocessor>:玩家手牌已满." + userPriority[i].ToString());
                }
                //翻牌 如果是当前用户 则替换成需要的牌
                if (i == currentUserID)
                {
                    yield return(gameAct.DisplayCard(userPriority[i], cardTemp));
                }
                else
                {
                    yield return(gameAct.DisplayCard(userPriority[i]));
                }
                //每次抽完牌稍微停滞一下
                yield return(new WaitForSeconds(0.1f));
            }
            //整理手牌
            yield return(new WaitForSeconds(0.5f));

            yield return(gameAct.SortCard(userPriority[currentUserID], handCard));

            control.EndStatusFlag(userID, UserAction.send_card);
            break;

        //摸牌
        case Logic.get_handlecard:
            previousState = nextState;
            nextState     = Logic.empty;
            //获取手牌
            if (currentUserID != userID && userPriority[userID].handleCard.IsNotFull)
            {
                yield return(gameAct.AddHandleCard(userPriority[userID], gameAct.group_H.GetMahjongCard(index)));
            }
            else if (userPriority[userID].handleCard.IsNotFull)
            {
                MahjongPrefab cardtemp = gameAct.group_H.GetMahjongCard(index);
                //替换模型
                cardtemp.mesh.mesh = ResoucreMtr.Instance.GetMesh(handleCard);
                yield return(gameAct.AddHandleCard(userPriority[userID], cardtemp));
            }

            //可以界面操作
            globalOperateFlag = true;
            //允许玩家操作
            userPriority[userID].operateFlag = true;

            //如果是当前用户 则判断是否有操作提示
            if (currentUserID == userID)
            {
                GameTipAnalys();
            }

            control.EndStatusFlag(userID, UserAction.get_card);
            break;

        //出牌
        case Logic.out_card:
            previousState = nextState;
            nextState     = Logic.empty;
            //出牌
            yield return(gameAct.AddOutCard(userPriority[userID], mahjong));

            break;

        //胡
        case Logic.hu:
            previousState = nextState;
            nextState     = Logic.empty;
            //全局控制关闭
            globalOperateFlag = false;
            //玩家控制关闭并摊开玩家手牌
            for (int i = 0; i < 4; ++i)
            {
                userPriority[i].operateFlag = false;
                yield return(gameAct.SortCard(userPriority[i], cardData[i]));

                //如果手牌不为空
                if (!userPriority[i].handleCard.IsEmpty)
                {
                    userPriority[i].handleCard[0].mesh.mesh = ResoucreMtr.Instance.GetMesh(cardData[4][0]);
                }
                yield return(gameAct.TurnOverCard(userPriority[i]));
            }
            control.EndStatusFlag(userID, UserAction.hu);
            break;

        case Logic.chi_hu:
            previousState = nextState;
            nextState     = Logic.empty;
            //全局控制关闭
            globalOperateFlag = false;
            //玩家控制关闭并摊开玩家手牌
            for (int i = 0; i < 4; ++i)
            {
                userPriority[i].operateFlag = false;
                yield return(gameAct.SortCard(userPriority[i], cardData[i]));

                yield return(gameAct.TurnOverCard(userPriority[i]));
            }
            control.EndStatusFlag(userID, UserAction.hu);
            break;
        }
        yield return(0);
    }