import randomclass PokerGame: def __init__(self): self.poker = ['♣2', '♥2', '♦2', '♠2', '♣3', '♥3', '♦3', '♠3', '♣4', '♥4', '♦4', '♠4', '♣5', '♥5', '♦5', '♠5', '♣6', '♥6', '♦6', '♠6', '♣7', '♥7', '♦7', '♠7', '♣8', '♥8', '♦8', '♠8', '♣9', '♥9', '♦9', '♠9', '♣10', '♥10', '♦10', '♠10', '♣J', '♥J', '♦J', '♠J', '♣Q', '♥Q', '♦Q', '♠Q', '♣K', '♥K', '♦K', '♠K', '♣A', '♥A', '♦A', '♠A', 'JOKER', 'joker'] def __repr__(self): return f'{str(self.__dict__)[10:-1]}' @staticmethod def give_card(poker): # 发牌 player1 = [] player2 = [] player3 = [] num = 0 index = 0 # 给三个人发牌 while num != 17: player1.append(poker[index]) player2.append(poker[index+1]) player3.append(poker[index+2]) num += 1 index += 3 # 定义牌大小规则 rule = {'♣3': 0, '♥3': 0, '♦3': 0, '♠3': 0, '♣4': 1, '♥4': 1, '♦4': 1, '♠4': 1, '♣5': 2, '♥5': 2, '♦5': 2, '♠5': 2, '♣6': 3, '♥6': 3, '♦6': 3, '♠6': 3, '♣7': 4, '♥7': 4, '♦7': 4, '♠7': 4, '♣8': 5, '♥8': 5, '♦8': 5, '♠8': 5, '♣9': 6, '♥9': 6, '♦9': 6, '♠9': 6, '♣10': 7, '♥10': 7, '♦10': 7, '♠10': 7, '♣J': 8, '♥J': 8, '♦J': 8, '♠J': 8, '♣Q': 9, '♥Q': 9, '♦Q': 9, '♠Q': 9, '♣K': 10, '♥K': 10, '♦K': 10, '♠K': 10, '♣A': 11, '♥A': 11, '♦A': 11, '♠A': 11, '♣2': 12, '♥2': 12, '♦2': 12, '♠2': 12, 'joker': 13, 'JOKER': 14} new_player1 = sorted(player1, key=lambda x: rule[x]) new_player2 = sorted(player2, key=lambda x: rule[x]) new_player3 = sorted(player3, key=lambda x: rule[x]) new_undercard = sorted(poker[-3:], key=lambda x: rule[x]) # 底牌 print(f'Player1:{new_player1 }') print(f'Player2:{new_player2}') print(f'Player3:{new_player3}') print(f'底牌:{new_undercard}') def shuffle_the_deck(self): # 洗牌 self.poker = str(self.__dict__)[10:-1] self.poker = eval(self.poker) random.shuffle(self.poker) return self.pokerpoker1 = PokerGame()poker2 = poker1.shuffle_the_deck() # 洗牌poker1.give_card(poker2) # 发牌
总结 以上是内存溢出为你收集整理的Python斗地主扑克牌游戏全部内容,希望文章能够帮你解决Python斗地主扑克牌游戏所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)