当前位置: 首页>>代码示例>>Python>>正文


Python Deck.dealer_play方法代码示例

本文整理汇总了Python中Deck.Deck.dealer_play方法的典型用法代码示例。如果您正苦于以下问题:Python Deck.dealer_play方法的具体用法?Python Deck.dealer_play怎么用?Python Deck.dealer_play使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Deck.Deck的用法示例。


在下文中一共展示了Deck.dealer_play方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: play_game

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import dealer_play [as 别名]
def play_game():
    
    deck = Deck()
    bankroll = Bankroll()
    
    deck.shuffle()
    
    print(f"Current bankroll is {bankroll.player_bank}")
    dep_draw = input("Deposit/Withdraw? D/W or Enter to pass: ").upper()
            
    # BANKROLL: Deposit
    if dep_draw == "D" or bankroll.player_bank <= 0:
        while True:
            try:
                if bankroll.player_bank <=0:
                    print("Sorry your bankroll is 0!")
                bankroll.deposit(int(input("Please enter deposit amount: ")))
            except:
                print("Whoops! That is not a number")
            else:
                break

    # BANKROLL: Withdraw        
    if dep_draw == "W":
        while True:
            try:
                bankroll.withdraw(int(input("Please enter withdraw amount: ")))
            except:
                print("Whoops! That is not a number")
            else:
                break
    
    # BANKROLL: Place bet
    while True:
        try:
            bankroll.bet(int(input("Please place your bet: ")))
        except:
            print("Whoops! That is not a number")
        else:
            break
    
    
    # RUN GAME (Consider adding to 'Game' class as .deal_game)
    for i in range(4):
        if deck.turn == 'Player':
            deck.turn = 'Dealer'
        else:
            deck.turn = 'Player'
        
        deck.draw_card()
        deck.tally()
            
    print(f"Dealer: {deck.dealer_hand[0]}")
    print(f"Player: {deck.player_hand}")
    print(f"Player count: {deck.player_count_A11} & {deck.player_count_A1}")
    
    play = True
    hit_stand = ''
    while play:
        invalid_play = True
        while invalid_play:
            hit_stand = input("Hit or stand? H/S: ").upper()
            invalid_play = (hit_stand != 'H' and hit_stand != 'S')
            if invalid_play:
                print ("Please enter either 'H' or 'S'.")                      
        deck.player_play(hit_stand)  
        print(f"\nPlayer: {deck.player_hand}")
        print(f"Player count: {deck.player_count_A11} & {deck.player_count_A1}")
        play = ((deck.player_count_A11 < 21 or deck.player_count_A1 < 21) and
               (deck.player_count_A11 != 21 and deck.player_count_A1 != 21) and hit_stand == "H")
    
    if deck.player_count_A11 > 21 and deck.player_count_A1 > 21:
        # Player loses
        print("Bust")
    else:
        while (deck.score_check()[1] != -1) and (deck.score_check()[0]  > deck.score_check()[1]) and (deck.dealer_count_A1 < 17):
            deck.dealer_play("H")       
    
    print("\n")
    print(deck.player_hand)
    print(deck.dealer_hand)
    print(deck.dealt)
    print(f"Player count: {deck.player_count_A11} & {deck.player_count_A1}")
    print(f"Dealer count: {deck.dealer_count_A11} & {deck.dealer_count_A1}")
        
    if deck.score_check()[0]  > deck.score_check()[1]:        
        print("Player wins!")
        bankroll.player_bank += bankroll.curr_bet
        print(f"Your bankroll is now: {bankroll.player_bank}")
    elif deck.score_check()[0] == deck.score_check()[1]:
        print("Push! Bets returned")
        print(f"Your bankroll is now: {bankroll.player_bank}")
    else:
        print("Dealer wins!")
        bankroll.player_bank -= bankroll.curr_bet
        print(f"Your bankroll is now: {bankroll.player_bank}")
        
    make_deposit = "N"
    make_withdraw = "N"
开发者ID:vindard,项目名称:Learning-Python,代码行数:101,代码来源:play_game.py


注:本文中的Deck.Deck.dealer_play方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。