python模拟刘谦2024春晚扑克牌魔术代码
代码语言:python
所属分类:其他
代码描述:python模拟刘谦2024春晚扑克牌魔术代码
代码标签: python 模拟 刘谦 2024 春晚 扑克牌 魔术 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
#!/usr/local/python3/bin/python3 # -*- coding: utf-8 -* # 魔术模拟类 import random class MagicTrickSimulation: def __init__(self): # 初始化扑克牌集合,包含52张牌和大小王 self.full_deck = ['A♠', '2♠', '3♠', '4♠', '5♠', '6♠', '7♠', '8♠', '9♠', '10♠', 'J♠', 'Q♠', 'K♠', 'A♣', '2♣', '3♣', '4♣', '5♣', '6♣', '7♣', '8♣', '9♣', '10♣', 'J♣', 'Q♣', 'K♣', 'A♥', '2♥', '3♥', '4♥', '5♥', '6♥', '7♥', '8♥', '9♥', '10♥', 'J♥', 'Q♥', 'K♥', 'A♦', '2♦', '3♦', '4♦', '5♦', '6♦', '7♦', '8♦', '9♦', '10♦', 'J♦', 'Q♦', 'K♦', 'Joker1', 'Joker2'] # 从完整牌组中随机选择4张牌 self.cards = random.sample(self.full_deck, 4) self.hidden_card = None def shuffle(self): # 洗牌:将第一张牌放到末尾 card = self.cards.pop(0) self.cards.append(card) print(f"洗牌:{self.cards}") def pop_card(self): # 弹出一张牌 card = self.cards.pop(0) print(f"弹出牌:{card},剩余牌:{self.cards}") return card def fold_and_tear(self): # 对纸牌进行对折撕裂,每张纸牌分成两半 self.cards = [f'{card}_1' for card in self.cards] + [f'{card}_2' for card in self.cards] print(f"对折撕裂:{self.cards}") def shuffle_based_on_name(self, name_length): # 根据姓名的字数进行洗牌 for _ in range(name_length): self.shuffle() def insert_first_three_cards(self): # 将前三张牌插入到中间位置 first_three = self.cards[:3] self.cards = self.cards[3:] middle = len(self.cards) // 2 self.cards[middle:middle] = first_three print(f"将前三张牌插入中间:{self.cards}") def hide_top_card(self): # 隐藏牌堆顶部的第一张牌 self.hidden_card = self.cards.pop(0) print(f"隐藏的牌:{self.hidden_card}") def regional_operation(self, region): # 根据地区进行操作 if region == 'south': self.cards.insert(len(self.cards) // 2, self.pop_card()) elif region == 'north': for _ in range(2): self.cards.insert(len(self.cards) // 2, self.pop_card()) else: for _ in range(3): self.cards.insert(len(self.cards) // 2, self.pop_card()) print(f"{region}地区操作:{self.cards}") def gender_operation(self, gender): # 根据性别进行操作 if gender == 'male': self.pop_card() self.pop_card(.........完整代码请登录后点击上方下载按钮下载查看
网友评论0