本文整理汇总了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())
示例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()