Game Development Reference
In-Depth Information
void InitializeRooms();
void WelcomePlayer();
void GivePlayerOptions() const;
void GetPlayerInput(std::stringstream& playerInput) const;
PlayerOptions EvaluateInput(std::stringstream& playerInput);
public:
Game();
void RunGame();
};
The Game class now has two AttackEnemyOption instances, an OpenChestOption , a Sword , Chest , and
two Enemy class instances. These are initialized in the constructor, shown in Listing 19-16.
Listing 19-16. The Game Constructor
Game::Game()
: m_attackDragonOption(&m_dragon, "Attack Dragon")
, m_attackOrcOption(&m_orc, "Attack Orc")
, m_moveNorthOption(Room::JoiningDirections::North, PlayerOptions::GoNorth, "Go North")
, m_moveEastOption(Room::JoiningDirections::East, PlayerOptions::GoEast, "Go East")
, m_moveSouthOption(Room::JoiningDirections::South, PlayerOptions::GoSouth, "Go South")
, m_moveWestOption(Room::JoiningDirections::West, PlayerOptions::GoWest, "Go West")
, m_openSwordChest(&m_swordChest, "Open Chest")
, m_quitOption("Quit")
, m_swordChest(&m_sword)
, m_dragon(Enemy::EnemyType::Dragon)
, m_orc(Enemy::EnemyType::Orc)
{
}
Listing 19-17 shows how these are added to the Room instances using the new AddStaticOption and
AddDynamicOption methods. This is done in the Game::InitializeRooms method.
Listing 19-17. Game::InitializeRooms
void Game::InitializeRooms()
{
// Room 0 heads North to Room 1
m_rooms[0].AddRoom(Room::JoiningDirections::North, &(m_rooms[1]));
m_rooms[0].AddStaticOption(&m_moveNorthOption);
m_rooms[0].AddStaticOption(&m_quitOption);
m_rooms[0].AddDynamicOption(&m_openSwordChest);
// Room 1 heads East to Room 2, South to Room 0 and West to Room 3
m_rooms[1].AddRoom(Room::JoiningDirections::East, &(m_rooms[2]));
m_rooms[1].AddStaticOption(&m_moveEastOption);
m_rooms[1].AddRoom(Room::JoiningDirections::South, &(m_rooms[0]));
m_rooms[1].AddStaticOption(&m_moveSouthOption);
m_rooms[1].AddRoom(Room::JoiningDirections::West, &(m_rooms[3]));
m_rooms[1].AddStaticOption(&m_moveWestOption);
m_rooms[1].AddStaticOption(&m_quitOption);
 
Search WWH ::




Custom Search