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


Python Deck.dealCard方法代码示例

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


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

示例1: playBJ

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import dealCard [as 别名]
 def playBJ(self):
     
     deck = Deck(self.game_deck_num)
     deck.shuffleDeck()
     in_hand = True
     #print deck.printDeck(self.game_deck_num * 52)
     
     player_card1 = deck.dealCard(in_hand)
     dealer_card1 = deck.dealCard(in_hand)
     player_card2 = deck.dealCard(in_hand)
     dealer_card2 = deck.dealCard(in_hand)
开发者ID:daleinen,项目名称:BlackJackSim_Python,代码行数:13,代码来源:Game.py

示例2: play

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import dealCard [as 别名]
def play():
    deck = Deck()
    dealerHand = Hand()
    playerHand = Hand()

    deck.shuffle()
    dealerHand.addCard( deck.dealCard() )
    dealerHand.addCard( deck.dealCard() )
    playerHand.addCard( deck.dealCard() )
    playerHand.addCard( deck.dealCard() )

    print(" - ")
    print(" - ")

    if dealerHand.getHandValue() == 21:
        print("Dealers cards: ")
        print(dealerHand.getCard(0) + " and " + dealerHand.getCard(1))
        print("Players cards: " + playerHand.getCard(0) + " and " + playerHand.getCard(1))
        print(" ");
        print("Dealer has Blackjack.  Dealer wins.")
        return False

    if playerHand.getHandValue() == 21:
        print("Dealers cards: ")
        print(dealerHand.getCard(0) + " and " + dealerHand.getCard(1))
        print("Players cards: " + playerHand.getCard(0) + " and " + playerHand.getCard(1))
    print(" ");
    print("Player has Blackjack.  Player wins.")
    return True

    while True:
        print(" == ")
    print(" == ")
    print("Players cards: ")
    for i in range(playerHand.getCardCount()):
        print("    " + playerHand.getCard(i))

    print("Player total hand value: " + playerHand.getHandValue())
    print(" ")
    print("Dealers cards: " + dealerHand.getCard(0))
    print(" ")
    choice = input("(H)it or (S)tand?")
    if choice != "H" and choice != "S":
        print("H or S")
        test2 = True

    while test2 == True:
        print(" ")
        choice = input("(H)it or (S)tand?")
        if choice != "H" and choice != "S":
            print("H or S")
            test2 = True
        else:
            test2 = False



    if choice == "S":
        return False
    else:
        drawCard = deck.dealCard()
        playerHand.addCard( drawCard )
        print(" ")
        print("Player hits!")
        print("Player gets card " + drawCard)
        print("Player total is now: " + playerHand.getHandValue())
        if playerHand.getHandValue() > 21:
            print("!")
            print("Player busted!")
            print("Dealer's other card was: " + dealerHand.getCard(1))
        return False

    print("")
    print("Player stands.")
    print("Dealers cards: ")
    print("    " + dealerHand.getCard(0))
    print("    " + dealerHand.getCard(1))


    while dealerHand.getHandValue() <= 16:
        drawCard = deck,dealCard()
        print("Dealer hits and draws a " + drawCard)
        dealerHand.addCard(drawCard)
        if dealerHand.getHandValue() > 21:
            print("!")
            print("Dealer busted! Player wins!")
            return True
    print("Dealer total is " + dealerHand.getHandValue())
    print("-")

    if dealerHand.getHandValue() == playerHand.getHandValue():
        print("It's a tie. Dealer wins.")
        return False
    elif dealerHand.getHandValue() > playerHand.getHandValue():
        print("Dealer wins with the total of: " + dealerHand.getHandValue()) + ". Versus players total:  " + playerHand.getHandValue() + "."
        return False
    else:
        print("Player wins with the total: " + playerHand.getHandValue() + ". Versus dealers total: " + dealerHand.getHandValue())
        return True
开发者ID:bangoluf,项目名称:lufsen,代码行数:101,代码来源:Main.py

示例3: Player

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import dealCard [as 别名]
from Card import Card
from Deck import Deck
from Hand import Hand
from Player import Player

player1 = Player("test")
player2 = Player("test2")

