Game Development Reference
In-Depth Information
, m_moveSouthOption{
CreateOption(
PlayerOptions::GoSouth,
SDBMCalculator<15>::CalculateValue("MoveSouthOption")) }
, m_moveWestOption{
CreateOption(
PlayerOptions::GoWest,
SDBMCalculator<14>::CalculateValue("MoveWestOption")) }
, m_openSwordChest{
CreateOption(
PlayerOptions::OpenChest,
SDBMCalculator<20>::CalculateValue("OpenSwordChestOption")) }
, m_quitOption{
CreateOption(
PlayerOptions::Quit,
SDBMCalculator<10>::CalculateValue("QuitOption")) }
, m_swordChest{ &m_sword, SDBMCalculator<5>::CalculateValue("Chest") }
{
static_cast<OpenChestOption*>(m_openSwordChest.get())->SetChest(&m_swordChest);
m_enemies.emplace_back(
CreateEnemy(
EnemyType::Dragon,
SDBMCalculator<6>::CalculateValue("Dragon")));
static_cast<AttackEnemyOption*>(m_attackDragonOption.get())->SetEnemy(m_enemies[0]);
m_enemies.emplace_back(
CreateEnemy(
EnemyType::Orc,
SDBMCalculator<3>::CalculateValue("Orc")));
static_cast<AttackEnemyOption*>(m_attackOrcOption.get())->SetEnemy(m_enemies[1]);
static_cast<QuitOption*>(m_quitOption.get())->AddObserver(this);
}
As you can see, each factory function now takes a hashed string that is used to construct the object
and supply a unique ID for the SerializationManager 's unordered_map . This unique key is also useful
for game objects to be able to save out their references to other objects. You can see this in
Listing 24-12, in which the source code for Player::OnSave is shown.
Listing 24-12. The Player::OnSave Method
void Player::OnSave(std::ofstream& file)
{
file << m_name;
file << std::endl;
file << m_items.size();
file << std::endl;
 
Search WWH ::




Custom Search