标签:main numbers color pop and imp 分享 图片 ima
from random import shuffle class Card(object): colors = [‘黑桃‘,‘方片‘,‘红心‘,‘梅花‘] numbers = [‘A‘]+ [str(i) for i in range(2,11)]+ [‘J‘]+ [‘Q‘]+ [‘K‘] def __init__(self,color,number,face= True): self._color = color self._number = number self._face = face def show(self): if self._face: return self._color + self._number else: return ‘x‘ def flip(self): self._face = not self._face class Hand(object): def __init__(self,name = ‘神秘玩家‘): self._name = name self._cards = [] def addcard(self,card): self._cards.append(card) def show(self): end = [] for c in self._cards: end.append(c.show()) return ‘,‘.join(end) class Poke(Hand): def allcard(self): for c in Card.colors: for n in Card.numbers: self._cards.append(Card(c,n)) def randpoke(self): shuffle(self._cards) def dealpoke(self,hands,count = 13): for c in range(count): for h in hands: poppoke = self._cards.pop() h.addcard(poppoke) if __name__ ==‘__main__‘: poke = Poke() poke.allcard() poke.randpoke() hands = [Hand(‘小猪‘),Hand(‘小狗‘),Hand(‘蜈蚣‘),Hand(‘老虎‘)] poke.dealpoke(hands) for h in hands: print(h._name,h.show())
标签:main numbers color pop and imp 分享 图片 ima
原文地址:https://www.cnblogs.com/ZHang-/p/10115980.html