0

So basically I've got a game that runs with 4 game states. One for the main menu and 3 for my mini-games. Within each of these mini games there are smaller states to handle various sections of the gameplay.

Now here's my question. When a player dies in the game I want to restart the game with them at the beginning. So I use one of my mini game structs to send them to .beginning However a lot of my bools and counters are messed up because they are different from what initialize would have them set to.

Is there any way I can send the player back to my .beginning and tell the code to reinialize in order to get my values back to what they should be for the start of the game?

cheers folks

Gandeh
  • 141
  • 1
  • 1
  • 5

2 Answers2

0

It depends on architecture of your game and code in overall.
If you use different classes for game states (for example, one menu class per game state), you could create a method which will set all your bools and counters to default values. Or you could even recreate that menu if it doesn't contain important data.

RaZeR RawByte
  • 238
  • 1
  • 10
  • What line of code would I need in order to create a method which set my bools and counters to default values? – Gandeh May 13 '13 at 18:41
0

You could either make a function or change the constructor

public class State
{
// Bools and stuff
// ...

public State(/* Whater goes in there */)
{
    // Other logic ...
    Initialise();
}

public void Initialise()
{
// Set the bools and stuff to what they should be when the game starts / restarts
}
}
Francis.Beauchamp
  • 1,323
  • 15
  • 28