public override void execute() { List <MahjongAction> actionList = new List <MahjongAction>(); for (int i = 0; i < 4; ++i) { Character player = mCharacterManager.getCharacter(mActionPlayer.mValue[i]); Character droppedPlayer = mCharacterManager.getCharacter(mDroppedPlayer.mValue[i]); ACTION_TYPE type = (ACTION_TYPE)mAction.mValue[i]; if (type != ACTION_TYPE.AT_MAX) { MAHJONG mah = (MAHJONG)mMahjong.mValue[i]; List <HU_TYPE> huList = null; if (type == ACTION_TYPE.AT_HU) { huList = new List <HU_TYPE>(); for (int j = 0; j < GameDefine.MAX_HU_COUNT; ++j) { if (mHuList.mValue[i] == 0) { break; } huList.Add((HU_TYPE)mHuList.mValue[i]); } } actionList.Add(new MahjongAction(type, player, droppedPlayer, mah, huList)); } } CommandCharacterAskAction cmd = mCommandSystem.newCmd <CommandCharacterAskAction>(); cmd.mActionList = actionList; mCommandSystem.pushCommand(cmd, mCharacterManager.getMyself()); }
protected void showPengGang(int index, ACTION_TYPE type, MAHJONG mah) { int count = 0; if (type == ACTION_TYPE.AT_PENG) { count = 3; } else if (type == ACTION_TYPE.AT_GANG) { count = 4; } else { return; } LT.ACTIVE_WINDOW(mPengGangSingleRoot[index]); int maxCount = mMahjongWindows[index].Count; string mahjongSpriteName = mMahjongPreName + GameDefine.MAHJONG_NAME[(int)mah]; for (int i = 0; i < maxCount; ++i) { LT.ACTIVE_WINDOW(mMahjongWindows[index][i], i < count); if (i < count) { mMahjongWindows[index][i].setSpriteName(mahjongSpriteName); } } }
// 打出一张牌 public virtual void notifyDrop(MAHJONG mah, int index) { if (index >= 0 && index < mHandInMahjong.Count) { LT.ACTIVE_WINDOW(mHandInMahjong[index].mMahjongWindow, false); } }
public override void markAbleToPengOrGang(MAHJONG mah) { for (int i = 0; i < mHandInMahjong.Count; ++i) { LT.ACTIVE_WINDOW(mHandInMahjong[i].mSelectMask, mah != MAHJONG.M_MAX && mah == mHandInMahjong[i].mMahjong); } }
// 杠指定牌 public virtual void gangMahjong(MAHJONG mahjong, Character dropPlayer) { int pengIndex = -1; bool isAlreadyPeng = hasPeng(mahjong, ref pengIndex); if (isAlreadyPeng) { mCharacterData.mPengGangList[pengIndex].mType = ACTION_TYPE.AT_GANG; } else { GameUtility.gangMahjong(ref mCharacterData.mHandIn, mahjong); addGang(mahjong); } // 如果是自己摸了一张牌,则需要将自己摸的牌拿出来,如果是其他人打出的牌,则不进行操作 if (dropPlayer == this) { int handInCount = mCharacterData.mHandIn.Count; for (int j = 0; j < handInCount; ++j) { if (mCharacterData.mHandIn[j] == mahjong) { mCharacterData.mHandIn.RemoveAt(j); break; } } } }
public MahjongAction(ACTION_TYPE type, Character actionPlayer, Character droppedPlayer, MAHJONG mahjong, List <HU_TYPE> huList = null) { mType = type; mActionPlayer = actionPlayer; mDroppedPlayer = droppedPlayer; mMah = mahjong; mHuList = huList; }
// 通知开局时的拿牌 public virtual void notifyGetStart(MAHJONG mah) { // 开局拿了一张牌 HandInMahjongInfo info = mHandInMahjong[mCurHandInCount]; LT.ACTIVE_WINDOW(info.mMahjongWindow); ++mCurHandInCount; }
protected void addGang(MAHJONG mahjong) { PengGangInfo info = new PengGangInfo(); info.mMahjong = mahjong; info.mType = ACTION_TYPE.AT_GANG; mCharacterData.mPengGangList.Add(info); }
public void notifyPlayerDrop(Character player, MAHJONG mah) { // 正常游戏过程中,玩家打了一张牌后,判断其他玩家是否有碰或者杠,该下家摸牌 if (mPlayState == MAHJONG_PLAY_STATE.MPS_NORMAL_GAMING) { // 判断其他玩家是否可以碰或者杠 bool hasAction = false; foreach (var item in mPlayerIDList) { if (item.Value != player) { List <MahjongAction> checkActionList = new List <MahjongAction>(); CharacterData data = item.Value.getCharacterData(); // 是否可胡 if (GameUtility.canHu(data.mHandIn, mah)) { List <HU_TYPE> huList = GameUtility.generateHuType(data.mHandIn, mah, data.mPengGangList, false, false); checkActionList.Add(new MahjongAction(ACTION_TYPE.AT_HU, item.Value, player, mah, huList)); } // 是否可杠 if (GameUtility.canGang(data.mHandIn, mah)) { checkActionList.Add(new MahjongAction(ACTION_TYPE.AT_GANG, item.Value, player, mah)); } // 是否可碰 if (GameUtility.canPeng(data.mHandIn, mah)) { checkActionList.Add(new MahjongAction(ACTION_TYPE.AT_PENG, item.Value, player, mah)); } if (checkActionList.Count > 0) { hasAction = true; // 添加pass操作 checkActionList.Add(new MahjongAction(ACTION_TYPE.AT_PASS, item.Value, player, mah)); askPlayerAction(item.Value, player, mah, checkActionList); } } } // 没有人需要这张牌,则该下家摸牌 if (!hasAction) { if (mMahjongPool.Count > 0) { PLAYER_POSITION nextPosition = (PLAYER_POSITION)(((int)(player.getCharacterData().mPosition) + 1) % (int)PLAYER_POSITION.PP_MAX); Character nextPlayer = getCharacterByPosition(nextPosition); CommandCharacterGet cmdGet = mCommandSystem.newCmd <CommandCharacterGet>(); cmdGet.mMahjong = requestGet(); mCommandSystem.pushCommand(cmdGet, nextPlayer); } // 牌已经摸完了,则本局为平局 else { //End; } } } }
public override void notifyDrop(MAHJONG mah, int index) { base.notifyDrop(mah, index); HandInMahjongInfo info = mHandInMahjong[index]; info.mMahjong = MAHJONG.M_MAX; info.mState = HANDIN_STATE.HS_MAX; info.mMahjongWindow.setSpriteName(""); }
// handInMah必须是从小到大的有序数组 public static bool canHu(List <MAHJONG> handInMah, MAHJONG mah) { //复制一份列表 List <MAHJONG> temp = new List <MAHJONG>(handInMah); // 然后别人打出的牌加入其中 temp.Add(mah); return(canHu(temp)); }
// 请求从麻将池中拿一张牌 protected MAHJONG requestGet() { if (mMahjongPool.Count > 0) { MAHJONG mah = mMahjongPool[mMahjongPool.Count - 1]; mMahjongPool.RemoveAt(mMahjongPool.Count - 1); return(mah); } return(MAHJONG.M_MAX); }
public override void notifyGetStart(MAHJONG mah) { HandInMahjongInfo info = mHandInMahjong[mCurHandInCount]; info.mMahjong = mah; info.mState = HANDIN_STATE.HS_SAVED; info.mMahjongWindow.setSpriteName(GameDefine.MAHJONG_NAME[(int)mah]); // 最后才调用基类函数 base.notifyGetStart(mah); }
// 打出一张牌 public void notifyDrop(MAHJONG mah, int index) { HandInMahjongInfo info = mHandInMahjong[index]; if (mPosition == PLAYER_POSITION.PP_MYSELF) { info.mMahjong = MAHJONG.M_MAX; info.mState = HANDIN_STATE.HS_MAX; info.mWindow.setSpriteName(""); } LayoutTools.ACTIVE_WINDOW(info.mWindow, false); }
// 得到指定牌的花色 public static MAHJONG_HUASE getHuaSe(MAHJONG mah) { if (mah >= MAHJONG.M_FENG_DONG && mah <= MAHJONG.M_FENG_BAI) { return(MAHJONG_HUASE.MH_FENG); } else { int huaseIndex = (mah - MAHJONG.M_TONG1) / 9; return(MAHJONG_HUASE.MH_TONG + huaseIndex); } }
// handInIncludeDrop表示handInMah中是否已经包含了dropMah public static List <HU_TYPE> generateHuType(List <MAHJONG> handInMah, MAHJONG dropMah, List <PengGangInfo> gangPengList, bool isSelfGet, bool handInIncludeDrop) { // 将数组转换为列表 List <MAHJONG> handInList = new List <MAHJONG>(); List <MAHJONG> pengs = new List <MAHJONG>(); List <MAHJONG> gangs = new List <MAHJONG>(); int handInCount = handInMah.Count; for (int i = 0; i < handInCount; ++i) { handInList.Add(handInMah[i]); } // 如果handInMah中不包含dropMah,则需要加到列表中 if (!handInIncludeDrop) { int curCount = handInList.Count; for (int i = 0; i < curCount; ++i) { if (handInList[i] >= dropMah) { handInList.Insert(i, dropMah); } } } int gangPengCount = gangPengList.Count; for (int i = 0; i < gangPengCount; ++i) { if (gangPengList[i].mType == ACTION_TYPE.AT_GANG) { pengs.Add(gangPengList[i].mMahjong); } else if (gangPengList[i].mType == ACTION_TYPE.AT_PENG) { gangs.Add(gangPengList[i].mMahjong); } } // 判断胡牌类型 List <HU_TYPE> huList = new List <HU_TYPE>(); // 是否为清一色 if (isQingYiSe(handInList, pengs, gangs)) { huList.Add(HU_TYPE.HT_QINGYISE); } // 如果不满足任意一种番型,则为平胡 if (huList.Count == 0) { huList.Add(HU_TYPE.HT_NORMAL); } return(huList); }
// 通知开局时的拿牌 public void notifyGetStart(MAHJONG mah) { // 开局拿了一张牌 HandInMahjongInfo info = mHandInMahjong[mCurHandInCount]; if (mPosition == PLAYER_POSITION.PP_MYSELF) { info.mMahjong = mah; info.mState = HANDIN_STATE.HS_SAVED; info.mWindow.setSpriteName(GameDefine.MAHJONG_NAME[(int)mah]); } LayoutTools.ACTIVE_WINDOW(info.mWindow); ++mCurHandInCount; }
public bool hasPeng(MAHJONG mahjong, ref int pengIndex) { int count = mCharacterData.mPengGangList.Count; for (int i = 0; i < count; ++i) { if (mCharacterData.mPengGangList[i].mMahjong == mahjong) { pengIndex = i; return(true); } } return(false); }
public static bool canGang(List <MAHJONG> handInMah, MAHJONG mah) { List <MahInfo> infoList = toMahjongGroup(handInMah); int count = infoList.Count; for (int i = 0; i < count; ++i) { if (infoList[i].mCount == 3 && infoList[i].mMah == mah) { return(true); } } return(false); }
public static void gangMahjong(ref List <MAHJONG> handInMah, MAHJONG mah) { // 杠的前提是之前检测过可以杠 int mahCount = handInMah.Count; for (int i = 0; i < mahCount - 2; ++i) { if (handInMah[i] == mah && handInMah[i + 1] == mah && handInMah[i + 2] == mah) { handInMah.RemoveRange(i, 3); break; } } }
public override void execute() { GameScene gameScene = mGameSceneManager.getCurScene(); if (gameScene.getSceneType() != GAME_SCENE_TYPE.GST_MAHJONG) { return; } if (!gameScene.atProcedure(PROCEDURE_TYPE.PT_MAHJONG_WAITING)) { return; } List <int> playerIDList = new List <int>(); List <List <MAHJONG> > handInList = new List <List <MAHJONG> >(); List <List <MAHJONG> > huaList = new List <List <MAHJONG> >(); for (int i = 0; i < mPlayerCount.mValue; ++i) { playerIDList.Add(mPlayerIDList.mValue[i]); handInList.Add(new List <MAHJONG>()); for (int j = 0; j < GameDefine.MAX_HAND_IN_COUNT; ++j) { MAHJONG mah = (MAHJONG)mHandInList.mValue[GameDefine.MAX_HAND_IN_COUNT * i + j]; if (mah == MAHJONG.M_MAX) { break; } handInList[i].Add(mah); } huaList.Add(new List <MAHJONG>()); for (int j = 0; j < GameDefine.MAX_HAND_IN_COUNT; ++j) { MAHJONG mah = (MAHJONG)mHuaList.mValue[GameDefine.MAX_HUA_COUNT * i + j]; if (mah == MAHJONG.M_MAX) { break; } huaList[i].Add(mah); } } mMahjongSystem.setDice(mDice.mValue); mMahjongSystem.setBankerPos(mBankerPos.mValue); mMahjongSystem.startMahjong(playerIDList, handInList, huaList); // 跳转到掷骰子流程 CommandGameSceneChangeProcedure cmd = newCmd(out cmd); cmd.mProcedure = PROCEDURE_TYPE.PT_MAHJONG_RUNNING_DICE; pushCommand(cmd, mGameSceneManager.getCurScene()); }
// 摸牌 public void notifyGet(MAHJONG mah) { HandInMahjongInfo info = mHandInMahjong[mCurHandInCount]; LayoutTools.ACTIVE_WINDOW(info.mWindow); if (mPosition == PLAYER_POSITION.PP_MYSELF) { // 放到末尾,并且设置为准备打出的状态 info.mMahjong = mah; info.mState = HANDIN_STATE.HS_SAVED; info.mWindow.setSpriteName(GameDefine.MAHJONG_NAME[(int)mah]); prepareDropMahjong(mCurHandInCount); } ++mCurHandInCount; }
public static List <MahInfo> toMahjongGroup(List <MAHJONG> list) { SortedDictionary <MAHJONG, MahInfo> groupMap = new SortedDictionary <MAHJONG, MahInfo>(); int listSize = list.Count; for (int i = 0; i < listSize; ++i) { MAHJONG mah = list[i]; if (groupMap.ContainsKey(mah)) { groupMap[mah].mCount += 1; } else { groupMap.Add(mah, new MahInfo(mah, 1)); } } return(new List <MahInfo>(groupMap.Values)); }
public override void execute() { Character character = (mReceiver) as Character; CharacterData data = character.getCharacterData(); int dropIndex = -1; // 如果还未打缺一色,则需要打最少的一色牌 SortedDictionary <MAHJONG_HUASE, List <MAHJONG> > huaseList = GameUtility.getHuaseList(GameUtility.toMahjongGroup(data.mHandIn)); if (huaseList.Count > 2) { MAHJONG_HUASE minHuase = MAHJONG_HUASE.MH_MAX; foreach (var item in huaseList) { if (minHuase == MAHJONG_HUASE.MH_MAX || minHuase > item.Key) { minHuase = item.Key; } } MAHJONG dropMah = huaseList[minHuase][huaseList[minHuase].Count - 1]; int handInCount = data.mHandIn.Count; for (int i = 0; i < handInCount; ++i) { if (data.mHandIn[i] == dropMah) { dropIndex = i; break; } } } // 如果已经打缺了,则打最后一张 if (dropIndex == -1) { dropIndex = data.mHandIn.Count - 1; } CommandCharacterDrop cmd = mCommandSystem.newCmd <CommandCharacterDrop>(); cmd.mIndex = dropIndex; cmd.mMah = data.mHandIn[dropIndex]; mCommandSystem.pushCommand(cmd, character); }
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); } }
// 询问玩家要选择哪种操作 public void askPlayerAction(Character player, Character droppedPlayer, MAHJONG mah, List <MahjongAction> actionList) { if (actionList.Count == 0) { UnityUtility.logError("has no action"); return; } // 将行为放入列表 WaitActionInfo info = new WaitActionInfo(); info.mPlayer = player; info.mDroppedPlayer = droppedPlayer; info.mActionList = actionList; info.mMahjong = mah; mWaitList.Add(info.mPlayer, info); // 设置状态为等待玩家确认操作 notifyPlayState(MAHJONG_PLAY_STATE.MPS_WAIT_FOR_ACTION); // 询问玩家进行什么操作 CommandCharacterAskAction cmd = mCommandSystem.newCmd <CommandCharacterAskAction>(); cmd.mActionList = actionList; mCommandSystem.pushCommand(cmd, player); }
public override void init() { base.init(); mDroppedPlayer = null; mMahjong = MAHJONG.M_MAX; }
public override void init() { base.init(); mMah = MAHJONG.M_MAX; }
public virtual void markAbleToPengOrGang(MAHJONG mah) { }
// 摸牌 public virtual void notifyGet(MAHJONG mah) { LT.ACTIVE_WINDOW(mHandInMahjong[mCurHandInCount].mMahjongWindow); ++mCurHandInCount; }