本文整理汇总了Python中Deck.Deck.drawCard方法的典型用法代码示例。如果您正苦于以下问题:Python Deck.drawCard方法的具体用法?Python Deck.drawCard怎么用?Python Deck.drawCard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Deck.Deck
的用法示例。
在下文中一共展示了Deck.drawCard方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import drawCard [as 别名]
class Game(object):
'''
This represents a game of UNO. It keeps track of a list of the players currently involved in the game.
'''
def __init__(self):
''' Creates a new Game. '''
self._playerList = []
self._deck = Deck()
self._deck.shuffle()
self._discardPile = DiscardPile()
self._currentPlayer = 0
self._currentCard = self._deck.drawCard()
self._blankCards = {
'blue' : Card('blue', 'blank'),
'yellow' : Card('yellow', 'blank'),
'red' : Card('red', 'blank'),
'green' : Card('green', 'blank')}
def getDeck(self):
''' Returns the deck used for this game '''
return self._deck
def addPlayerToGame(self, name):
''' Add a human player to the game '''
self._playerList.append(Player(name, self._deck.draw7Cards()))
def addAIPlayerToGame(self, name):
''' Add an AI player to the game '''
self._playerList.append(AIPlayer(name, self._deck.draw7Cards()))
def getCurrentCard(self):
''' Returns the current card in play for this game '''
return self._currentCard
def isFinished(self):
''' Returns True if the game is finished, that is if one player has 0 cards '''
for player in self._playerList:
if len(player.getCurrentHand()) == 0:
return True
return False
def testMove(self, card):
''' Test to see if the Card card is a valid move given the current card in play '''
if not self.currentPlayer().testMove(self._currentCard, card):
raise InvalidMoveException
def hasUno(self, player):
''' Returns True if the Player player has UNO, that is has only one card left '''
return len(player.getCurrentHand()) == 1
def nextPlayerHasUno(self):
''' Returns true if the next player has UNO (to help the AI) '''
try:
return len(self._playerList[self._currentPlayer-1].getCurrentHand) == 1
except:
return len(self._playerList[0].getCurrentHand()) == 1
def applySpecial(self,card, color=None):
''' Applies the special ability of Card card. '''
ability = card.getData()
if ability == 'skip':
self._currentPlayer+=1
if self._currentPlayer >= len(self._playerList):
self._currentPlayer = 0
return True
elif ability == 'reverse':
self._playerList = self._playerList[::-1] #reverse the list
if len(self._playerList) > 2:
self._currentPlayer = abs(self._currentPlayer-len(self._playerList)) #fix order
if self._currentPlayer > len(self._playerList)-1:
self._currentPlayer=0
return len(self._playerList) == 2
elif ability == 'draw 2':
try:
nextplayer = self._playerList[self._currentPlayer+1]
self.playerDrawCard(nextplayer, 2)
self._currentPlayer+=1
except:
self.playerDrawCard(self._playerList[0], 2)
self._currentPlayer = 0
return True
elif ability == 'wild' or ability == 'wild draw four':
self._currentCard = self._blankCards[color]
if ability == "wild draw four":
try:
nextplayer = self._playerList[self._currentPlayer+1]
self.playerDrawCard(nextplayer, 4)
self._currentPlayer+=1
except:
self.playerDrawCard(self._playerList[0], 4)
self._currentPlayer=0
return True
def playerDrawCard(self, player, amount):
try:
player.giveCard(self._deck.drawCard(amount))
except EmptyDeckException:
self._discardPile.shuffle()
self._deck = self._discardPile
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import drawCard [as 别名]
#.........这里部分代码省略.........
### Ask for bets
bets = []
for i in range(len(self.players)):
keepAsking = True
while (keepAsking):
questionText = ""
if verbose:
questionText = self.players[i].getName() + ", what is your bet (10) ? "
inputBet = self.strategyList[i].getInput(questionText, "BET", cardCount=self.cardCountCorrected)
## Default bet
if inputBet == "":
inputBet = defaultBet
try:
currentBet = int(inputBet)
if (currentBet <= self.players[i].getMoney()):
keepAsking = False
bets.append(currentBet)
else:
if verbose:
print "You dont have enough money to place this bet !"
else:
## In case of AI playing, all in if not enough money left
keepAsking = False
bets.append(self.players[i].getMoney())
except ValueError:
print "Not a valid bet !"
### Give cards to players + to dealer
dealerCards = self.deck.drawCard(2)
if verbose:
print BlackJack.displayDealerCards(self, dealerCards)
dealerCardNumber = self.deck.cardNumber(dealerCards[0])
self.logDF['dealerCardNumber'][self.currentRoundNumber] = dealerCardNumber
self.logDF['dealerCardName'][self.currentRoundNumber] = self.deck.cardNames[dealerCardNumber]
playerCards = []
for i in range(len(self.players)):
cards = self.deck.drawCard(2)
playerCards.append(cards)
if verbose:
print BlackJack.displayPlayerCards(self, playerCards)
### If dealer has Ace, player can choose insurance
if(self.deck.cardNumber(dealerCards[0]) == 0):
for i in range(len(self.players)):
questionText = ""
if verbose:
questionText = self.players[i].getName() + ", do you want the insurance Y/N (N) ?"
playerAction = self.strategyList[i].getInput(questionText, "INSURANCE")
if playerAction == "Y":
insurancesList[i] = True
### Ask for players' actions
i = 0 ## i counts the number of players (including splits)