示例#1
0
    IEnumerator GetTest(CardTest type, MahjongPrefab carditem = new MahjongPrefab())
    {
        switch (type)
        {
        case CardTest.group:
            yield return(GameAct.AddGroup());

            break;

        case CardTest.handCard:
            yield return(GameAct.AddHandCard(GameAct.hostUser, carditem));

            yield return(GameAct.DisplayCard(GameAct.hostUser));

            break;

        case CardTest.outCard:
            yield return(GameAct.AddOutCard(GameAct.hostUser, carditem));

            break;

        case CardTest.spacialCard:
            yield return(GameAct.AddSpacialCard(GameAct.hostUser, carditem));

            break;

        case CardTest.getCard:
            yield return(GameAct.AddHandleCard(GameAct.hostUser, carditem));

            break;

        case CardTest.insertCard:
            int index = GameAct.hostUser.handCard.Count;
            if (index < 3)
            {
                --index;
            }
            else
            {
                index = 2;
            }
            yield return(GameAct.InsertToHandCard(GameAct.hostUser, index, GameAct.hostUser.handleCard.GetMahjongCard()));

            break;

        case CardTest.diceRoll:
            yield return(GameAct.TurnDice(Random.Range(1, 7), Random.Range(1, 7)));

            break;

        case CardTest.displayDice:
            yield return(GameAct.DisapperDice());

            break;
        }
    }
示例#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);
    }