Running out of money

As the rounds go on, the amount of money needed to satisfy the minimum bet will grow. This means that if the player loses enough rounds, they will be unable to continue playing.

When this happens, the GameScreen will call the on_game_over method within our GameWindow so that it can adjust the GUI elements accordingly:

def on_game_over(self):
self.hit_button.pack_forget()
self.stick_button.pack_forget()
self.new_game_button.pack(side=tk.LEFT, padx=(100, 200))
self.quit_button.pack(side=tk.LEFT)

The hit and stick buttons are replaced with a new game button as well as our familiar quit button. The new game button will call a method named new_game on our GameWindow:

def new_game(self):
self.remove_all_buttons()
self.game_screen.refresh()
self.game_screen.setup_opening_animation()

Upon starting a new game, the GameWindow will remove its buttons to prevent a double-click, then pass back over to the GameScreen to refresh its GameState instance and play the opening shuffle animation:

def refresh(self):
self.game_state = GameState()

All that's needed from the GameScreen to restart itself is a new instance of the GameState, which will be set back at around 1.

With that, the game logic is all finished. You should now have three fairly big classes containing all of the window widgets, canvas animations, and game logic. All that's left to do is make it run.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset