> For the complete documentation index, see [llms.txt](https://redboard.gitbook.io/r-type-1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://redboard.gitbook.io/r-type-1/server/game.md).

# Game

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

## Public member functions

```cpp
// 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.

```cpp
Game();
```

### createRoom

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

```cpp
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.

```cpp
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.

```cpp
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.
