扑克11点游戏(python代码)
import random
'''
纸牌11点游戏
规则:
1. 3个⼈参与,默认先给⽤户发⼀张牌,其中 J、Q、K、⼩王、⼤王代表的值为0.5,其他就是则就是当前的牌⾯值。
python可以做什么游戏2. 随机顺序开始轮流抽牌,可以不抽,就得到点数
3. 超过11点爆炸出局,最接近11点的获胜
result={'player1':10,
'player2':8,
'player3':0}
'''
# ⽣成⼀副牌. The suits are called hearts, clubs, diamonds and spades.
poker_cards = []
for s in ['⿊桃', '草花', '红⼼', '⽅⽚']:
for n in range(1, 14):
poker_cards.append((s, n))
poker_cards.append(('joker', 14))
poker_cards.append(('joker', 15))
# print(poker_cards)
# print(len(poker_cards))
# ⽣成玩家
players = []
play_num = int(input("⼏个⼈玩 ? "))
for i in range(play_num):
players.append(input("玩家 {}:".format(i + 1)))
print(players)
result = {}
# ⽣成当前玩家过程
while players:
now_player = players.pop(random.randint(0, len(players) - 1))
now_pick = []
while True:
msg1 = "{player},你要抽牌还是不抽?(y/n)".format(player=now_player)
choice = input(msg1)
if choice.lower() == 'y':
pick_card = poker_cards.pop(random.randint(0, len(poker_cards) - 1))
now_pick.append(pick_card)
if 1 <= pick_card[1] <= 10:
card_value = pick_card[1]
else:
card_value = 0.5
player_score = (now_player, 0)
player_score += card_value
result[now_player] = player_score
if player_score <= 11:
msg2 = "{player},你抽到的牌是:{pick},现有牌组{cards},你的总分是 {score} .".format(player=now_player, pick=pick_card,
cards=now_pick,
score=player_score)
print(msg2)
else:
player_score = 0
result[now_player] = player_score
msg3 = "{player},你抽到的牌是:{pick},现有牌组{cards},总分>11,你爆了,分数归0".format(player=now_player, pick=pick_card, cards
=now_pick, )
print(msg3)
break
elif choice.lower() == 'n':
player_score = (now_player, 0)
msg4 = "{player},你选择不抽牌,你的总分是 {score} . 等待结果吧".format(
player=now_player, score=player_score)
print(msg4)
result[now_player] = player_score
break
else:
print("输⼊错误,请重试。")
for k, v in result.items():
msg5 = "{name} 的总分是 {score}".format(name=k, score=v)
print(msg5)
# 结果演⽰:
#
# ⼏个⼈玩 ? 3
# 玩家 1:a
# 玩家 2:b
# 玩家 3:c
# ['a', 'b', 'c']
# c,你要抽牌还是不抽?(y/n)y
# c,你抽到的牌是:('草花', 12),现有牌组[('草花', 12)],你的总分是 0.5 .
# c,你要抽牌还是不抽?(y/n)y
# c,你抽到的牌是:('红⼼', 8),现有牌组[('草花', 12), ('红⼼', 8)],你的总分是 8.5 .
# c,你要抽牌还是不抽?(y/n)n
# c,你选择不抽牌,你的总分是 8.5 . 等待结果吧
# b,你要抽牌还是不抽?(y/n)y
# b,你抽到的牌是:('⿊桃', 7),现有牌组[('⿊桃', 7)],你的总分是 7 .
# b,你要抽牌还是不抽?(y/n)y
# b,你抽到的牌是:('草花', 5),现有牌组[('⿊桃', 7), ('草花', 5)],总分>11,你爆了,分数归0 # a,你要抽牌还是不抽?(y/n)n
# a,你选择不抽牌,你的总分是 0 . 等待结果吧
# c 的总分是 8.5
# b 的总分是 0
# a 的总分是 0
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论