Esempio n. 1
0
    public void update(float elapsedTime)
    {
        // 开始拿牌时,需要由麻将系统给玩家分发牌
        if (mPlayState == MAHJONG_PLAY_STATE.MPS_GET_START)
        {
            mCurInterval -= elapsedTime;
            // 从庄家开始发牌
            if (mCurInterval <= 0.0f)
            {
                mCurInterval = GameDefine.ASSIGN_MAHJONG_INTERVAL;
                Character curPlayer = mPlayerPositionList[mCurAssignPos];
                // 给玩家发牌
                CommandCharacterGetStart cmd = mCommandSystem.newCmd <CommandCharacterGetStart>();
                cmd.mMahjong = requestGet();
                mCommandSystem.pushCommand(cmd, curPlayer);

                bool isDone            = false;
                int  palyerHandInCount = curPlayer.getCharacterData().mHandIn.Count;
                // 如果是庄家,需要拿够14张牌
                if (mCurAssignPos == mBankerPos)
                {
                    isDone = (palyerHandInCount == GameDefine.MAX_HAND_IN_COUNT);
                }
                // 不是庄家则拿13张牌
                else
                {
                    isDone = (palyerHandInCount == GameDefine.MAX_HAND_IN_COUNT - 1);
                }
                // 牌拿完时需要重新排列
                if (isDone)
                {
                    CommandCharacterReorderMahjong cmdReorder = mCommandSystem.newCmd <CommandCharacterReorderMahjong>();
                    mCommandSystem.pushCommand(cmdReorder, curPlayer);

                    // 如果是庄家拿完了牌,则进入正常游戏流程
                    if (mCurAssignPos == mBankerPos)
                    {
                        CommandMahjongSceneNotifyStartDone cmdStartDone = mCommandSystem.newCmd <CommandMahjongSceneNotifyStartDone>();
                        mCommandSystem.pushCommand(cmdStartDone, mGameSceneManager.getCurScene());

                        // 通知玩家打出一张牌
                        CommandCharacterAskDrop cmdAskDrop = mCommandSystem.newCmd <CommandCharacterAskDrop>();
                        mCommandSystem.pushCommand(cmdAskDrop, curPlayer);
                        return;
                    }
                }
                mCurAssignPos = (PLAYER_POSITION)(((int)mCurAssignPos + 1) % (int)PLAYER_POSITION.PP_MAX);
            }
        }
    }
Esempio n. 2
0
    public void notifyGet(Character player, MAHJONG mah)
    {
        // 判断是否可胡或者可杠
        CharacterData        data       = player.getCharacterData();
        List <MahjongAction> actionList = new List <MahjongAction>();

        // 是否可胡
        if (GameUtility.canHu(data.mHandIn))
        {
            List <HU_TYPE> huList = GameUtility.generateHuType(data.mHandIn, mah, data.mPengGangList, true, true);
            actionList.Add(new MahjongAction(ACTION_TYPE.AT_HU, player, player, mah, huList));
        }
        // 是否可以杠
        else if (GameUtility.canGang(data.mHandIn))
        {
            actionList.Add(new MahjongAction(ACTION_TYPE.AT_GANG, player, player, mah));
        }
        // 摸了一张自己碰的牌,可以开杠
        else
        {
            int pengIndex = 0;
            if (player.hasPeng(mah, ref pengIndex))
            {
                actionList.Add(new MahjongAction(ACTION_TYPE.AT_GANG, player, player, mah));
            }
        }
        if (actionList.Count > 0)
        {
            // 如果有可以操作的行为,则还需要添加Pass行为
            actionList.Add(new MahjongAction(ACTION_TYPE.AT_PASS, player, null, MAHJONG.M_MAX));
            askPlayerAction(player, player, mah, actionList);
        }
        else
        {
            // 没有任何操作则通知玩家需要打一张牌出来
            CommandCharacterAskDrop cmdAskDrop = mCommandSystem.newCmd <CommandCharacterAskDrop>();
            mCommandSystem.pushCommand(cmdAskDrop, player);
        }
    }
