A class that represents the client.
More...
#include <Client.hpp>
|
|
typedef std::tuple< CmdID, int, std::string > | response_t |
| |
|
| | Client (int ac, char **av) |
| | Constructor for Client class.
|
| |
|
| ~Client () |
| | Destructor for Client class.
|
| |
| | Client (const Client &)=delete |
| | Deleted copy constructor.
|
| |
| Client & | operator= (const Client &)=delete |
| | Deleted assignment operator.
|
| |
| void | sendCommand (int fd, const std::vector< std::string > &command) |
| | Sends a command to the server.
|
| |
| std::pair< int, std::string > | getResponse () |
| | Receives a response from the server.
|
| |
| response_t | getJetpackResponse () |
| | Receives a response from the server.
|
| |
| void | run () |
| | Runs the client.
|
| |
|
|
static std::mutex | isRunningMutex |
| |
|
static bool | isRunning = false |
| |
|
| void | executeExit (std::vector< std::string > &command) |
| | Executes the exit command.
|
| |
| void | handleCommandId (const int &code, const std::string &message) |
| | Handles the response of the command ID.
|
| |
| void | handleCommandMap (const int &code, const std::string &message) |
| | Handles the response of the command MAP.
|
| |
| void | handleCommandPseudo (const int &code, const std::string &message) |
| | Handles the response of the command PSEUDO.
|
| |
| void | handleCommandMove (const int &code, const std::string &message) |
| | Handles the response of the command MOVE.
|
| |
| void | handleCommandClientsNb (const int &code, const std::string &message) |
| | Handles the response of the command CLIENT_NB.
|
| |
| void | handleCommandClientsStats (const int &code, const std::string &message) |
| | Handles the response of the command CLIENTS_STATS.
|
| |
| void | handleCommandClientsPositions (const int &code, const std::string &message) |
| | Handles the response of the command CLIENTS_POSITIONS.
|
| |
|
|
std::unordered_map< std::string, std::function< void(std::vector< std::string > &command)> > | _commands |
| |
|
| enum class | MusicState { NONE
, PLAYING
, PAUSED
, STOPPED
} |
| |
| enum | GameState { MAIN_MENU
, GAME
, END
} |
| |
|
| void | _checkArgs (int ac, char **av) |
| | Check the arguments passed to the client.
|
| |
|
void | _initCommands () |
| | Initializes the commands of the client.
|
| |
| void | _initGameInformation () |
| | Initializes the game information.
|
| |
| void | _initClient () |
| | Initializes the client.
|
| |
| void | _initFx () |
| | Initializes the FX for the game.
|
| |
| void | _initMusic () |
| | Initializes the music for the game.
|
| |
| void | _initElements () |
| | Initializes the elements of the game.
|
| |
| void | _initSfml () |
| | Initializes the SFML window and all game elements.
|
| |
|
void | _promptThread () |
| | Thread for handling user input.
|
| |
|
void | _communicationThread () |
| | Thread for handling communication with the server.
|
| |
|
void | _gameThread () |
| | Thread for handling the game loop.
|
| |
|
void | _updateFromResponse () |
| | Updates the game from the server responses.
|
| |
| void | _updateAnimation (float deltaTime) |
| | Updates the animation.
|
| |
| void | _updateMenu (float deltaTime) |
| | Updates the menu.
|
| |
| void | _updateGame (float deltaTime) |
| | Updates the game.
|
| |
| void | _update (float deltaTime) |
| | Updates the client.
|
| |
|
void | _drawMenu () |
| | Draws the elements of the menu.
|
| |
|
void | _drawGame () |
| | Draws the elements of the game.
|
| |
|
void | _drawEnd () |
| | Draws the elements of the end.
|
| |
|
void | _draw () |
| | Draws the elements on the screen depending on the game state.
|
| |
|
void | _analyseEvent () |
| | Analyses the events of the game.
|
| |
|
|
std::string | _ip |
| |
|
std::string | _port |
| |
|
std::unique_ptr< Socket > | _client_socket |
| |
|
struct sockaddr_in | _client |
| |
|
std::mutex | _commands_queue_mutex |
| |
|
std::queue< std::vector< std::string > > | _commands_queue |
| |
|
std::mutex | _response_queue_mutex |
| |
|
std::queue< response_t > | _response_queue |
| |
|
GameState | _gameState = MAIN_MENU |
| |
|
std::size_t | _id |
| |
|
std::vector< std::string > | _map |
| |
|
std::size_t | _nb_players = 0 |
| |
|
std::map< size_t, std::unique_ptr< Player > > | _players |
| |
|
std::string | _winner |
| |
|
sf::RenderWindow | _window |
| |
|
sf::Font | _font |
| |
|
sf::Text | _text |
| |
|
sf::Music | _menuMusic |
| |
|
MusicState | _menuMusicState = MusicState::NONE |
| |
|
sf::Music | _gameMusic |
| |
|
MusicState | _gameMusicState = MusicState::NONE |
| |
|
sf::SoundBuffer | _jetpackSoundStartBuffer |
| |
|
sf::Sound | _jetpackSoundStart |
| |
|
sf::SoundBuffer | _jetpackSoundStopBuffer |
| |
|
sf::Sound | _jetpackSoundStop |
| |
|
sf::SoundBuffer | _jetpackSoundDownBuffer |
| |
|
sf::Sound | _jetpackSoundDown |
| |
|
sf::SoundBuffer | _jetpackSoundUpBuffer |
| |
|
sf::Sound | _jetpackSoundUp |
| |
|
sf::SoundBuffer | _coinSoundBuffer |
| |
|
sf::Sound | _coinSound |
| |
|
sf::SoundBuffer | _zappedSoundBuffer |
| |
|
sf::Sound | _zappedSound |
| |
|
sf::SoundBuffer | _firedSoundBuffer |
| |
|
sf::Sound | _firedSound |
| |
|
sf::Texture | _background_texture |
| |
|
sf::Sprite | _background_sprite |
| |
|
float | _background_size |
| |
|
float | _background_pos = 0.f |
| |
|
sf::Texture | _player_texture |
| |
|
sf::Sprite | _player_sprite |
| |
|
bool | _jetpack = false |
| |
|
Player::PlayerState | _curent_state = Player::PlayerState::NORMAL |
| |
|
sf::Texture | _coin_texture |
| |
|
sf::Sprite | _coin_sprite |
| |
|
Animation | _coin_animation |
| |
|
std::unordered_map< std::array< std::size_t, 2 >, std::unique_ptr< Coin >, PositionHash > | _coins |
| |
|
std::unordered_map< std::array< std::size_t, 2 >, std::unique_ptr< Trap >, PositionHash > | _traps |
| |
|
sf::Texture | _zapper_texture |
| |
|
sf::Sprite | _zapper_sprite |
| |
|
Animation | _zapper_animation |
| |
|
sf::Texture | _laser_texture |
| |
|
sf::Sprite | _laser_sprite |
| |
|
Animation | _laser_animation |
| |
|
sf::Texture | _missile_texture |
| |
|
sf::Sprite | _missile_sprite |
| |
|
Animation | _missile_animation |
| |
|
|
static constexpr float | WINDOW_WIDTH = 1280.0f |
| |
|
static constexpr float | WINDOW_HEIGHT = 720.0f |
| |
|
static constexpr float | BACKGROUND_SPEED = 100.0f |
| |
A class that represents the client.
◆ Client() [1/2]
Constructor for Client class.
- Parameters
-
| ac | Number of command line arguments |
| av | Array of command line arguments |
◆ Client() [2/2]
Deleted copy constructor.
- Parameters
-
| other | The other Client object to copy from |
◆ _checkArgs()
| void _checkArgs |
( |
int | ac, |
|
|
char ** | av ) |
|
private |
Check the arguments passed to the client.
- Parameters
-
| ac | The number of arguments |
| av | The arguments |
- Exceptions
-
◆ _initClient()
Initializes the client.
- Exceptions
-
◆ _initElements()
Initializes the elements of the game.
- Exceptions
-
◆ _initFx()
Initializes the FX for the game.
- Exceptions
-
◆ _initGameInformation()
| void _initGameInformation |
( |
| ) |
|
|
private |
Initializes the game information.
- Exceptions
-
◆ _initMusic()
Initializes the music for the game.
- Exceptions
-
◆ _initSfml()
Initializes the SFML window and all game elements.
- Exceptions
-
◆ _update()
| void _update |
( |
float | deltaTime | ) |
|
|
private |
Updates the client.
- Parameters
-
| deltaTime | The time since the last update |
◆ _updateAnimation()
| void _updateAnimation |
( |
float | deltaTime | ) |
|
|
private |
Updates the animation.
Updates the animation of the game.
- Parameters
-
| deltaTime | The time since the last update |
| deltaTime | The time since the last frame |
◆ _updateGame()
| void _updateGame |
( |
float | deltaTime | ) |
|
|
private |
Updates the game.
- Parameters
-
| deltaTime | The time since the last update |
◆ _updateMenu()
| void _updateMenu |
( |
float | deltaTime | ) |
|
|
private |
Updates the menu.
- Parameters
-
| deltaTime | The time since the last update |
◆ closeJetpackClient()
| void closeJetpackClient |
( |
int | signal | ) |
|
|
static |
Closes the client.
- Note
- This function is a signal handler for SIGINT
- Parameters
-
| signal | The signal to close the client |
◆ executeExit()
| void executeExit |
( |
std::vector< std::string > & | command | ) |
|
|
protected |
Executes the exit command.
- Parameters
-
| command | The command to execute |
◆ getJetpackResponse()
| Client::response_t getJetpackResponse |
( |
| ) |
|
Receives a response from the server.
- Returns
- A tuple containing the command ID, the code and the message
◆ getResponse()
| std::pair< int, std::string > getResponse |
( |
| ) |
|
Receives a response from the server.
- Returns
- A pair containing the code and the message
◆ handleCommandClientsNb()
| void handleCommandClientsNb |
( |
const int & | code, |
|
|
const std::string & | message ) |
|
protected |
Handles the response of the command CLIENT_NB.
- Parameters
-
| code | The command code |
| message | The message to handle |
◆ handleCommandClientsPositions()
| void handleCommandClientsPositions |
( |
const int & | code, |
|
|
const std::string & | message ) |
|
protected |
Handles the response of the command CLIENTS_POSITIONS.
- Parameters
-
| code | The command code |
| message | The message to handle |
◆ handleCommandClientsStats()
| void handleCommandClientsStats |
( |
const int & | code, |
|
|
const std::string & | message ) |
|
protected |
Handles the response of the command CLIENTS_STATS.
- Parameters
-
| code | The command code |
| message | The message to handle |
◆ handleCommandId()
| void handleCommandId |
( |
const int & | code, |
|
|
const std::string & | message ) |
|
protected |
Handles the response of the command ID.
- Parameters
-
| code | The command code |
| message | The message to handle |
◆ handleCommandMap()
| void handleCommandMap |
( |
const int & | code, |
|
|
const std::string & | message ) |
|
protected |
Handles the response of the command MAP.
- Parameters
-
| code | The command code |
| message | The message to handle |
◆ handleCommandMove()
| void handleCommandMove |
( |
const int & | code, |
|
|
const std::string & | message ) |
|
protected |
Handles the response of the command MOVE.
- Parameters
-
| code | The command code |
| message | The message to handle |
◆ handleCommandPseudo()
| void handleCommandPseudo |
( |
const int & | code, |
|
|
const std::string & | message ) |
|
protected |
Handles the response of the command PSEUDO.
- Parameters
-
| code | The command code |
| message | The message to handle |
◆ operator=()
Deleted assignment operator.
- Parameters
-
| other | The other Client object to assign from |
- Returns
- Reference to the current object
◆ run()
Runs the client.
- Note
- This function is the main loop of the client
◆ sendCommand()
| void sendCommand |
( |
int | fd, |
|
|
const std::vector< std::string > & | command ) |
Sends a command to the server.
- Parameters
-
| fd | The file descriptor of the socket |
| command | The command to send |
The documentation for this class was generated from the following files: