Game

The Game class is used to manage all the different rooms in the program.

Public member functions

// Construct a new Game object
Game();
// Create a new room with a client (player)
void createRoom(Reader::Packet &packet, bool privateRoom = false);
// Search a room for the client
void searchRoom(Reader::Packet &packet);
// Get a room by its id
Room &getRoom(u_int id);
// Get a room by a client that is in it
Room &getRoom(std::shared_ptr<Client> client);

Member functions documentation

Constructor

The constructor of the Game class.

Game();

createRoom

This method creates a new room with a client (player).

void createRoom(Reader::Packet &packet, bool privateRoom = false);

Parameters

  • packet: A reference to the packet containing the information about the client that wants to create a room.

  • privateRoom: A boolean which is true if the room must be private, false otherwise. (default: false)

searchRoom

This method searches a room for the client that sent the command. If no room is found or all rooms are full, it will create a new one and add the client to it.

void searchRoom(Reader::Packet &packet);

Parameters

  • packet: A reference to the packet containing the information about the client that wants to search a room.

getRoom

This method returns a reference to a room. The room can be find by its id or by a client that is in it.

Room &getRoom(u_int id);
Room &getRoom(std::shared_ptr<Client> client);

Parameters

  • id: The id of the room to get.

  • client: A shared pointer to the client that is in the room to get.

Returns

A reference to the room that has the id or the client passed as parameter.