def draw_status():
"""Draws the status bar."""
global is_draw
if current_winner is None:
message = f"{current_player.upper()}'s Turn"
elif is_draw:
message = "Game Draw!"
else:
message = f"{current_winner.upper()} Won!"
font = pg.font.Font(None, 36)
text = font.render(message, True, (255, 255, 255))
screen.fill((0, 0, 0), (0, 400, WIDTH, 100))
text_rect = text.get_rect(center=(WIDTH // 2, HEIGHT + 50))
screen.blit(text, text_rect)
pg.display.update()
def check_win():
"""Checks game grid for wins or draws."""
global grid, current_winner, is_draw
for row in range(3):
if grid[row][0] == grid[row][1] == grid[row][2] and grid[row][0]:
current_winner = grid[row][0]
pg.draw.line(screen, (250, 0, 0), (0, (row + 0.5) * HEIGHT // 3), (WIDTH, (row + 0.5) * HEIGHT // 3), 5)
break
for col in range(3):
if grid[0][col] == grid[1][col] == grid[2][col] and grid[0][col]:
current_winner = grid[0][col]
pg.draw.line(screen, (250, 0, 0), ((col + 0.5) * WIDTH // 3, 0), ((col + 0.5) * WIDTH // 3, HEIGHT), 5)
break
if grid[0][0] == grid[1][1] == grid[2][2] and grid[0][0]:
current_winner = grid[0][0]
pg.draw.line(screen, (250, 0, 0), (0, 0), (WIDTH, HEIGHT), 5)
if grid[0][2] == grid[1][1] == grid[2][0] and grid[0][2]:
current_winner = grid[0][2]
pg.draw.line(screen, (250, 0, 0), (WIDTH, 0), (0, HEIGHT), 5)
if all(cell for row in grid for cell in row) and not current_winner:
is_draw = True
draw_status()
def reset_game():
"""Restarts the game on win or draw."""
global grid, current_player, current_winner, is_draw
time.sleep(10) # Pause for 10 seconds
current_player = 'x'
current_winner = None
is_draw = False
grid = [[None] * 3 for _ in range(3)]
game_initiating_window()
ZGVmIGRyYXdfc3RhdHVzKCk6CiAgICAiIiJEcmF3cyB0aGUgc3RhdHVzIGJhci4iIiIKICAgIGdsb2JhbCBpc19kcmF3CiAgICBpZiBjdXJyZW50X3dpbm5lciBpcyBOb25lOgogICAgICAgIG1lc3NhZ2UgPSBmIntjdXJyZW50X3BsYXllci51cHBlcigpf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