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


Python Hand.playCard方法代码示例

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


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

示例1: __init__

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import playCard [as 别名]
class Player:
    def __init__(self, id, deck, name = ""):
        self.name = name
        self.id = id
        self.hand = Hand(deck) #Every player has a hand of cards drawn from deck

    def setName(self, name):
        self.name = name

    def getName(self):
        return self.name

    def getId(self):
        return self.id

    def getHand(self):
        return self.hand
    
    def noOfCardsInHand(self):
        return self.hand.noOfCardsInHand()
    
    def askForCardToPlay(self):
        """Input 0 to draw a card."""
        playCardWithIndex = None
        while playCardWithIndex == None:           
            try:
                playCardWithIndex = int(input("Play Card: ")) - 1 #-1 because we want index starting with 0
                if playCardWithIndex >= self.noOfCardsInHand() or playCardWithIndex < -1:
                    print("Wrong number of card!")
                    playCardWithIndex = None 
            except ValueError:
                print('Wrong number of card!')
        return playCardWithIndex
    
    def playCard(self, onOtherCard, deck):
        index = self.askForCardToPlay()
        if index == -1:
            self.drawCards(deck, 1)
            return None
        else:
            cardToPlay = self.hand.playCard(index, keepInHand = True)
            while not cardToPlay.allowedOn(onOtherCard):
                print('Card not allowed')
                index = self.askForCardToPlay()
                if index == -1:
                    self.drawCards(deck, 1)
                    return None
                cardToPlay = self.hand.playCard(index, keepInHand = True)
            return self.hand.playCard(index)
    
    def drawCards(self, deck, amount):
        for card in deck.drawCard(amount):
                self.hand.addCard(card)
    
    def takeTurn(self, deck, topCard, noOfPlayers):
        if topCard.isSpecial():
            if not topCard.didActionHappen(): #Did action already act on a player
                topCard.actionHappens() #Let action happen
                if topCard.isSkip():
                    return 'skip'
                elif topCard.isDraw2():            
                    self.drawCards(deck, 2)
                elif topCard.isDraw4():
                    self.drawCards(deck, 4)
                    return 'skip'
                elif topCard.isReverse(): 
                    if noOfPlayers == 2: #Skip next player if 2 players and reverse card is played
                        return 'skip'
                
        print(self) #Show the current player's hand
        cardToPlay = self.playCard(topCard, deck) #Play a card that's allowed on
                                                  #discard pile or draw a card
        return cardToPlay #Play a card
    
    def isWinner(self):
        if self.hand.noOfCardsInHand() == 0:
            return True
        else:
            return False
        
    def isKi(self):
        return False

    def __str__(self):
        return '%s\n%s' % (self.getName(), self.getHand())
开发者ID:halexus,项目名称:Uno,代码行数:87,代码来源:player.py

示例2: __init__

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import playCard [as 别名]
class Player:
    def __init__(self, name, popularity=50):
        self.name = name
        self.popularity = popularity
        self.deck = Deck(self)
        self.hand = Hand(self.deck)
        self.cardsInGame = []

        def addHealth(self, nb=1):
            self.health += nb
            return self.health

    #
    def drawFromDeck(self):
        return self.deck.draw()

    #
    def inGame(self, card):
        if card in self.cardsInGame:
            return True
        #
        return False

    #
    def noCardOnGame(self):
        if len(self.cardsInGame) == 0:
            return True
        #
        return False

    #
    def drawFromHand(self):
        return self.hand.draw

    #
    def getCard(self, card):
        return self.cardsInGame[card]

    #
    def playCard(self, card):
        if len(self.cardsInGame) < 3:
            self.cardsInGame.append(self.hand.playCard(card))
        else:
            print("ATTENTION : Pas plus de 3 cartes sur votre plateau, vous ne pouvez pas en rajouter")

    #
    def deleteCardFromGame(self, card):
        for current in self.cardsInGame:
            if card.name == current.name:
                # print("DEBUG"+card.name+"== "+current.name)
                self.cardsInGame.remove(current)

    #
    def getCardsOnGame(self):
        print("ID | NOM \t\t| ATTAQUE \t| DEFENSE")
        i = 0
        for current in self.cardsInGame:
            print(str(i) + "  | " + current.name + " \t| " + str(current.power) + " \t| " + str(current.defense))
            i += 1

    #
    def getHand(self):
        return self.getCard()
开发者ID:ChristopheVilleger,项目名称:House-of-Cards---French-Edition,代码行数:65,代码来源:player.py


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