本文整理汇总了Python中Deck.restore方法的典型用法代码示例。如果您正苦于以下问题:Python Deck.restore方法的具体用法?Python Deck.restore怎么用?Python Deck.restore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Deck
的用法示例。
在下文中一共展示了Deck.restore方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_06_hands
# 需要导入模块: import Deck [as 别名]
# 或者: from Deck import restore [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")
示例2: BlackjackFrame
# 需要导入模块: import Deck [as 别名]
# 或者: from Deck import restore [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()
#.........这里部分代码省略.........