使用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);

    }

 

效果图:

image

image

image

image

image

代码下载

posted @ 2022-01-09 13:37  石曼迪  Views(92)  Comments(0Edit  收藏  举报
瓴域建设-环保事业中心