本文整理汇总了Python中hand.Hand.noOfCardsInHand方法的典型用法代码示例。如果您正苦于以下问题:Python Hand.noOfCardsInHand方法的具体用法?Python Hand.noOfCardsInHand怎么用?Python Hand.noOfCardsInHand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hand.Hand
的用法示例。
在下文中一共展示了Hand.noOfCardsInHand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import noOfCardsInHand [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())