public bool notifyPlayerJoin(Character player) { if (player == null) { return(false); } int guid = player.getCharacterData().mGUID; if (mPlayerIDList.ContainsKey(guid)) { return(false); } // 添加到查找列表中 mPlayerIDList.Add(guid, player); // 在位置列表中找到一个空的位置,然后放入玩家 List <PLAYER_POSITION> posList = new List <PLAYER_POSITION>(mPlayerPositionList.Keys); int posCount = posList.Count; for (int i = 0; i < posCount; ++i) { PLAYER_POSITION pos = posList[i]; if (mPlayerPositionList[pos] == null) { mPlayerPositionList[pos] = player; player.getCharacterData().mPosition = pos; return(true); } } return(false); }
//----------------------------------------------------------------------------------------------------------- // 事件通知 public void notifyPlayState(MAHJONG_PLAY_STATE state) { mPlayState = state; // 进入等待流程时,就是开始新一局的麻将游戏,需要重置麻将系统的数据 if (mPlayState == MAHJONG_PLAY_STATE.MPS_WAITING) { mPlayerIDList.Clear(); List <PLAYER_POSITION> posList = new List <PLAYER_POSITION>(mPlayerPositionList.Keys); int posCount = posList.Count; for (int i = 0; i < posCount; ++i) { mPlayerPositionList[posList[i]] = null; } mMahjongPool.Clear(); int diceCount = mDice.Length; for (int i = 0; i < diceCount; ++i) { mDice[i] = 0; } mBankerPos = PLAYER_POSITION.PP_MAX; mCurAssignPos = PLAYER_POSITION.PP_MAX; mCurInterval = 0.0f; } // 开始掷骰子时,需要计算出掷骰子的结果 else if (mPlayState == MAHJONG_PLAY_STATE.MPS_DICE) { generateDiceRet(ref mDice); } // 开始拿牌时,需要重置麻将池 else if (mPlayState == MAHJONG_PLAY_STATE.MPS_GET_START) { resetMahjongPool(); // 判断当前谁是庄家 foreach (var item in mPlayerPositionList) { if (item.Value.getCharacterData().mBanker) { mBankerPos = item.Key; mCurAssignPos = mBankerPos; break; } } if (mBankerPos == PLAYER_POSITION.PP_MAX) { UnityUtility.logError("not find banker!"); } } else if (mPlayState == MAHJONG_PLAY_STATE.MPS_NORMAL_GAMING) { mWaitList.Clear(); } else if (mPlayState == MAHJONG_PLAY_STATE.MPS_WAIT_FOR_ACTION) { ; } else if (mPlayState == MAHJONG_PLAY_STATE.MPS_ENDING) { ; } }
public PlayerMahjong(ScriptMahjongHandIn script, PLAYER_POSITION position) { mScript = script; mPosition = position; mHandInMahjong = new HandInMahjong(mScript, mPosition); mShowMahjong = new ShowMahjong(mScript, CommonDefine.mDropMahjongPreName[(int)mPosition]); mPengGangMahjong = new PengGangMahjong(mScript, CommonDefine.mDropMahjongPreName[(int)mPosition]); }
PLAYER_POSITION position; // позиция, тип игры игрока public Player() { this.Name = "Василий"; this.Surname = "Пупкин"; this.Age = 23; this.skill = 25; this.health = 100; this.position = PLAYER_POSITION.BENCHWARMER; }
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 Player(string name, string Surname, byte Age, byte Skill, PLAYER_POSITION Position, Team Team) : base(name, Surname) { this.skill = Skill; this.team = Team; this.health = 100; // значение здоровья по умолчанию this.position = Position; this.Age = Age; }
// 服务器中的位置转换为客户端的位置 public static PLAYER_POSITION serverPositionToClientPosition(PLAYER_POSITION serverPosition, PLAYER_POSITION myselfSererPosition) { int interval = serverPosition - myselfSererPosition; if (interval < 0) { interval += GameDefine.MAX_PLAYER_COUNT; } return((PLAYER_POSITION)(interval)); }
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); } } }
//-------------------------------------------------------------------------------------------------------------------------------------- protected void refreshDropMahjong(PLAYER_POSITION pos, List <MAHJONG> droppedMahjong) { int droppedCount = droppedMahjong.Count; int showCount = MathUtility.getMin(mMaxDropCount, droppedCount); int showStartIndex = droppedCount - showCount; for (int i = 0; i < mMaxDropCount; ++i) { LayoutTools.ACTIVE_WINDOW(mDropList[(int)pos][i], i < showCount); if (i < showCount) { mDropList[(int)pos][i].setSpriteName(GameDefine.mDropMahjongPreName[(int)pos] + GameDefine.MAHJONG_NAME[(int)droppedMahjong[showStartIndex + i]]); } } }
// pos是玩家的位置 public void notifyDropMahjong(PLAYER_POSITION pos, List <MAHJONG> droppedMahjong, MAHJONG mahjong) { int preCount = droppedMahjong.Count - 1; if (preCount < mDropList[(int)pos].Count) { string mahjongSpriteName = GameDefine.mDropMahjongPreName[(int)pos] + GameDefine.MAHJONG_NAME[(int)mahjong]; mDropList[(int)pos][preCount].setSpriteName(mahjongSpriteName); LayoutTools.ACTIVE_WINDOW(mDropList[(int)pos][preCount]); } else { refreshDropMahjong(pos, droppedMahjong); } }
public PlayerMahjong(ScriptMahjongHandIn script, PLAYER_POSITION position) { mScript = script; mPosition = position; if (mPosition == PLAYER_POSITION.PP_MYSELF) { mHandInMahjong = new HandInMahjongMyself(mScript, mPosition); } else { mHandInMahjong = new HandInMahjongOther(mScript, mPosition); } mShowMahjong = new ShowHuMahjong(mScript, GameDefine.mDropMahjongPreName[(int)mPosition]); mPengGangMahjong = new PengGangMahjong(mScript, GameDefine.mDropMahjongPreName[(int)mPosition]); mHuaMahjong = new HuaMahjong(mScript, GameDefine.mDropMahjongPreName[(int)mPosition]); }
public HandInMahjong(ScriptMahjongHandIn script, PLAYER_POSITION position) { mScript = script; mPosition = position; mCanDrop = false; mHandInMahjong = new List <HandInMahjongInfo>(); mHandInPosition = new List <Vector3>(); mHandInTargetPosition = new List <Vector3>(); for (int i = 0; i < GameDefine.MAX_HAND_IN_COUNT; ++i) { HandInMahjongInfo info = new HandInMahjongInfo(); info.mState = HANDIN_STATE.HS_MAX; info.mMahjong = MAHJONG.M_MAX; mHandInMahjong.Add(info); } }
public override void update(float elapsedTime) { // 开始拿牌时,需要由麻将系统给玩家分发牌 if (mPlayState == MAHJONG_PLAY_STATE.MPS_GET_START) { mCurInterval -= elapsedTime; // 从庄家开始发牌 if (mCurInterval <= 0.0f) { mCurInterval += GameDefine.ASSIGN_MAHJONG_INTERVAL; // 给玩家发牌 CommandCharacterGetStart cmd = newCmd(out cmd); cmd.mMahjong = mHandInList[(int)mCurAssignPos][0]; pushCommand(cmd, mPlayerPositionList[(int)mCurAssignPos]); mHandInList[(int)mCurAssignPos].RemoveAt(0); // 如果到房主的牌发完了,则退出发牌 if (mCurAssignPos == mBankerPos && mHandInList[(int)mCurAssignPos].Count == 0) { mPlayState = MAHJONG_PLAY_STATE.MPS_NORMAL_GAMING; // 牌拿完时需要重新排列,发放花牌 int playerCount = mPlayerPositionList.Count; for (int i = 0; i < playerCount; ++i) { int huaCount = mHuaList[i].Count; for (int j = 0; j < huaCount; ++j) { CommandCharacterGetHua cmdHua = newCmd(out cmdHua); cmdHua.mMah = mHuaList[i][j]; pushCommand(cmdHua, mPlayerPositionList[i]); } } // 通知服务器开局麻将已经拿完了 mSocketManager.sendMessage <CSGetStartMahjongDone>(); return; } else { mCurAssignPos = (PLAYER_POSITION)(((int)mCurAssignPos + 1) % (int)PLAYER_POSITION.PP_MAX); } } } }
public bool notifyPlayerQuit(Character player) { if (player == null) { return(false); } CharacterData data = player.getCharacterData(); if (!mPlayerIDList.ContainsKey(data.mGUID)) { return(false); } mPlayerIDList.Remove(data.mGUID); PLAYER_POSITION position = data.mPosition; if (mPlayerPositionList[position] != player) { return(false); } mPlayerPositionList[position] = null; return(true); }
// 玩家请求确认操作 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; } } } } } }
public void notifyGetHua(PLAYER_POSITION pos, List <MAHJONG> huaList) { mPlayerMahjong[(int)pos].notifyGetHua(huaList); }
public void notifyAbleToPengOrGang(PLAYER_POSITION pos, MAHJONG mah) { mPlayerMahjong[(int)pos].notifyAbleToPengOrGang(mah); }
// 摸牌 public void notifyGetMahjong(PLAYER_POSITION pos, MAHJONG mah) { mPlayerMahjong[(int)pos].notifyGet(mah); }
public Character getCharacterByPosition(PLAYER_POSITION pos) { return(mPlayerPositionList[pos]); }
public void notifyGetStartMahjong() { mPlayState = MAHJONG_PLAY_STATE.MPS_GET_START; mCurAssignPos = mBankerPos; }
public void setBankerPos(int bankerPos) { // 计算出服务器中庄家在本地的方位 mBankerPos = (PLAYER_POSITION)bankerPos; }
// 打牌 public void notifyDropMahjong(PLAYER_POSITION pos, MAHJONG mah, int index) { mPlayerMahjong[(int)pos].notifyDrop(mah, index); }
public void notifyTakeDroppedMahjong(PLAYER_POSITION pos, int index) { int maxIndex = MathUtility.getMin(mMaxDropCount - 1, index); LayoutTools.ACTIVE_WINDOW(mDropList[(int)pos][maxIndex], false); }
public void notifyEnd(PLAYER_POSITION pos, List <MAHJONG> handIn) { mPlayerMahjong[(int)pos].notifyEnd(handIn); }
public HandInMahjongMyself(ScriptMahjongHandIn script, PLAYER_POSITION position) : base(script, position) { }
// 碰牌或者杠牌 public void notifyPengOrGang(PLAYER_POSITION pos, List <PengGangInfo> infoList) { mPlayerMahjong[(int)pos].notifyPengOrGang(infoList); }