Game Development Reference
In-Depth Information
Creating and deleting the SerializationManager in main ensures that it exists for the entirety of the
Game::RunGame method. The game is saved when the player chooses to quit, and Listing 24-8 shows
how this is achieved.
Listing 24-8. Saving the Game
void Game::OnQuit()
{
SerializationManager::GetSingleton().Save();
m_playerQuit = true;
}
A call to SerializationManager::Save is added to the Game::OnQuit method. The Load and
ClearSave methods are added to Game::RunGame in Listing 24-9.
Listing 24-9. The Game::RunGame Method
void Game::RunGame()
{
InitializeRooms();
const bool loaded = SerializationManager::GetSingleton().Load();
WelcomePlayer(loaded);
bool playerWon = false;
while (m_playerQuit == false && playerWon == false)
{
GivePlayerOptions();
stringstream playerInputStream;
GetPlayerInput(playerInputStream);
EvaluateInput(playerInputStream);
for (auto& enemy : m_enemies)
{
playerWon = enemy->IsAlive() == false;
}
}
if (playerWon == true)
{
SerializationManager::GetSingleton().ClearSave();
cout << "Congratulations, you rid the dungeon of monsters!" << endl;
cout << "Type goodbye to end" << endl;
std::string input;
cin >> input;
}
}
 
Search WWH ::




Custom Search