Skip to content Skip to sidebar Skip to footer

Adding A Play Again Option To Python Game

I'm working on making a game for my programming class using python. I don't know how to give the option to the player again when they lose, or quit the game. I am using python 2.7.

Solution 1:

First of, one suggestion. People will be more likely to help you if you show them what you've tried.

anyhow.

What I would do is wrap your entire game loop in a function. Like so:

def game_loop():
    while True:
    # check for the QUIT eventforeventin pygame.event.get():
        ifevent.type == QUIT:
            pygame.quit()
            sys.exit()
            ....

next when ever your game ends(I'm assuming it does have a condition that makes it end), call a game over screen function. In your game over screen function, you could first fill the window with a color, then blit any text to the screen you wan to show the user, such as "Press any key to play again". Then you would check if any key was pressed and if so call the game loop function. You also need to check if the user is trying to close the window.

Then call the game over screen function like so:

#pseudo codeif game_has_ended == True:
   game_over_screen()

Post a Comment for "Adding A Play Again Option To Python Game"