20181213hw
小作业8
实现发牌器(排中不包含大小鬼),共4个玩家,没人13张牌
import random
class Card( object ):
count = 0
def __init__( self , number , pattern = '' , is_cover = 1 ):
self.temp = number
self.number = number
self.pattern = pattern
self.is_cover = is_cover
Card.count += 1
def setNumber( self , number ):
self.number = number
return None
def setPattern( self , pattern ):
self.pattern = pattern
return None
def setIs_cover( self , is_cover ):
self.is_cover = is_cover
return None
def getNumber( self ):
return None if self.is_cover else self.number
def getPattern( self ):
return None if self.is_cover else self.pattern
def getIs_cover( self ):
return self.is_cover
def getCount( self ):
return self.count
def setCard( self ):
self.setNumber( self.number % 13 if self.number % 13 else 13 )
p = ( self.temp - 1 ) // 13 + 3
num_pattern = { 3:' ♥ ' , 4:' ♦ ' , 5:' ♣ ' , 6:' ♠ ' }
self.setPattern( num_pattern[ p ] )
self.setIs_cover( 0 )
def card_info( self ):
return ( self.getNumber() , self.getPattern() , self.getIs_cover() )
def player_card_info( self ):
return ( self.getPattern() + str( self.getNumber() ) )
cards = [ i for i in range( 1 , 53 ) ]
players = [ [] , [] , [] , [] ]
def shuffle_cards():
global cards
return random.shuffle( cards )
#test
# c = Card( 2 )
# c.setCard()
# print( c.card_info() )
def deal_card():
global cards
global players
shuffle_cards()
for i in cards:
c = Card( i )
c.setCard()
players[ cards.index( i ) // 13 ].append( c.player_card_info() )
deal_card()
for i in players:
print( i )