• Advertisement
Sign in to follow this  

VB 2005 - Restart Program

This topic is 3843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a game, and I'd like to have a button that restarts the game if the player dies. What is the command syntax?

Share this post


Link to post
Share on other sites
Advertisement
Well, you could probably do something like:

System.Diagnostics.Process.Start(Application.ExeName)
Application.Exit()

The code should start a new instance of your program, and then exit the current one. Have not tried it, so I don´t know if it works. However, you should generaly not restart the whole program instance, but just reset the game logic inside your game so that the player can play again if he wants.

//chinc

Share this post


Link to post
Share on other sites
At the start of the game, I enter data into Arrays and set initial values for some variables.

So, I would have them as normal, and copy them into a "re-start game" sub that would get accessed when the player restarted the game?

Share this post


Link to post
Share on other sites
Quote:
Original post by Dan Verssen
At the start of the game, I enter data into Arrays and set initial values for some variables.

So, I would have them as normal, and copy them into a "re-start game" sub that would get accessed when the player restarted the game?


What you want is to manage game states.

At the beginning of the game, you are in a state "menu"; the user then press for a key (or select a menu option) and you go in state "game". When the player dies, you go in state "game over", which either wait for a keypress or lasts a few seconds and then goes to state "menu".

States are quite easy to implement in C# (that's a simple object). If you need any kind of help, do not hesitate to continue this thread with other questions.

Share this post


Link to post
Share on other sites
I've looked around for "states" in VB2005. I don't see any references to them. Maybe VB2005 calls them something different?

Share this post


Link to post
Share on other sites
That explains why I couldn't find them. :)

Can you give a snip of code that shows how to go in and out of different states?

Share this post


Link to post
Share on other sites
They're not something you necessarily have to "go in and out of" explicitly - more just a way of splitting up your program.

That said, I think they're not relevant to this particular problem - they're a good plan for other reasons, but all you really need to do here is change these arrays from being set up at "program start" into being set up at "game start." That way, the code is only in one place, but you can go through the "game start" code as many times as you want.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement