# Player

The Player class represents the player in the game.

This class is derived from the ArmedEntity class and add some methods to manage the player.

## Public member functions

```cpp
// Construct a new Player object
Player(Room &room, std::shared_ptr<Client> client, u_int id, short x, short y);
// Construct a new Player object
Player(Room &room, std::shared_ptr<Client> client, u_int id, const std::pair<short, short> &pos);

// Refresh the player. This method currently only refresh the missiles of the player by calling refreshMissiles()
virtual void refresh();
// Checks if any missile of the player collide with another entity (this method override the one from IEntity)
virtual bool collide(const IEntity &other) override;
// Move the player. This method checks if the player is out of the screen and if it is, it doesn't move it.
virtual void move(short dx, short dy);
// Send the player's position to all the clients in the room
virtual void sendPos();
// Fire a missile. This method checks the time between the last missile fired and the current time and if it's less than PLAYER_FIRE_TIME, it doesn't fire a missile.
virtual void fireMissile();
// Get the last move time. This method is used by the room to not move the player too fast
const std::chrono::system_clock::time_point &lastMoveTime() const;
// Set the last move time. This method is used by the room to not move the player too fast
void setLastMoveTime(const std::chrono::system_clock::time_point &lastMoveTime);
// Get the player's score
int score() const;
// Set the player's score
void setScore(int score);
// Get the player's client
std::shared_ptr<Client> client() const;
```

## Member functions documentation

### Constructor

The constructor of the Player class.

```cpp
Player(Room &room, std::shared_ptr<Client> client, u_int id, short x, short y);
Player(Room &room, std::shared_ptr<Client> client, u_int id, const std::pair<short, short> &pos);
```

#### Parameters

* `room`: A reference to the room in which the player is.
* `client`: A shared pointer to the client of the player.
* `id`: The id of the player.
* `x`: The x position of the player.
* `y`: The y position of the player.
* `pos`: A pair of short containing the position of the player (x, y).

### refresh

This method refreshes the player. It currently only refresh the missiles of the player by calling refreshMissiles()

```cpp
virtual void refresh();
```

### collide

This method checks if any missile of the player collide with another entity (this method override the one from IEntity)

```cpp
virtual bool collide(const IEntity &other) override;
```

#### Parameters

* `other`: A reference to the other entity to check collision with.

#### Returns

A boolean which is true if the player collide with the other entity, false otherwise.

### move

This method moves the player. It checks if the player is out of the screen and if it is, it doesn't move it.

```cpp
virtual void move(short dx, short dy);
```

#### Parameters

* `dx`: The x offset to move the player.
* `dy`: The y offset to move the player.

### sendPos

This method sends the player's position to all the clients in the room.

```cpp
virtual void sendPos();
```

### fireMissile

This method fires a missile. It checks the time between the last missile fired and the current time and if it's less than PLAYER\_FIRE\_TIME, it doesn't fire a missile.

```cpp
virtual void fireMissile();
```

### lastMoveTime

This method returns the last move time of the player. It is used by the room to not move the player too fast.

```cpp
const std::chrono::system_clock::time_point &lastMoveTime() const;
```

#### Returns

A reference to the last move time of the player.

### setLastMoveTime

This method sets the last move time of the player. It is used by the room to not move the player too fast.

```cpp
void setLastMoveTime(const std::chrono::system_clock::time_point &lastMoveTime);
```

#### Parameters

* `lastMoveTime`: The last move time of the player.

### score

This method returns the score of the player.

```cpp
int score() const;
```

#### Returns

The player's score.

### setScore

This method sets the score of the player.

```cpp
void setScore(int score);
```

#### Parameters

* `score`: The player's score.

### client

This method returns the client of the player.

```cpp
std::shared_ptr<Client> client() const;
```

#### Returns

A shared pointer to the client of the player.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://redboard.gitbook.io/r-type-1/server/entities/player.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
