TheCOSCGameProject  1.0
Public Member Functions | List of all members
Dungeon Class Reference

Manages the generation and traversal of dungeon floors. More...

#include <dungeon.h>

Public Member Functions

 Dungeon ()
 Constructor for the Dungeon class. More...
 
 ~Dungeon ()
 Destructor for the Dungeon class. More...
 
RoomgenerateFloor (int numRooms)
 Generates a dungeon floor with a specified number of rooms. More...
 
int numRooms (Room *startRoom)
 Counts the number of rooms in the dungeon starting from a given room. More...
 
void linkRooms (Room *room1, Room *room2, int direction)
 Links two rooms together in a specified direction. More...
 
std::string getMap (Room *room)
 Get a string representation of the dungeon map centered on a specific room. More...
 

Detailed Description

Manages the generation and traversal of dungeon floors.

The Dungeon class handles the creation of a dungeon floor with a specified number of rooms, linking rooms together, and providing methods to traverse and print the contents of the dungeon.

Constructor & Destructor Documentation

◆ Dungeon()

Dungeon::Dungeon ( )

Constructor for the Dungeon class.

Initializes the Dungeon object, including the random number generator.

Initializes the random number generator with the current time to ensure different dungeon layouts each time.

◆ ~Dungeon()

Dungeon::~Dungeon ( )

Destructor for the Dungeon class.

Cleans up any dynamically allocated memory.

Cleans up dynamically allocated Room objects when the Dungeon object is destroyed.

Member Function Documentation

◆ generateFloor()

Room * Dungeon::generateFloor ( int  numRooms)

Generates a dungeon floor with a specified number of rooms.

Public method to generate a floor with a specified number of rooms.

Parameters
numRoomsThe number of rooms to generate in the floor.
Returns
A pointer to the starting room of the generated floor.
Parameters
numRoomsThe number of rooms to generate.
Returns
A pointer to a randomly selected Room object from the generated floor.

This method generates a floor by creating a starting room and linking additional rooms to it until the specified number of rooms is reached.

◆ getMap()

std::string Dungeon::getMap ( Room room)

Get a string representation of the dungeon map centered on a specific room.

Parameters
roomThe room to center the map on.
Returns
A string representing the map of the dungeon.

The map displays a 5x5 grid centered on the given room, with visited rooms marked with '*', unvisited rooms with 'X', and the current room in blue.

◆ linkRooms()

void Dungeon::linkRooms ( Room room1,
Room room2,
int  direction 
)

Links two rooms together in a specified direction.

Private method to link two rooms together in a specified direction.

Parameters
room1A pointer to the first room.
room2A pointer to the second room.
directionThe direction in which to link the rooms (0 = north, 1 = south, 2 = west, 3 = east).
room1The first room to link.
room2The second room to link.
directionThe direction from room1 to room2 (0: North, 1: South, 2: West, 3: East).

◆ numRooms()

int Dungeon::numRooms ( Room startRoom)

Counts the number of rooms in the dungeon starting from a given room.

Public method to count the number of rooms in the dungeon.

Parameters
startRoomA pointer to the room from which to start counting.
Returns
The total number of rooms in the dungeon.
Parameters
startRoomA pointer to the room where the count begins.
Returns
The number of rooms in the dungeon.

Counts the total number of rooms in the dungeon starting from the given room and traversing all connected rooms.


The documentation for this class was generated from the following files: