本文整理汇总了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
#.........这里部分代码省略.........