您的位置:首页 > 财经 > 产业 > 京东企业门户_网页前端技术_新媒体运营工作是什么_网站seo分析案例

京东企业门户_网页前端技术_新媒体运营工作是什么_网站seo分析案例

2024/12/23 2:54:06 来源:https://blog.csdn.net/weixin_52642840/article/details/143131114  浏览:    关键词:京东企业门户_网页前端技术_新媒体运营工作是什么_网站seo分析案例
京东企业门户_网页前端技术_新媒体运营工作是什么_网站seo分析案例

斗地主发牌程序:
模拟一个斗地主发牌程序,实现对三个玩家进行手牌的派发,实现功能:

需要展示 玩家 的所有手牌,要求按照从小到大的顺序排序,相同点数的情况下,按照 黑桃 > 红桃 > 方片 > 梅花 的大小关系排列

import randomclass Card:def __init__(self, point, color, big):self.color = colorself.point = pointself.big = bigdef __str__(self):return f"({self.point},{self.color})"def __repr__(self):return f"Card({self.point},{self.color})"class Player:def __init__(self, name, listCard):self.name = nameself.listCard = listCarddef __str__(self):return f"({self.name},{self.listCard})"def __repr__(self):return f"Player({self.name},{self.listCard})"def custom_sort(card1):return card1.pointlistNum = ["3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"]
listColor = ["♣", "♦", "♥", "♠"]
listCard = []
i = 1
for num in listNum:for color in listColor:listCard.append(Card(num, color, i))i += 1
listCard.append(Card("🃏", "红", 200))
listCard.append(Card("🃏", "黑", 100))print("*" * 10 + " 欢迎进入 XX 斗地主 " + "*" * 10)
aName = input("请输入A玩家姓名:")
aListCard = []
bName = input("请输入B玩家姓名:")
bListCard = []
cName = input("请输入B玩家姓名:")
cListCard = []
print("洗牌中...")
print("洗牌完成!")print("发牌中...")while len(listCard) != 3:if (len(listCard) - 3) % 3 == 0:index = random.randint(0, len(listCard) - 1)aListCard.append(listCard.pop(index))elif (len(listCard) - 3) % 3 == 1:index = random.randint(0, len(listCard) - 1)bListCard.append(listCard.pop(index))elif (len(listCard) - 3) % 3 == 2:index = random.randint(0, len(listCard) - 1)cListCard.append(listCard.pop(index))print("发牌完成!")
landName = input("谁叫地主?")
if landName == aName:aListCard.extend(listCard)
elif landName == bName:bListCard.extend(listCard)
else:cListCard.extend(listCard)listCard.sort(key=lambda card: card.big)
aListCard.sort(key=lambda card: card.big)
bListCard.sort(key=lambda card: card.big)
cListCard.sort(key=lambda card: card.big)
aPlayer = Player(aName, aListCard)
bPlayer = Player(bName, bListCard)
cPlayer = Player(cName, cListCard)
print(listCard)
print(aPlayer)
print(bPlayer)
print(cPlayer)
********** 欢迎进入 XX 斗地主 **********
请输入A玩家姓名:zhangsan
请输入B玩家姓名:lisi
请输入B玩家姓名:wangwu
洗牌中...
洗牌完成!
发牌中...
发牌完成!
谁叫地主?zhangsan
[Card(7,♦), Card(9,♦), Card(2,♣)]
(zhangsan,[Card(3,♥), Card(3,♠), Card(4,♣), Card(4,♠), Card(5,♣), Card(5,♦), Card(5,♥), Card(7,♦), Card(8,♥), Card(9,♦), Card(10,♣), Card(10,♥), Card(J,♦), Card(J,♥), Card(Q,♣), Card(K,♣), Card(K,♦), Card(K,♠), Card(A,♦), Card(2,♣)])
(lisi,[Card(3,♣), Card(4,♦), Card(4,♥), Card(5,♠), Card(6,♦), Card(6,♥), Card(7,♣), Card(7,♥), Card(9,♣), Card(9,♥), Card(10,♠), Card(J,♠), Card(Q,♦), Card(Q,♥), Card(Q,♠), Card(2,♠), Card(🃏,黑)])
(wangwu,[Card(3,♦), Card(6,♣), Card(6,♠), Card(7,♠), Card(8,♣), Card(8,♦), Card(8,♠), Card(9,♠), Card(10,♦), Card(J,♣), Card(K,♥), Card(A,♣), Card(A,♥), Card(A,♠), Card(2,♦), Card(2,♥), Card(🃏,红)])

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com