@@ -92,6 +92,10 @@ def progress_game(key: str, player_marker: str):
92
92
game_won , winning_marker = is_winning ()
93
93
if game_won :
94
94
continue_with_next_game = display_winner_and_continue (winning_marker = winning_marker )
95
+ else :
96
+ # GAME DRAWN - GAME_PROGRESS_ARRAY is full and we do not have a winner.
97
+ if np .all ((GAME_PROGRESS_ARRAY != '' )):
98
+ continue_with_next_game = display_winner_and_continue (winning_marker = '' )
95
99
96
100
return continue_with_next_game
97
101
@@ -240,12 +244,13 @@ def display_winner_and_continue(winning_marker: str):
240
244
241
245
if winning_marker == PLAYER1_MARKER :
242
246
popup_result = sg .PopupYesNo ('The Winner is ' + PLAYER1_NAME + '.\n Do you want to play another game with the current players?' ,
243
- title = 'Board Winner!' , text_color = 'darkblue' , icon = GAME_ICON ,
244
- grab_anywhere = True , font = ('Blackadder ITC' , 20 ))
247
+ title = 'Board Winner!' , text_color = 'darkblue' , icon = GAME_ICON , grab_anywhere = True )
245
248
elif winning_marker == PLAYER2_MARKER :
246
249
popup_result = sg .PopupYesNo ('The Winner is ' + PLAYER2_NAME + '.\n Do you want to play another game with the current players?' ,
247
- title = 'Board Winner!' , text_color = 'darkblue' , icon = GAME_ICON ,
248
- grab_anywhere = True , font = ('Blackadder ITC' , 20 ))
250
+ title = 'Board Winner!' , text_color = 'darkblue' , icon = GAME_ICON , grab_anywhere = True )
251
+ else : # game drawn
252
+ popup_result = sg .PopupYesNo ('The Game is DRAWN.\n Do you want to play another game with the current players?' ,
253
+ title = 'Board Drawn!' , text_color = 'darkblue' , icon = GAME_ICON , grab_anywhere = True )
249
254
250
255
return popup_result
251
256
@@ -265,7 +270,7 @@ def init_game_window():
265
270
266
271
return sg .Window ('Tic Tac Toe Options' , init_game_layout , icon = GAME_ICON , finalize = True )
267
272
268
- def reset_game_board ():
273
+ def reset_game_board (reset_board : str ):
269
274
'''Resets the current game board and re-initializes all the
270
275
game parameters to continue playing the game with the same players.'''
271
276
@@ -277,7 +282,9 @@ def reset_game_board():
277
282
global PLAYER_SWITCH
278
283
global MAIN_DIAGONAL_IS_WINNER
279
284
280
- GAME_BOARD = initialize_game_board ()
285
+ if reset_board == 'Yes' :
286
+ GAME_BOARD = initialize_game_board ()
287
+
281
288
GAME_PROGRESS_ARRAY = [['' for i in range (COLS )] for j in range (ROWS )]
282
289
GAME_PROGRESS_ARRAY = np .array (GAME_PROGRESS_ARRAY , dtype = str )
283
290
STEP_COUNTER = 0
@@ -294,14 +301,17 @@ def start_next_session(user_choice: str):
294
301
295
302
global INIT_WINDOW
296
303
global GAME_BOARD
297
-
304
+
298
305
if user_choice == 'Yes' :
299
306
# retain the players and reset the board state.
300
307
GAME_BOARD .Close ()
301
- reset_game_board ()
308
+ GAME_BOARD = None
309
+ reset_game_board (reset_board = 'Yes' )
302
310
elif user_choice == 'No' :
303
311
# return to the game init dialog to start over with new set of players.
304
312
GAME_BOARD .Close ()
313
+ GAME_BOARD = None
314
+ reset_game_board (reset_board = 'No' )
305
315
INIT_WINDOW = init_game_window ()
306
316
307
317
def initialize_game_board ():
@@ -376,6 +386,7 @@ def initialize_game_board():
376
386
if START_GAME and EVENT != '-RESET-' :
377
387
378
388
if EVENT not in ('-START-' , 'WIN_CLOSE' , '-EXIT-' ):
389
+
379
390
CURRENT_MARKER = GAME_BOARD .Element (EVENT ).get_text ()
380
391
GAME_BOARD .Element (EVENT ).update (PLAYER1_MARKER if CURRENT_MARKER == ' ' and \
381
392
PLAYER_SWITCH is True else PLAYER2_MARKER if CURRENT_MARKER == ' ' and \
@@ -444,4 +455,5 @@ def initialize_game_board():
444
455
title = 'Game Reset' , icon = GAME_ICON , grab_anywhere = True )
445
456
if RESET_GAME == 'Yes' :
446
457
GAME_BOARD .Close ()
447
- reset_game_board ()
458
+ GAME_BOARD = None
459
+ reset_game_board (reset_board = 'Yes' )
0 commit comments