# -*- codeing: utf-8 -*-
# Project: 棋牌游戏11点
# Author: jack
# Version: 2.2
# Start Time: 2021-07-24 import random P_INFO = [["小王",0.5],["大王",0.5]] # 初始一副poker牌
USER_LIST = ["庄家","玩家1","玩家2"] # 玩家信息表
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("{}选择是否要牌,输入N/n不要牌,回车继续要牌:".format(USER_LIST[count])).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("{}现在的牌面是:{}".format(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)+1:
if win_sorted[count-1][1] != win_sorted[count][1]:
print("胜者是{}".format(win_sorted[:count]).center(40,"-"))
break
else:
count += 1

最新文章

  1. ashx中Response.ContentType的常用类型
  2. atoi()函数
  3. JavaScript定时器
  4. BZOJ 1004
  5. IOS 弹出式 POPMenuView
  6. Swing圆角边框的实现
  7. Linux Add a Swap File
  8. angularjs 中ie兼容性的问题收集
  9. linux kernel API and google android compile guide
  10. tomcat install on Linux
  11. Why Doesn’t Drag-and-Drop work when my Application is Running Elevated? – A: Mandatory Integrity Control and UIPI(转载)
  12. 基于visual Studio2013解决C语言竞赛题之0205位数求和
  13. LPC2478的外部中断使用
  14. 字典树trie
  15. C#接口和泛型类
  16. Linux 安装vsftpd和ftp客户端
  17. 深入 kernel panic 流程【转】
  18. Job for apache2.service failed because the control process exited with error code. See &quot;systemctl status apache2.service&quot; and &quot;journalctl -xe&quot; for details.
  19. postgresql的启停和创建
  20. 概率和期望dp

热门文章

  1. Spring Cloud专题之二:OpenFeign
  2. 一文彻底理解Apache Hudi的多版本清理服务
  3. 【NX二次开发】Block UI 面收集器
  4. 理解Spring:AOP的原理及手动实现
  5. 连接过的WiFi改了密码之后再次连接不让输入新密码还是用旧密码一直显示连接失败
  6. 01-Tkinter教程-窗口的管理与设置
  7. 基于 electron 实现简单易用的抓包、mock 工具
  8. js笔记22
  9. Elasticsearch查询文档总数
  10. 29、windows下通过zip包方式安装mysql