使用SuperSocket開發聯網斗地主(四):出牌
本節內容:
出牌和大牌邏輯。(昨天新發現了還有一個專門做游戲開發的框架cocos,后面學習下這個吧,這個就不更新了)
出牌邏輯:
1. 如果當前沒人出牌,我是第一個,只需符合出牌條件就行;
2. 如果之前有人出牌,就要既符合出牌條件也要大住上家;
/// <summary> /// 是否符合出牌規則 /// </summary> /// <param name="userShowedList"></param> /// <returns></returns> private static bool WithRules(List<DouDiZhuGameCard> userShowedList) { int userShowedCount = userShowedList.Count(); bool can = true; //單牌,對子,三不帶(連字需要5張及以上) if (userShowedCount <= 3) { DouDiZhuGameCard last = null; foreach (var item in userShowedList) { if (last == null || last.CardName == item.CardName) { last = item; } else { can = false; break; } } return can; } //...其他的規則 return can; }
大牌
/// <summary> /// 能否大過上家 /// </summary> /// <param name="userShowedList"></param> /// <param name="LastShowedList"></param> /// <returns></returns> private static bool IsBigger(List<DouDiZhuGameCard> userShowedList, List<DouDiZhuGameCard> LastShowedList) { int userShowedCount = userShowedList.Count(); int lastShowedCount = LastShowedList.Count(); bool can = true; //單牌,對子,三不帶(連字需要5張及以上) if (userShowedCount <= 3) { return userShowedList[0].CardValue > LastShowedList[0].CardValue; } //...其他的規則 return can; }
然后客戶端需要通知其他人當前出的牌,思路是把出的牌放在底牌區域,用以展示
然后就是控制按鈕的顯示與隱藏等
//出牌成功 else if (result.Action == "show_ok") { diPai = result.Data.CommonCards; player_me = result.Data.MyCards; shuaXinTangZi(); shuaXinShouPai(); if (result.Data.IsMyTurn) { btnBox.children[0].style.display = 'none'; btnBox.children[1].style.display = 'none'; btnBox.children[2].style.display = 'none'; btnBox.children[3].style.display = 'inline-block'; btnBox.children[4].style.display = 'inline-block'; } else { btnBox.children[0].style.display = 'none'; btnBox.children[1].style.display = 'none'; btnBox.children[2].style.display = 'none'; btnBox.children[3].style.display = 'none'; btnBox.children[4].style.display = 'none'; } } //出牌錯誤 else if (result.Action == "show_err") { //startQiangDiZhu(result.Data); } //公開廣播信息 else if (result.Action == "pubInfo") { pubUserInfo(PlayerMeInfo,result.Data); }
效果圖:






浙公網安備 33010602011771號