views:

188

answers:

4

I made a game in Visual C#. It starts out with a welcome screen. After the game ends, it says "game over." Then I want the program to restart at the welcome screen like it was just started. How do I do that?

+1  A: 

create a method to reset all variables and call the method used to start the game/display the start screen

Euclid
+2  A: 

Is this a serious question? Since you are coding in C#, have you looked at that language's syntax for loops? Things like while or for?

If neither works out for you, check out the GOTO statement - it is awesome (I know that - I used it a lot in my first Commodore C-64 programs back in 1985)! Just ignore the community content at the bottom of the MSDN page that the link above takes you to - the first person obviously does not know what he (or she) is talking about.

cdonner
Oh you're evil. :)
Raj More
Hardy har har. -1 vote.
Phenom
+2  A: 

call Application.Restart();

Benny
@Benny: Never thought of that *slaps head*....damn that was short simple and sweet...look at my post!!!! :) Nice one!
tommieb75
Won't that cause an infinite loop?
Raj More
No, because my game has an exit button.
Phenom
lol, that's not gonna help much if you call restart upon click.
cdonner
+3  A: 
public void RunMyGame()
{
    bool isFinish = false;
    while (!isFinish)
    {
        ShowWelcome();
        InitVars();
        PlayTheGame();
        // We reach here when the game is finished
        // Play again? 'Y' isFinish set to false then loop
        isFinish = PromptToPlayAgain();
    }
}

Does this help?

Best regards, Tom.

tommieb75