• 12/13


    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())

  • 相关阅读:
    深入单机事务
    事务的本质
    云计算是什么?
    linux命令之tail
    linux命令之rpm
    String、StringBuffer与StringBuilder区别
    自定义今天的520
    logback中MDC使用
    数组(转载)
    spring获取webapplicationcontext,applicationcontext几种方法详解(转载)
  • 原文地址:https://www.cnblogs.com/ZHang-/p/10115980.html
Copyright © 2020-2023  润新知