Room System - UQcsse3200/2024-studio-1 GitHub Wiki
Overview
The Room System is a crucial component of our game's level design, responsible for creating, managing, and populating different types of rooms within the game. It leverages a factory-based approach to instantiate and configure rooms, ensuring flexibility and reusability in room creation.
RoomFactory
Purpose: The RoomFactory
class serves as a central factory for creating different types of room entities. It simplifies the instantiation process by providing methods to create standard, Gamble, Shop, and Boss rooms with the required dependencies.
Key Responsibilities:
- Create Main Room: Initialises a
MainRoom
with the specified NPC, collectible, and terrain factories, along with room connections and specifications. - Create Boss Room: Initialises a
BossRoom
, incorporating additional features such as special terrain and unique entities. - Create Shop Room: Initialises a
ShopRoom
, , incorporating additional features such as special terrain and unique entities and instantiation of the unique child class
Dependencies:
NPCFactory
: Creates NPCs for rooms.CollectibleFactory
: Produces collectible items.TerrainFactory
: Provides terrain components.MainGameLevelFactory
: initialises a room factory to create main room instances and add it to a map of rooms and their keys and also creates a boss room instance.
BaseRoom
Purpose: The BaseRoom
class provides a foundational implementation for all room types. It manages room layout, spawns entities, and handles room connections and completion status.
Key Responsibilities:
- Initialize Specifications: Abstract method to be implemented by subclasses for setting up animal and item specifications.
- Spawn Terrain and Walls: Configures the room's terrain and surrounding walls based on the room type.
- Manage Entities: Handles spawning and removal of collectibles, and items.
- Room Completion: Tracks the completion status of the room based on the state of enemies and other criteria.
Dependencies:
NPCFactory
: Creates NPC entities.CollectibleFactory
: Provides collectible items.TerrainFactory
: Supplies terrain components.ObstacleFactory
: Used to create wall entities.
EnemyRoom
Purpose: The EnemyRoom
class provides a foundational implementation for any room type that requires a enemy Animal in the Room. It manages the item rewards for EnemyRooms, enemy spawning and enemy disposing.
Key Responsibilities:
- Initialise Specifications: Abstract method to be implemented by subclasses for setting up animal and item specifications.
- Manage Entities: Handles spawning and removal of hostile Entities
- Room Completion: Tracks the completion status of the EnemyRooms
Dependencies:
- Inherits from
BaseRoom
. - Uses
NPCFactory
,CollectibleFactory
, andTerrainFactory
for entity creation.
MainRoom
Purpose: The MainRoom
class represents a standard room in the game. It is configured with various specifications for animals and items that populate the room, and handles room initialization and item spawning.
Key Responsibilities:
- Initialize Specifications: Sets up the lists of animals and items based on predefined configurations. These specifications are used to populate the room with appropriate entities. each room will have different items and animals being spawned based on the room id.
- Create Room Entities: Utilizes the provided factories to create NPCs, items, and terrain elements within the room.
Dependencies:
- Inherits from
EnemyRoom
. - Uses
NPCFactory
,CollectibleFactory
, andTerrainFactory
for entity creation.
BossRoom
Purpose: The BossRoom
class extends BaseRoom
to create special boss rooms. These rooms feature unique animals, items, and additional functionalities, such as spawning stairs to the next level.
Key Responsibilities:
- Initialize Specifications: Configures unique animal and item specifications tailored for boss encounters.
- Spawn Stairs: Adds a staircase entity in the room, facilitating progression to the next area.
Dependencies:
- Inherits from
EnemyRoom
. - Uses
NPCFactory
,CollectibleFactory
, andTerrainFactory
. StairFactory
is used to create staircase entities.
Attributes:
minGridPoint
andmaxGridPoint
: Define the room's grid boundaries.animalSpecifications
anditemSpecifications
: Lists detailing the types of animals and items present in the room.isRoomFresh
,isBossRoom
, andisRoomCompleted
: Flags that manage room state.
ShopRoom
Purpose: The ShopRoom
class extends BaseRoom
to create special shop rooms. These rooms feature a variety of items that the player can buy with their gold by using the purchase button (P).
Key Responsibilities:
- Initialize Specifications: Configures the items in the room for selling.
- Display message: Display a message to help new users know how to buy items.
Dependencies:
- Inherits from
BaseRoom
. - Uses
CollectibleFactory
Attributes:
itemSpecifications
: Lists detailing the items that are buyable.isRoomCompleted
: Flags that manage room state.
Usage
To utilize the Room System in your game, follow these steps:
- Instantiate Factories: Create instances of
NPCFactory
,CollectibleFactory
, andTerrainFactory
. - Create Rooms: Use
RoomFactory
to createMainRoom
orBossRoom
instances as needed. - Configure Rooms: Set up room specifications, connections, and additional attributes.
- Spawn Entities: Invoke methods in
BaseRoom
and its subclasses to spawn terrain, walls, and entities within the room.
UML Diagram
The diagram below depicts how each class is related to the other in the room system.
Sequence Diagram
The following sequence diagram depicts the sequence of how each method and classes are being called:
This structured approach allows for consistent and flexible room creation and management, essential for dynamic level design and gameplay experiences.