Game Development Reference
In-Depth Information
Listing 21-2. The EventManager Class
#include "Singleton.h"
class EventManager
: public Singleton<EventManager>
{
};
You can see here that the Singleton class is derived from by EventManager , but you also pass the
type EventManager to the Singleton template. This is a template programming pattern known as
the curiously recurring template pattern (you can get more information about this topic from
http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern ). You can now create and
delete Singleton derived classes in the manner shown in Listing 21-3.
Listing 21-3. Instantiating the EventManager
void Game::RunGame()
{
new EventManager();
InitializeRooms();
WelcomePlayer();
bool playerWon = false;
bool playerQuit = false;
while (playerQuit == false && playerWon == false)
{
GivePlayerOptions();
stringstream playerInputStream;
GetPlayerInput(playerInputStream);
PlayerOptions selectedOption = EvaluateInput(playerInputStream);
playerQuit = selectedOption == PlayerOptions::Quit;
playerWon = m_dragon.IsAlive() == false && m_orc.IsAlive() == false;
}
if (playerWon == true)
{
cout << "Congratulations, you rid the dungeon of monsters!" << endl;
cout << "Type goodbye to end" << endl;
std::string input;
cin >>input;
}
delete EventManager::GetSingletonPtr();
}
Search WWH ::




Custom Search