Room
The Room class represents a room in the game. It contains and manages all the entities in the room and the clients connected to it. It also contains the game loop that refreshes the entities and send the positions of the entities to the clients. The game loop runs in its own thread that is started when the room is created and stopped when the room is deleted.
Each room has a unique id and a boolean that indicates if the room is private or not. A private room is a room that can only be joined by the client that created it. It also has a maximum number of players that can be in it.
A room cannot be copied or moved.
Public member functions
Public member attributes
Member functions documentation
Constructor
The constructor of the Room class.
Parameters
id
: The id of the roomclient
: The client that created the roomlevels
: The levels of the gameplayallClients
: The list of all the clients connected to the serverprivateRoom
: A boolean that indicates if the room is private or not (default: false)
getState
Get the state of the room.
Return value
The State of the room. (WAIT | RUN | END | STOPPED)
getId
Get the id of the room.
Return value
An unsigned int containing the id of the room.
getNbPlayer
Get the number of players in the room.
Return value
An unsigned int containing the number of players in the room.
getProgress
Get the progress of the game.
Return value
An unsigned int containing the progress of the game.
getMaxPlayer
Get max number of players allowed in the room.
Return value
An unsigned int containing the max number of players allowed in the room.
addPlayer
Add a new player to the room.
Parameters
client
: A shared pointer of the client to add to the room
removePlayer
Remove a player from the room.
Parameters
client
: A shared pointer of the client to remove from the room
movePlayer
Move a player in the room.
Parameters
client
: A shared pointer of the client to movemove
: The direction to move the player (UP | DOWN | LEFT | RIGHT)nbr
: The number of times to move the player (default: 1)
isClientInRoom
Checks if a client is in the room.
Parameters
client
: A shared pointer of the client to check
Return value
A boolean that indicates if the client is in the room or not.
getPlayer
Get the player associated with a client.
Parameters
client
: A shared pointer of the client to get the player from
Return value
A reference to the player associated with the client.
sendToAll
Send a packet to all players in the room.
Parameters
stream
: The stream to send to all players
getMissilesIds
Get the id of the next missile to create.
Return value
A reference to the id of the next missile to create.
addMonster
Add a monster in the room.
Parameters
type
: The type of the monster to addx
: The x position of the monstery
: The y position of the monster
getNearestPlayerPos
Get the position of the nearest player from an entity.
Parameters
entity
: The entity to get the nearest player from
Return value
A pair of short containing the x and y position of the nearest player.
isPrivate
Check if the room is private.
Return value
A boolean that indicates if the room is private or not.
isMonster
Check if the it remain monsters in the room.
Return value
A boolean that indicates if the it remain monsters in the room.
getBombIds
Get the id of the next Bomb to create.
Return value
A reference to the id of the next Bomb to create.
getLaserIds
Get the id of the next Laser to create.
Return value
A reference to the id of the next Laser to create.
getRayIds
Get the id of the next Ray to create.
Return value
A reference to the id of the next Ray to create.
degInZone
Apply damage to all monsters in a zone.
Parameters
x
: The x position of the center of the zoney
: The y position of the center of the zoneradius
: The radius of the zoneplayer
: The player that apply the damage
getPlayers
Get the Players object.
Return value
A reference to the Players object.
sendChat
Send a message in the chat.
Parameters
client
: A shared pointer of the client that send the messagemessage
: The message to send
Last updated