In a game I made, I want to restart the game when the players presses a button.

I have an instance of a Game class, which is where most of the game happens.

I though that I could simply initialize it again, and it will be reset.

Game game = new Game(); - When the program launches. game = new Game(); - When restarting the game.

But the game uses a lot of additional classes, such as Tank and Missile. Do I have to initialize all of them too, or is initializing the Game class, which will create new Tank objects and Missile objects (with the same reference names as the previous Game instance), enough?

In general, what would be the best way to reset a game or a level in a game?


  • \$\begingroup\$ How is this different than your last question? Note that there's no general best way to do anything in game development. \$\endgroup\$ – MichaelHouse Jan 25 '14 at 21:12
  • \$\begingroup\$ If you need just slightly more information about a previous question you asked, you can post a comment on the answer's answer or you can update your question to include the additional request. \$\endgroup\$ – MichaelHouse Jan 25 '14 at 21:18

You already asked a very similar question to this, I have explained a simple ScreenManager's working process in this answer.

When you "unload" your screen, or Game class in your example, then you should remove every item, everything that is related to THAT game class. Storing the objects in Arrays, lists or vectors (depending on language) is (from my point of view) a good practice. It makes handling objects easier and more reachable.

Check my other answer (link above) to see how my simple ScreenManager is working.

| improve this answer | |
  • \$\begingroup\$ In this case, when you know the question is duplicate, it would be best to update your original answer with more information, not just post a link to your original answer as an answer. \$\endgroup\$ – MichaelHouse Jan 25 '14 at 21:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.