本文整理匯總了Python中Deck.deal方法的典型用法代碼示例。如果您正苦於以下問題:Python Deck.deal方法的具體用法?Python Deck.deal怎麽用?Python Deck.deal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Deck
的用法示例。
在下文中一共展示了Deck.deal方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_deal
# 需要導入模塊: import Deck [as 別名]
# 或者: from Deck import deal [as 別名]
def test_deal():
newdeck = Deck()
newdeck.shuffle()
first_player = []
second_player = []
third_player = []
card_per_hand = 7
for card in range(card_per_hand):
first_player.append(newdeck.deal())
second_player.append(newdeck.deal())
third_player.append(newdeck.deal())
assert len(first_player) == 7
assert len(second_player) == 7
assert len(third_player) == 7
示例2: test_06_hands
# 需要導入模塊: import Deck [as 別名]
# 或者: from Deck import deal [as 別名]
def test_06_hands(self):
d = Deck()
h = d.deal(5)
self.assertEqual(5, len(h), "hand doesn't have 5 cards")
self.assertEqual(47, len(d), "hand wasn't removed from deck")
d.restore(h)
self.assertEqual(52, len(d), "had wasn't put back in deck")
d.sort()
self.assertTrue(same_cards(d, Deck()), "restored deck incomplete")
示例3: test_empty
# 需要導入模塊: import Deck [as 別名]
# 或者: from Deck import deal [as 別名]
def test_empty():
with pytest.raises(Exception):
newdeck = Deck()
for numcards in len(xrange(53)):
newdeck.deal()
示例4: BlackjackFrame
# 需要導入模塊: import Deck [as 別名]
# 或者: from Deck import deal [as 別名]
class BlackjackFrame(Frame):
"""
Subclass of Frame, creates a blackjack game.
"""
_player_hand = []
_dealer_hand = []
_player_move = 0
_dealer_move = 0
_player_wins = 0
_dealer_wins = 0
def __init__(self, parent):
"""
Buttons and card labels initialized.
"""
Frame.__init__(self, parent)
self.configure(background = 'white')
self._cards = Deck(BlackjackCard)
self._cards.shuffle()
self.pack()
CardLabel.load_images()
self._dc1 = CardLabel(self)
self._dc1.grid(row = 0, column = 0)
self._dc2 = CardLabel(self)
self._dc2.grid(row = 0, column = 1)
self._dc3 = CardLabel(self)
self._dc3.grid(row = 0, column = 2)
self._dc4 = CardLabel(self)
self._dc4.grid(row = 0, column = 3)
self._dc5 = CardLabel(self)
self._dc5.grid(row = 0, column = 4)
self._dc6 = CardLabel(self)
self._dc6.grid(row = 0, column = 5)
self._pc1 = CardLabel(self)
self._pc1.grid(row = 1, column = 0)
self._pc2 = CardLabel(self)
self._pc2.grid(row = 1, column = 1)
self._pc3 = CardLabel(self)
self._pc3.grid(row = 1, column = 2)
self._pc4 = CardLabel(self)
self._pc4.grid(row = 1, column = 3)
self._pc5 = CardLabel(self)
self._pc5.grid(row = 1, column = 4)
self._pc6 = CardLabel(self)
self._pc6.grid(row = 1, column = 5)
self._deal = Button(self, text = 'Deal', command = self.dealcb)
self._deal.grid(row = 2, column = 0, padx = 10, pady = 10)
self._hit = Button(self, text = 'Hit', command = self.hitcb)
self._hit.grid(row = 2, column = 2, padx = 10, pady = 10)
self._stand = Button(self, text = 'Stand', command = self.standcb)
self._stand.grid(row = 2, column = 4, padx = 10, pady = 10)
self.dealcb()
def dealcb(self):
"""
Resets player and dealer hands with 2 cards each from top of deck and sets up starting layout for each hand.
"""
self._hit.configure(state = ACTIVE)
self._stand.configure(state = ACTIVE)
old = self._dealer_hand + self._player_hand
self._cards.restore(old)
self._player_hand = self._cards.deal(2)
self._dealer_hand = self._cards.deal(2)
self._player_move = 0
self._dealer_move = 0
self._dc1.display('back')
self._dc2.display('front', self._dealer_hand[1]._id)
self._dc3.display('blank')
self._dc4.display('blank')
self._dc5.display('blank')
self._dc6.display('blank')
self._pc1.display('front', self._player_hand[0]._id)
self._pc2.display('front', self._player_hand[1]._id)
self._pc3.display('blank')
self._pc4.display('blank')
self._pc5.display('blank')
self._pc6.display('blank')
Label(self, text = 'Dealer Wins: ').grid(row = 3, column = 2, padx = 10, pady = 10)
self.dcount = Label(self, text = self._dealer_wins)
self.dcount.update_idletasks()
self.dcount.grid(row = 3, column = 3, padx = 10, pady = 10)
Label(self, text = 'Player Wins: ').grid(row = 4, column = 2, padx = 10, pady = 10)
self.pcounts = Label(self, text = self._player_wins)
self.pcounts.grid(row = 4, column = 3, padx = 10, pady = 10)
self.pcounts.update_idletasks()
#.........這裏部分代碼省略.........