deck = Deck()


player1.hand.addCard( deck.dealCard() )
player1.hand.addCard( deck.dealCard() )
player2.hand.addCard( deck.dealCard() )
player2.hand.addCard( deck.dealCard() )

print("-------------------------------------------")
print("DECK: ")
print("-------------------------------------------")
print(deck)
print("-------------------------------------------")
print("DECK2: ")
print("-------------------------------------------")
print(deck)

print("\n-------------------------------------------")
print("HAND VALUE: ")
print("-------------------------------------------")
print( player1.hand.getHandValue() )
print( player2.hand.getHandValue() )
开发者ID:bangoluf,项目名称:lufsen,代码行数:32,代码来源:Test.py

示例4: play

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import dealCard [as 别名]
def play():
    deck = Deck()
    dealerHand = Hand()
    playerHand = Hand()

    deck.shuffle()
    dealerHand.addCard(deck.dealCard())
    dealerHand.addCard(deck.dealCard())
    playerHand.addCard(deck.dealCard())
    playerHand.addCard(deck.dealCard())

    print ' - '
    print ' - '

    if dealerHand.getHandValue() == 21:
        print 'Dealers cards: '
        print dealerHand.getCard(0) + ' and ' + dealerHand.getCard(1)
        print 'Players cards: ' + playerHand.getCard(0) + ' and ' \
            + playerHand.getCard(1)
        print ' '
        print 'Dealer has Blackjack.  Dealer wins.'
        return False

    if playerHand.getHandValue() == 21:
        print 'Dealers cards: '
        print dealerHand.getCard(0) + ' and ' + dealerHand.getCard(1)
        print 'Players cards: ' + playerHand.getCard(0) + ' and ' \
            + playerHand.getCard(1)
    print ' '
    print 'Player has Blackjack.  Player wins.'
    return True

    while True:
        print ' == '
    print ' == '
    print 'Players cards: '
    for i in range(playerHand.getCardCount()):
        print '    ' + playerHand.getCard(i)

    print 'Player total hand value: ' + playerHand.getHandValue()
    print ' '
    print 'Dealers cards: ' + dealerHand.getCard(0)
    print ' '
    choice = input('(H)it or (S)tand?')
    if choice != 'H' and choice != 'S':
        print 'H or S'
        test2 = True

    while test2 == True:
        print ' '
        choice = input('(H)it or (S)tand?')
        if choice != 'H' and choice != 'S':
            print 'H or S'
            test2 = True
        else:
            test2 = False

    if choice == 'S':
        return False
    else:
        drawCard = deck.dealCard()
        playerHand.addCard(drawCard)
        print ' '
        print 'Player hits!'
        print 'Player gets card ' + drawCard
        print 'Player total is now: ' + playerHand.getHandValue()
        if playerHand.getHandValue() > 21:
            print '!'
            print 'Player busted!'
            print "Dealer's other card was: " + dealerHand.getCard(1)
        return False

    print ''
    print 'Player stands.'
    print 'Dealers cards: '
    print '    ' + dealerHand.getCard(0)
    print '    ' + dealerHand.getCard(1)

    while dealerHand.getHandValue() <= 16:
        drawCard = (deck, dealCard())
        print 'Dealer hits and draws a ' + drawCard
        dealerHand.addCard(drawCard)
        if dealerHand.getHandValue() > 21:
            print '!'
            print 'Dealer busted! Player wins!'
            return True
    print 'Dealer total is ' + dealerHand.getHandValue()
    print '-'

    if dealerHand.getHandValue() == playerHand.getHandValue():
        print "It's a tie. Dealer wins."
        return False
    elif dealerHand.getHandValue() > playerHand.getHandValue():
        print 'Dealer wins with the total of: ' \
            + dealerHand.getHandValue() + '. Versus players total:  ' \
            + playerHand.getHandValue() + '.'
        return False
    else:
        print 'Player wins with the total: ' \
            + playerHand.getHandValue() + '. Versus dealers total: ' \
#.........这里部分代码省略.........
开发者ID:bangoluf,项目名称:lufsen,代码行数:103,代码来源:Main2.py


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