/// <summary> /// 请求弃牌 /// </summary> /// <param name="uid"></param> private void RepDisCard(int uid) { if (!UserFight.ContainsKey(uid) || !LoopOrder.Contains(uid)) { DebugUtil.Instance.LogToTime(uid + "请求弃牌失败,没有此玩家"); return; } if (DisCardList.Contains(uid)) { DebugUtil.Instance.LogToTime(uid + "请求弃牌失败,已经弃过牌了"); return; } if (LoopOrder.Count < 2) { DebugUtil.Instance.LogToTime(uid + "请求弃牌失败,玩家不足了,最后一个人直接胜利"); return; } //广播玩家弃牌消息 Broadcast(FightProtocol.TPDISCARD_BRQ, uid); //将玩家添加到弃牌列表中 DisCardList.Add(uid); //将玩家从当前玩家列表中删除 LoopOrder.Remove(uid); DebugUtil.Instance.LogToTime(uid + "请求弃牌成功"); //TODO:NEXT LOOPORDER(继续下一个玩家) if (LoopOrder.Count == 1) { GameOver(); } }
/// <summary> /// 请求看牌 /// </summary> /// <param name="uid">看牌的玩家</param> private void ReqCheckCard(int uid) { if (!UserFight.ContainsKey(uid) || !LoopOrder.Contains(uid)) { DebugUtil.Instance.LogToTime(uid + "请求看牌失败,没有此玩家"); return; } if (CheckList.Contains(uid)) { DebugUtil.Instance.LogToTime(uid + "请求看牌失败,已经看过牌了"); return; } //告知玩家自己的手牌 SendMessage(uid, FightProtocol.TPCHECKCARD_SRES, UserFight[uid].poker); //通知所有人,自己看过牌了 Broadcast(FightProtocol.TPCHECKCARD_BRQ, uid); //将看牌的玩家添加到列表中 CheckList.Add(uid); DebugUtil.Instance.LogToTime(uid + "请求看牌成功,房间号:" + RoomId); }
/// <summary> /// 请求比牌 /// </summary> /// <param name="uid">比牌的玩家</param> /// <param name="cid">被比牌的玩家</param> private void ReqComCard(int uid, int cid) { if (!UserFight.ContainsKey(uid) || !LoopOrder.Contains(uid)) { DebugUtil.Instance.LogToTime(uid + "请求比牌失败,没有此玩家"); return; } if (!UserFight.ContainsKey(cid) || !LoopOrder.Contains(cid)) { DebugUtil.Instance.LogToTime(cid + "请求比牌失败,没有此玩家"); return; } if (LoopOrder [0] != uid) { DebugUtil.Instance.LogToTime(cid + "请求比牌错误,当前不是此玩家"); SendMessage(uid, FightProtocol.TPCOMCARD_SRES, -2); return; } if (!IsGameStart) { DebugUtil.Instance.LogToTime(uid + "请求错误,游戏尚未开始"); SendMessage(uid, FightProtocol.TPCOMCARD_SRES, -3); return; } int coin = NowScore; if (CheckList.Contains(uid)) { coin *= 2; } if (coin == 4) { coin = 5; } //将当前下注玩家和下注金额添加到集合中,等待结算 if (!BetCoinList.ContainsKey(uid)) { BetCoinList.Add(uid, new List <int>()); } BetCoinList[uid].Add(NowScore); //声明待广播的数据,将下注数据广播 TPBetModel tpm = new TPBetModel(); tpm.id = uid; tpm.coin = coin; tpm.isAdd = false; Broadcast(FightProtocol.TPBETCOIN_BRQ, tpm); //更新玩家筹码后广播给所有玩家 UserFight[uid].coin -= coin; Broadcast(FightProtocol.PLAYERINFO_BRQ, UserFight[uid]); //首轮可比 三轮可比 五轮可比 //默认首轮可比,将玩家的手牌和被比玩家的手牌传入,获取结果 bool GetResult = TPokerUtil.GetComparePoker(UserFight[uid].poker, UserFight[cid].poker); DebugUtil.Instance.LogToTime(uid + "请求和" + cid + "比牌,比牌结果为:" + GetResult); for (int i = 0; i < LoopOrder.Count; i++) { TPCompareModel model = new TPCompareModel(); model.userId = uid; model.compId = cid; model.Result = GetResult; //如果是比牌或被比牌的玩家,则可以看到牌 if (LoopOrder [i] == uid || LoopOrder [i] == cid) { model.PokerList1.AddRange(UserFight[uid].poker); model.PokerList2.AddRange(UserFight[cid].poker); } SendMessage(LoopOrder[i], FightProtocol.TPCOMCARD_BRQ, model); } if (GetResult) { LoopOrder.Remove(cid); } else { LoopOrder.Remove(uid); } if (LoopOrder.Count == 1) { GameOver(); } }
/// <summary> /// 请求下注 /// </summary> /// <param name="uid">请求下注的玩家</param> /// <param name="coin">请求下注的金额</param> private void ReqBet(int uid, int coin) { //下注金额coin== -1,是跟注,否则加注 bool initCoin = coin == -1 ? false : true; if (!UserFight.ContainsKey(uid) || !LoopOrder.Contains(uid)) { DebugUtil.Instance.LogToTime("请求错误,没有此玩家"); SendMessage(uid, FightProtocol.TPBETCOIN_SRES, -1); return; } if (LoopOrder [0] != uid) { DebugUtil.Instance.LogToTime(uid + "请求错误,当前不是此玩家"); SendMessage(uid, FightProtocol.TPBETCOIN_SRES, -2); return; } if (!IsGameStart) { DebugUtil.Instance.LogToTime("请求错误,游戏尚未开始"); SendMessage(uid, FightProtocol.TPBETCOIN_SRES, -3); return; } //是否看过牌 if (CheckList.Contains(uid)) { //跟注 if (coin == -1) { coin = NowScore * 2; if (coin == 4) { coin = 5; } } initCoin = coin == (NowScore * 2) ? false : true; if (coin == 5 && NowScore == 2) { initCoin = false; } //是否小于最小可下注金额 if (coin < NowScore * 2) { DebugUtil.Instance.LogToTime(uid + "请求下注失败,当前可下注金额最小为:" + (NowScore * 2)); SendMessage(uid, FightProtocol.TPBETCOIN_SRES, -4); return; } //是否大于最大下注金额 if (coin > MaxScore) { DebugUtil.Instance.LogToTime(uid + "请求下注失败,当前可下注金额最大为:" + MaxScore); SendMessage(uid, FightProtocol.TPBETCOIN_SRES, -5); return; } if (coin == 5) { NowScore = 2; } } else { if (coin == -1) { coin = NowScore; } initCoin = coin == NowScore ? false : true; //是否小于最小可下注金额 if (coin < NowScore) { DebugUtil.Instance.LogToTime(uid + "请求下注失败,当前可下注金额最小为:" + NowScore); SendMessage(uid, FightProtocol.TPBETCOIN_SRES, -4); return; } //是否大于最大下注金额 if (coin > MaxScore / 2) { DebugUtil.Instance.LogToTime(uid + "请求下注失败,当前可下注金额最大为:" + (MaxScore / 2)); SendMessage(uid, FightProtocol.TPBETCOIN_SRES, -5); return; } NowScore = coin; } // Bet(uid, coin, initCoin); }