2
votes

I have a game running in XNA. In order to create the menus and dialogs I am using windows forms. My main issue - however, is with my 'Game Over' dialog.

When you die, a message appears asking if you want to try again. When you do - it opens up another instance of xna (so you have two running).

When you select 'Try Again' I would like the first to close and to open a second one.

XNA Game1.cs

GameOver gameover = new GameOver(level, levelManager, kills);
                gameover.ShowDialog();
                this.Exit();

'GameOver' is the name of the windows form that displays the game over stats. (This takes the level that the user is on and starts the game at that level)

GameOver.cs (Windows form)

    private void button1_Click(object sender, EventArgs e)
{
    Visible = false;
    Thread thread = new Thread(() =>
    {
        Game1 game = new Game1(level);
        game.Run();
    });
    thread.Start();
    thread.Join();
}

Any help is much appreciated.

1
Why don't you start the new round in the same window? I think this would be the expected behaviour.Lucius
also, what's the problem closing the last window? add Dispose() in the end of button1_ClickNo Idea For Name
@lucius Sorry if this seems basic...but how would I do that?user1662290
Basically you would just reset the game state and jump back to the start, never actually exiting the game loop. It's hard to tell how that would work for your specific case.Lucius
Thanks for the answer @lucius it now all works:)user1662290

1 Answers

1
votes

i'll sum up the whole thing: You need to write a reset method that will reset the game window. you can do it by taking all the code in the contractor and put them in another method and call that method in the constructor and in the reset method. make sure you don't leave anything off the reset. any member or connection that need to be initialized.

you can also open a new window and close the current one, but that's not the right way of doing things