zoukankan      html  css  js  c++  java
  • 使用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

    代码下载

  • 相关阅读:
    Vue自定义Table
    Cesium GeometryIntstance 选中改变颜色 和 绘制带箭头的直线
    echart 饼图
    C# 读取json 文件 解析处理并另存
    滚动条到底 监听
    二分总结
    LeetCode 438. 找到字符串中所有字母异位词
    LeetCode 400. 第 N 位数字
    WPF深入浅出代码案例
    设计模式生成器模式
  • 原文地址:https://www.cnblogs.com/madyina/p/15780801.html
Copyright © 2011-2022 走看看