Esempio n. 3
0
    // 玩家请求确认操作
    public void playerConfirmAction(Character player, ACTION_TYPE type)
    {
        if (!mWaitList.ContainsKey(player))
        {
            UnityUtility.logError("player has no action : name : " + player.getName() + ", action : " + type);
        }
        MahjongAction        action     = null;
        List <MahjongAction> actionList = mWaitList[player].mActionList;
        int actionCount = actionList.Count;

        for (int i = 0; i < actionCount; ++i)
        {
            if (actionList[i].mType == type)
            {
                action = actionList[i];
                break;
            }
        }
        if (action == null)
        {
            return;
        }
        mWaitList[player].mConfirmedAction = action;
        // 胡牌的优先级最高,如果有玩家选择胡牌,则忽略其他玩家的操作
        if (action.mType == ACTION_TYPE.AT_HU)
        {
            // 游戏状态设置为正常游戏
            notifyPlayState(MAHJONG_PLAY_STATE.MPS_NORMAL_GAMING);
            CommandCharacterHu cmd = mCommandSystem.newCmd <CommandCharacterHu>();
            mCommandSystem.pushCommand(cmd, player);

            // 有玩家胡牌后则结束游戏
            //End;
        }
        else
        {
            bool          allConfirm          = true;
            Character     highestActionPlayer = null;
            MahjongAction highestAction       = null;
            foreach (var wait in mWaitList)
            {
                if (wait.Value.mConfirmedAction == null)
                {
                    allConfirm = false;
                    break;
                }
                if (highestAction == null || highestAction.mType > wait.Value.mConfirmedAction.mType)
                {
                    highestAction       = wait.Value.mConfirmedAction;
                    highestActionPlayer = wait.Value.mPlayer;
                }
            }
            // 如果全部玩家都已经确认操作了,允许优先级最高的操作进行
            if (allConfirm)
            {
                // 先获得信息,因为在设置状态时会将列表清空
                WaitActionInfo info = mWaitList[highestActionPlayer];
                // 游戏状态设置为正常游戏
                notifyPlayState(MAHJONG_PLAY_STATE.MPS_NORMAL_GAMING);
                if (highestAction.mType == ACTION_TYPE.AT_GANG)
                {
                    // 自己摸的牌开杠
                    if (info.mDroppedPlayer == info.mPlayer)
                    {
                        ;
                    }
                    // 别人打出牌开杠
                    else
                    {
                        ;
                    }
                    CommandCharacterGang cmd = mCommandSystem.newCmd <CommandCharacterGang>();
                    cmd.mDroppedPlayer = info.mDroppedPlayer;
                    cmd.mMahjong       = info.mMahjong;
                    mCommandSystem.pushCommand(cmd, info.mPlayer);

                    // 还有牌,玩家杠了一张牌以后需要再摸一张
                    if (mMahjongPool.Count > 0)
                    {
                        CommandCharacterGet cmdGet = mCommandSystem.newCmd <CommandCharacterGet>();
                        cmdGet.mMahjong = requestGet();
                        mCommandSystem.pushCommand(cmdGet, info.mPlayer);
                    }
                    // 没有牌了则平局
                    else
                    {
                        //End;
                    }
                }
                else if (highestAction.mType == ACTION_TYPE.AT_PENG)
                {
                    CommandCharacterPeng cmd = mCommandSystem.newCmd <CommandCharacterPeng>();
                    cmd.mDroppedPlayer = info.mDroppedPlayer;
                    cmd.mMahjong       = info.mMahjong;
                    mCommandSystem.pushCommand(cmd, info.mPlayer);

                    CommandCharacterAskDrop cmdAskDrop = mCommandSystem.newCmd <CommandCharacterAskDrop>();
                    mCommandSystem.pushCommand(cmdAskDrop, info.mPlayer);
                }
                else if (highestAction.mType == ACTION_TYPE.AT_PASS)
                {
                    // 如果是自己摸了一张牌,选择了pass,则需要自己打一张牌出来
                    if (info.mDroppedPlayer == info.mPlayer)
                    {
                        CommandCharacterAskDrop cmd = mCommandSystem.newCmd <CommandCharacterAskDrop>();
                        mCommandSystem.pushCommand(cmd, info.mPlayer);
                    }
                    else
                    {
                        // 还有牌则通知下一家摸牌
                        if (mMahjongPool.Count > 0)
                        {
                            PLAYER_POSITION     nextPosition = (PLAYER_POSITION)(((int)(info.mDroppedPlayer.getCharacterData().mPosition) + 1) % (int)PLAYER_POSITION.PP_MAX);
                            CommandCharacterGet cmdGet       = mCommandSystem.newCmd <CommandCharacterGet>();
                            cmdGet.mMahjong = requestGet();
                            mCommandSystem.pushCommand(cmdGet, getCharacterByPosition(nextPosition));
                        }
                        // 没有牌了则平局
                        else
                        {
                            //End;
                        }
                    }
                }
            }
        }
    }
Esempio n. 4
0
    public override void execute()
    {
        CommandCharacterAskDrop cmd = mCommandSystem.newCmd <CommandCharacterAskDrop>();

        mCommandSystem.pushCommand(cmd, mCharacterManager.getMyself());
    }