Question

How can I make a game to restart when I lose? My game is structured in 3 parts: mainMenu,Game and the end (when you lose). So I divided the Update and draw method in 3 parts. Now I need the option to restart the game if I lose.

bool lost=false; //when it is "true" I lost
if(lost==true)
{
    if(Keyboard.GetState().IsKeyDown(Keys.Enter))
    {
    // Restart game
    }
}
Was it helpful?

Solution

you need to make sure you set lost = false when you restart

OTHER TIPS

You'd have to show more for anyone to be able to give more specific help, so all I can say is that you need to somehow reset your game state in that event right there -- and this depends heavily on how you yourself built it. For example, a common scheme is to have an IScreen interface that all screens implement, and the Game class simply holds one of these. To switch from one to another (e.g. from a, say, "WorldScreen" to a "MainScreen"), you'd simply initialize the MainScreen and throw away the WorldScreen object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top