I'm creating a simple tic-tac-toegame with a little bit of support from this page. I want to extend reset_game() to show the end screen for a few seconds and then reset the game. I do not understand how to handle time. time.sleep works when I want to wait 2 seconds before showing end screen, but it doesn't work when I want to show end screen, and then reset game. Here's my code:
def reset_game():
global winner, draw, main_board, XO
time.sleep(2)
screen.fill((255, 255, 255))
if winner:
end_message = game_font.render(f"{winner} is the winner!", False, (0, 0, 0,))
end_message_rect = end_message.get_rect(center = (width/2, (height/2)+50))
screen.blit(end_message, end_message_rect)
elif draw:
end_message = game_font.render("Draw", False, (0, 0, 0,))
end_message_rect = end_message.get_rect(center = (width/2, (height/2)+50))
screen.blit(end_message, end_message_rect)
winner = None
draw = None
XO = "X"
main_board = [[None] * 3, [None] * 3, [None] * 3]
game_initiating_window()