当前位置: 首页>>代码示例>>Python>>正文


Python Hand.addCards方法代码示例

本文整理汇总了Python中hand.Hand.addCards方法的典型用法代码示例。如果您正苦于以下问题:Python Hand.addCards方法的具体用法?Python Hand.addCards怎么用?Python Hand.addCards使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hand.Hand的用法示例。


在下文中一共展示了Hand.addCards方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Game

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import addCards [as 别名]
class Game(object):
    MAXPOINTS = 16
    SPEED = 100
    
    def __init__(self):
        self.__players = []
        self.__board = Hand()
        self.__deck = Deck()
        self.nextInTurn = 0
        self.nextDealer = -1
        self.extraCardPoints=0
        self.extraSpadesPoints=0
        self.lastRaise=None
        
    def initForNewRound(self):
        self.__deck = Deck()
        for pl in self.__players:
            pl.setHand(self.deal(4))
            pl.clearStack()
            pl.clearCottages()
        self.lastRaise=None
        self.nextDealer += 1
        self.nextInTurn = self.nextDealer+1
        self.initBoard()
        
    def addPlayer(self,playerName, tyyppi):
        player = Player(playerName,tyyppi)
        self.__players.append(player)
    
    def addPlayer2(self,player):
        self.__players.append(player)
    
    def getPlayers(self):
        return self.__players
    
    def getNextInTurn(self):
        pl = self.__players[self.nextInTurn%len(self.__players)]
        self.nextInTurn+=1
        return pl
    
    def initBoard(self):
        cards = self.__deck.deal(4)
        self.__board.addCards(cards)
        
    def getBoard(self):
        return self.__board
        
    
    '''
    Checks if game is over/ someone has 16 or more points
    '''
    def gameOver(self):
        for player in self.__players:
            if player.getPoints()>=Game.MAXPOINTS:
                return True
        return False
        
    def deal(self,amount):
        return self.__deck.deal(amount)
    
    def nextInTurnType(self):
        return self.__players[self.nextInTurn%len(self.__players)].getType()
    
    def getDeck(self):
        return self.__deck
    
    '''
    returns boolean value determining if round should be continued i.e.  if cards are left on deck or on players hands
    '''
    def continueRound(self):
        if self.getDeck().cardsLeft()>0:
            return True
        for pl in self.getPlayers():
            if pl.hasCards():
                return True
        return False
    
    '''
    This function deals the card on board to the player who was the last one to raise cards
    '''
    def dealBoardToLatest(self):
        if len(self.getBoard().getCards())>0:
            try:
                self.lastRaise.addCardsToStack(self.getBoard().getCards())
                self.getBoard().clear()
            except AttributeError:
                self.getBoard().clear()
        
    '''
    THIS FUNCTION IS NOT USED ANYMORE FOR ANYTHING
    This function returns the minimum limit used in computerPlayerIO's chooseCardToTable function to determine the MIVALUE-limit
    '''            
    def getMinLimit(self):
        cards=[]
        c10=Card(10,Card.DIAMONDS)
        s2=Card(2,Card.SPADES)
        for pl in self.__players:
            cards.extend(pl.getStack().getCards())
        #cards.sort()
        am=[0]*13
#.........这里部分代码省略.........
开发者ID:severi,项目名称:Casino,代码行数:103,代码来源:game.py

示例2: Player

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import addCards [as 别名]
class Player(object):
    HUMAN = 1
    COMPUTER = 0
    
    def __init__(self,name,tyyppi):
        self.__name=name
        self.__cottages=0
        self.__points=0
        self.__hand = Hand()
        self.__type = tyyppi
        self.__stack = Hand()
        
    '''
    name methods
    '''
    def getName(self):
        return self.__name
        
    '''
    point methods
    '''
    def updatePoints(self,amount):
        self.__points += amount
        
    def setPoints(self,amount):
        self.__points = amount
        
    def getPoints(self):
        return self.__points
        
    '''
    cottage methods
    '''
    def getCottages(self):
        return self.__cottages  
        
    def raiseCottages(self,amount):
        self.__cottages+=amount
        
    def setCottages(self,amount):
        self.__cottages=amount
        
    def clearCottages(self):
        self.__cottages=0
        
    '''
    hand methods
    '''
    def getHand(self):
        return self.__hand
    
    def addCardsToHand(self,cards):
        self.__hand.addCards(cards)
            
    def addCardToHand(self,card):
        self.__hand.append(cards)
    
    def setHand(self,cards):
        self.__hand.clear()
        self.__hand.addCards(cards)
    
    def hasCards(self):
        return len(self.__hand.getCards())>0
    
    '''
    stack methods
    '''
    def getStack(self):
        return self.__stack
    
    def clearStack(self):
        self.__stack=Hand()
    
    def addCardsToStack(self,cards):
        for card in cards:
            self.addCardToStack(card)
            
    def addCardToStack(self,card):
        self.__stack.addCard(card)
    
    def setStack(self,cards):
        self.__stack.clear()
        self.__stack.addCards(cards)
    
    '''
    type methods
    '''
    def getType(self):
        return self.__type
            
    '''
    other methods
    '''
    def getScoreFromStack(self):
        points = self.__cottages
        points += self.__stack.getSureValue()
        return points
    
    def __str__(self):
        return self.__name+"-"+str(self.__points)
#.........这里部分代码省略.........
开发者ID:severi,项目名称:Casino,代码行数:103,代码来源:player.py


注:本文中的hand.Hand.addCards方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。