Introduction
I am creating a small game in C++ and would like to create a function to restart the game.
First I am creating the object player
. Then I have an if statement to determine when a certain key is pressed to call the New()
method.
My goal
In that method I would like to reinstantiate an object of the Player class, so all variables will be resetted.
My code:
Player player;
//New game method
Game::New()
{
player = new Player();
}
//Game loop
Game::Loop()
{
if(keyispressed(key))
{
Game.New();
}
}
Any suggestions?