码迷,mamicode.com
首页 > 其他好文 > 详细

12/13

时间:2018-12-14 17:19:43      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:main   numbers   color   pop   and   imp   分享   图片   ima   

  1. 实现发牌器(排中不包含大小鬼),共4个玩家,每人13张牌
    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())

    技术分享图片

12/13

标签:main   numbers   color   pop   and   imp   分享   图片   ima   

原文地址:https://www.cnblogs.com/ZHang-/p/10115980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!