Class RoomManager
java.lang.Object
game.RoomManager
Singleton class that manages room creation, transitions, and difficulty scaling.
Handles which room the player is in, spawning enemies, and tracking cleared rooms.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intInterval at which boss rooms appearprivate RoomCurrently active roomprivate doubleDifficulty scaling factor for enemy spawningprivate static RoomManagerSingleton instanceprivate PlayerThe player instanceprivate intNumber of rooms the player has clearedprivate static final intInterval at which store rooms appearprivate static final intInterval at which treasure rooms appear -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateRoomManager(Player player) Private constructor for singleton pattern. -
Method Summary
Modifier and TypeMethodDescriptionCreates the next room based on the last digit of roomsCleared and intervals.voidcreateTopDoor(Room room) Adds a door at the top of the room.voidTransitions the player to the next room, creating a top door and resetting player position.static RoomManagerRetrieves the singleton instance for later calls, after it has been initialized.static RoomManagergetInstance(Player player) Retrieves the singleton instance of RoomManager and initializes it if necessary.getScore()Returns the player's score as a 3-digit string.voidIncreases the difficulty scaling factor for future rooms.voidRenders the current room and the player.voidResets the singleton instance (for restarting the game).voidvoidUpdates the current room and checks for door collisions.
-
Field Details
-
BOSS_INTERVAL
private static final int BOSS_INTERVALInterval at which boss rooms appear- See Also:
-
TREASURE_INTERVAL
private static final int TREASURE_INTERVALInterval at which treasure rooms appear- See Also:
-
SHOP_INTERVAL
private static final int SHOP_INTERVALInterval at which store rooms appear- See Also:
-
roomCleared
private int roomClearedNumber of rooms the player has cleared -
currentRoom
Currently active room -
difficulty
private double difficultyDifficulty scaling factor for enemy spawning -
player
The player instance -
instance
Singleton instance
-
-
Constructor Details
-
RoomManager
Private constructor for singleton pattern.- Parameters:
player- the player instance to assign to rooms
-
-
Method Details
-
getInstance
Retrieves the singleton instance of RoomManager and initializes it if necessary.- Parameters:
player- the player instance- Returns:
- the RoomManager singleton instance
-
getInstance
Retrieves the singleton instance for later calls, after it has been initialized.- Returns:
- the RoomManager singleton instance
-
resetInstance
public void resetInstance()Resets the singleton instance (for restarting the game). -
createTopDoor
Adds a door at the top of the room.- Parameters:
room- the room to add the door to
-
createNextRoom
Creates the next room based on the last digit of roomsCleared and intervals. Boss, treasure, shop, and combat rooms are spawned accordingly. Last digit = 0 -> BossRoom Last digit = 5 -> TreasureRoom Last digit = 7 -> StoreRoom Anything else -> CombatRoom- Returns:
- the newly created room
-
enterNextRoom
public void enterNextRoom()Transitions the player to the next room, creating a top door and resetting player position. -
update
Updates the current room and checks for door collisions.- Parameters:
dt- delta time in secondsplayer- the player instance
-
render
Renders the current room and the player.- Parameters:
gc- the GraphicsContext for drawingplayer- the player instance
-
getCurrentRoom
- Returns:
- the currently active room
-
getPlayer
- Returns:
- the player instance
-
setPlayer
- Parameters:
player- the player instance to set
-
increaseDifficulty
public void increaseDifficulty()Increases the difficulty scaling factor for future rooms. -
getScore
Returns the player's score as a 3-digit string.- Returns:
- score formatted as 3 digits (e.g., "007")
-