The Game class and main loop

We will define the game's main loop within the class __init__ method so that to begin playing, we simply need to create an instance of this class:

class Game:    def __init__(self):        playing = True        while playing:            self.deck = Deck()            self.deck.shuffle()            self.player_hand = Hand()            self.dealer_hand = Hand(dealer=True)            for i in range(2):                self.player_hand.add_card(self.deck.deal())                self.dealer_hand.add_card(self.deck.deal())            print("Your hand is:")            self.player_hand.display()            print()            print("Dealer's hand is:")            self.dealer_hand.display()

We start off our loop with a Boolean which will be used to track whether or not we are still playing the game.

If we are, we need a shuffled Deck and two Hand instances—one for the dealer and ...

Get Tkinter GUI Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.