• python3.7 jack棋牌11点实例


    # Project:      棋牌游戏11点
    # Author:       jack
    # Version:     2.2
    # Start Time:  2021-07-24
    
    import random
    
    P_INFO = [["小王",0.5],["大王",0.5]]       # 初始一副poker牌
    USER_LIST = ["庄家","alex","武沛齐"]              # 玩家信息表
    P_INFO_TWO = []                           # 剩余牌列表
    USER_POKER = []                           # 人员和牌列表
    RESULT ={}                                # 最终成绩表
    
    # 1、生成一副扑克牌(自己设计扑克牌的结构)
    def one_poker(P_INFO):
        poker_type = ["黑桃","红桃","草花","方块"]
        # 基本牌数字
        poker_num  = ["A","2","3","4","5","6","7","8","9","10","J","Q","K","小王","大王"]
        for type in poker_type:
            count = 1
            for num in range(len(poker_num)):
                if num > 12:
                    pass
                elif num > 9:
                    card = [type+poker_num[num],0.5]    # J、Q、K、代表的值为0.5
                    P_INFO.append(card)
                else:
                    card = [type+poker_num[num],count]
                    P_INFO.append(card)
                count += 1
        # print(P_INFO)
        return P_INFO       # 已生成一副牌
    
    # 2、3个玩家(玩家也可以自己定义)
    def  user_num(USER_LIST):
        count = 0
        while  count < 54:
            user_name = input("输入玩家名字,输入Q/q退出游戏,S/s开始发牌:").strip()
            print()
            if user_name.upper() == "Q":
                exit()
            elif user_name.upper() == "S":
                break
            elif user_name in USER_LIST:
                print("{}玩家名称已存在,请重新输入".format(user_name))
            else:
                USER_LIST.append(user_name)                     # 新玩家自动添加到玩家信息表
                count += 1
        else:
            exit("太多人玩了,牌不够了")
        return USER_LIST
    
    # 3、发牌
    def deal(USER_LIST,P_INFO,RESULT,P_INFO_TWO):
        count = 0
        while count < len(USER_LIST):
            user_p_one = random.randint(0,len(P_INFO)-1)    # 产生0-53之间的一个整数
            card = P_INFO[user_p_one]
            user = USER_LIST[count]
            USER_POKER.append([user,card])
            print("{}抽到的第1张牌为:{}".format(user,card))
            print("牌面值为:{}".format(card[1]))
            print()
            RESULT[user] = card[1]
            P_INFO.pop(user_p_one)
            count += 1
        P_INFO_TWO.extend(P_INFO)                       # 剩余牌列表
        return USER_POKER,RESULT,P_INFO_TWO
    
    # 4、要牌
    def recard(USER_LIST,P_INFO_TWO,RESULT,USER_POKER):
        count = 0
        while count < len(USER_LIST):
            user = input(f"{USER_LIST[count]}选择是否要牌,输入N/n不要牌,回车继续要牌:").strip()
            print()
            if user.upper() == "N":
                count += 1
                # continue
            else:
                user_p_one = random.randint(0,len(P_INFO_TWO)-1) # 取一张牌
                card = P_INFO_TWO[user_p_one]                    # 牌的信息
                user = USER_LIST[count]                              # 用户信息
                USER_POKER[count].append(card)                       # 牌加到人员和牌列表
                print("{}抽到的牌为:{}".format(user,card))
                score = RESULT.get(user)                             # 得到第一次牌分数
                score += card[1]                                     # 计算新的分数
                print(f"{USER_LIST[count]}现在的牌面是:{USER_POKER[count][1:]}")
                print("牌面值为:{}".format(score))
                print()
                RESULT[user] = score                                 # 把分数写进字典
                P_INFO_TWO.pop(user_p_one)
                if score > 11:                                       # 超过11分牌爆掉
                    RESULT[user] = 0
                    print("{}牌爆掉了,下次注意点......".format(user))
                    print()
                    count += 1
        return P_INFO_TWO,RESULT
    
    one_poker(P_INFO)                               # 生产一副牌
    # for poker in P_INFO:
        # print(poker[0],end=" ")                   # 显示一副牌,不显示值
    print("JACK赌坊,欢迎光临".center(30,"-"))                       
    print("小赌怡情,大赌伤身,强赌灰飞烟灭".center(22,"-"))
    print("玩家请看牌".center(40,"-"))
    print(P_INFO)                                   # 显示一副牌
    print("开始棋牌11点".center(34,"-"))
    print()
    user_num(USER_LIST)                             # 人员列表
    # print(USER_LIST)
    deal(USER_LIST,P_INFO,RESULT,P_INFO_TWO)        # 第一次发牌
    # print(USER_POKER)
    # print(RESULT)
    # print(P_INFO_TWO)
    recard(USER_LIST,P_INFO_TWO,RESULT,USER_POKER)  # 要牌过程
    # print(P_INFO_TWO)
    print(RESULT)                                   # 打印最终结果字典
    
    # 5、判断胜者
    # 字典排序
    win_sorted = sorted(RESULT.items(),key=lambda x:x[1],reverse=True)
    # print(win_sorted)
    count = 1
    while count < len(win_sorted):
        if win_sorted[count-1][1] != win_sorted[count][1]:
            print("胜者是{}".format(win_sorted[:count]).center(40,"-"))
            break
        else:
            count += 1
    else:
        exit("没有赢家...")
    
    
    
    这个人虽然不太勤快,但是还是留下了一些什么......
  • 相关阅读:
    如何挖掘需求,覆盖整个系统
    JVM全整理
    7.linux文件与目录管理
    6.linux的文件权限与目录配置
    获取外汇基本汇率
    Pointer-Events: 如何处理ScreenTouch和MouseClicks
    Excel如何快速定位出两列的不同值
    Java数据结构: java.util.BitSet源码学习
    一道面试题与Java位操作 和 BitSet 库的使用
    Test post.
  • 原文地址:https://www.cnblogs.com/lwcccyingziji/p/15059207.html
Copyright © 2020-2023  润新知