Game Development Reference
In-Depth Information
The WelcomePlayer method is now updated to ask the players if they would like to load their save
game in Listing 24-10.
Listing 24-10. Updating Game::WelcomePlayer
void Game::WelcomePlayer(const bool loaded)
{
if (!loaded)
{
cout << "Welcome to Text Adventure!" << endl << endl;
cout << "What is your name?" << endl << endl;
string name;
cin >> name;
m_player.SetName(name);
cout << endl << "Hello " << m_player.GetName() << endl;
}
else
{
cout << endl << "Welcome Back " << m_player.GetName() << endl << endl;
}
}
WelcomePlayer now greets players with a Welcome Back message once the game has loaded and
reinstated the name they entered when they first played the game.
The next change to the Game class code is to pass a unique ID into the constructor of each object we
would like to be a Serializable . The Game constructor is one place where this happens, as shown in
Listing 24-11.
Listing 24-11. The Game Class Constructor
Game::Game()
: m_attackDragonOption{
CreateOption(
PlayerOptions::AttackEnemy,
SDBMCalculator<18>::CalculateValue("AttackDragonOption")) }
, m_attackOrcOption{
CreateOption(
PlayerOptions::AttackEnemy,
SDBMCalculator<15>::CalculateValue("AttackOrcOption")) }
, m_moveNorthOption{
CreateOption(
PlayerOptions::GoNorth,
SDBMCalculator<15>::CalculateValue("MoveNorthOption")) }
, m_moveEastOption{
CreateOption(
PlayerOptions::GoEast,
SDBMCalculator<14>::CalculateValue("MoveEastOption")) }
 
Search WWH ::




Custom Search