Game Development Reference
In-Depth Information
South,
West,
Max
};
private:
Room* m_pJoiningRooms[JoiningDirections::Max];
public:
Room();
void AddRoom(JoiningDirections direction, Room* pRoom);
Room* GetRoom(JoiningDirections direction) const;
};
Room::Room()
{
for (unsigned int i = 0;
i < static_cast<unsigned int>(JoiningDirections::Max);
++i)
{
m_pJoiningRooms[i] = nullptr;
}
}
void Room::AddRoom(Room::JoiningDirections direction, Room* pRoom)
{
m_pJoiningRooms[static_cast<unsigned int>(direction)] = pRoom;
}
Room* Room::GetRoom(Room::JoiningDirections direction) const
{
return m_pJoiningRooms[static_cast<unsigned int>(direction)];
}
For now, a Room is a simple object. We have inherited from Entity and have created an array to store
pointers to connecting rooms. There is an enum class that is used to enumerate the four different
directions in which rooms can be connected to the current room. The value of North is set to 0 in our
enum class as we will be using these values to index into our array of Room pointers. You can see this
in action in the method Room::AddRoom where we must static_cast the value of direction to be able
to index into our array and assign the passed Room* to the correct array member. The final method
in Room is GetRoom , which will allow us to get the pointer to a room adjoining any given room for the
supplied direction.
Now that you have a room class you will be able to add some rooms to our Game class. You can see
how this is done in Listing 10-14.
Search WWH ::




Custom Search