本文整理匯總了Python中cards.Deck.get_number_of_cards_left方法的典型用法代碼示例。如果您正苦於以下問題:Python Deck.get_number_of_cards_left方法的具體用法?Python Deck.get_number_of_cards_left怎麽用?Python Deck.get_number_of_cards_left使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cards.Deck
的用法示例。
在下文中一共展示了Deck.get_number_of_cards_left方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from cards import Deck [as 別名]
# 或者: from cards.Deck import get_number_of_cards_left [as 別名]
class BlackJack:
"""Main class of pyBlackJack. Define a BlackJack game with a 6-deck shoe, one player and one dealer."""
def __init__(self):
# Create the deck
self.deck = Deck(6)
# Create the player
self.player = Player(self.deck)
# Create the dealer
self.dealer = Dealer(self.deck, [self.player])
def start(self):
"""Starts the game. A game ends when the player has no more chips."""
# Print game's title
asciiArts.print_title()
utils.print_separator()
# While the player has enough money to play
while self.player.get_bankroll() > 0:
# Display player's bankroll
print("Your current bankroll is: " + str(self.player.get_bankroll())) + " chips."
# Play a game
self.play()
# End
self.end()
print("Thank you for playing pyBlackJack!")
def play(self):
"""Play a round. The player first bets and then play his hand(s)."""
# Clear player's and dealer's hand
self.player.clear()
self.dealer.clear()
#################
# Ask for a bet #
#################
bet = self.bet_step()
# Register player's bet
self.player.bet(bet)
##############
# Deal cards #
##############
# If the dealer has dealt 75% of the cards, then shuffle a new deck
if self.deck.get_number_of_cards_left() < 78:
self.deck = Deck(6)
print("Dealing...")
self.dealer.deal()
utils.print_separator()
self.print_dealer_hand(False)
#########
# Split #
#########
self.split_step()
##############
# Play Hands #
##############
for i in range(len(self.player.hands)):
self.player.hand = self.player.hands[i]
self.play_hand(i)
def end(self):
"""End of player's turn. The dealer plays and unveils his cards. The results are then displayed."""
self.dealer.unveil_cards()
self.dealer.hit_long()
self.print_dealer_hand(True)
self.display_results()
def bet_step(self):
"""The player choses how many chips he wants to bet."""
while True:
# Ask for the bet
bet = utils.read_integer("Enter your bet (1 chip minimum): ")
bankroll = self.player.get_bankroll()
# If the bet is less than player's bankroll and higher than 1 chip, play the round
if bet <= bankroll and bet >= 1:
return bet
# The bet is higher than player's bankroll
elif bet >= bankroll:
print("You cannot bet more than your current bankroll!")
continue
# The bet is lower than 1 chip
elif bet < 1:
print("The minimum bet is 1 chip!")
continue
#.........這裏部分代碼省略.........