57 typedef std::tuple<CmdID, int, std::string> response_t;
64 void sendCommand(
int fd,
const std::vector<std::string> &command);
80 static std::mutex isRunningMutex;
81 static bool isRunning;
100 enum class MusicState {
225 std::unordered_map<std::string, std::function<void(std::vector<std::string> &command)>> _commands;
231 void executeExit(std::vector<std::string> &command);
287 std::unique_ptr<Socket> _client_socket;
288 struct sockaddr_in _client;
289 std::mutex _commands_queue_mutex;
290 std::queue<std::vector<std::string>> _commands_queue;
291 std::mutex _response_queue_mutex;
292 std::queue<response_t> _response_queue;
304 GameState _gameState = MAIN_MENU;
306 std::vector<std::string> _map;
307 std::size_t _nb_players = 0;
308 std::map<size_t, std::unique_ptr<Player>> _players;
315 static constexpr float WINDOW_WIDTH = 1280.0f;
316 static constexpr float WINDOW_HEIGHT = 720.0f;
317 sf::RenderWindow _window;
318 #define NB_LINES _map.size()
319 #define RATIO (WINDOW_HEIGHT / static_cast<float>(NB_LINES))
330 sf::Music _menuMusic;
331 MusicState _menuMusicState = MusicState::NONE;
333 sf::Music _gameMusic;
334 MusicState _gameMusicState = MusicState::NONE;
339 sf::SoundBuffer _jetpackSoundStartBuffer;
340 sf::Sound _jetpackSoundStart;
342 sf::SoundBuffer _jetpackSoundStopBuffer;
343 sf::Sound _jetpackSoundStop;
345 sf::SoundBuffer _jetpackSoundDownBuffer;
346 sf::Sound _jetpackSoundDown;
348 sf::SoundBuffer _jetpackSoundUpBuffer;
349 sf::Sound _jetpackSoundUp;
351 sf::SoundBuffer _coinSoundBuffer;
352 sf::Sound _coinSound;
354 sf::SoundBuffer _zappedSoundBuffer;
355 sf::Sound _zappedSound;
357 sf::SoundBuffer _firedSoundBuffer;
358 sf::Sound _firedSound;
363 sf::Texture _background_texture;
364 sf::Sprite _background_sprite;
365 float _background_size;
366 float _background_pos = 0.f;
367 static constexpr float BACKGROUND_SPEED = 100.0f;
372 sf::Texture _player_texture;
373 sf::Sprite _player_sprite;
374 bool _jetpack =
false;
375 Player::PlayerState _curent_state = Player::PlayerState::NORMAL;
380 sf::Texture _coin_texture;
381 sf::Sprite _coin_sprite;
382 Animation _coin_animation;
383 std::unordered_map<std::array<std::size_t, 2>, std::unique_ptr<Coin>, PositionHash> _coins;
387 std::unordered_map<std::array<std::size_t, 2>, std::unique_ptr<Trap>, PositionHash> _traps;
390 sf::Texture _zapper_texture;
391 sf::Sprite _zapper_sprite;
392 Animation _zapper_animation;
395 sf::Texture _laser_texture;
396 sf::Sprite _laser_sprite;
397 Animation _laser_animation;
400 sf::Texture _missile_texture;
401 sf::Sprite _missile_sprite;
402 Animation _missile_animation;
A class that represents the client.
Definition Client.hpp:27
void _initElements()
Initializes the elements of the game.
Definition Game.cpp:95
void handleCommandId(const int &code, const std::string &message)
Handles the response of the command ID.
Definition Id.cpp:21
void _initSfml()
Initializes the SFML window and all game elements.
Definition Game.cpp:161
void handleCommandClientsNb(const int &code, const std::string &message)
Handles the response of the command CLIENT_NB.
Definition ClientsNb.cpp:21
void run()
Runs the client.
Definition Client.cpp:320
static void closeJetpackClient(int signal)
Closes the client.
Definition Client.cpp:24
Client & operator=(const Client &)=delete
Deleted assignment operator.
~Client()
Destructor for Client class.
Definition Client.cpp:258
void handleCommandMap(const int &code, const std::string &message)
Handles the response of the command MAP.
Definition Map.cpp:22
Client(int ac, char **av)
Constructor for Client class.
Definition Client.cpp:247
void _updateMenu(float deltaTime)
Updates the menu.
Definition Game.cpp:263
void _initCommands()
Initializes the commands of the client.
Definition Client.cpp:215
void _initGameInformation()
Initializes the game information.
Definition Client.cpp:192
void _analyseEvent()
Analyses the events of the game.
Definition Game.cpp:538
void _initFx()
Initializes the FX for the game.
Definition Game.cpp:20
void handleCommandMove(const int &code, const std::string &message)
Handles the response of the command MOVE.
Definition Move.cpp:22
std::pair< int, std::string > getResponse()
Receives a response from the server.
Definition Client.cpp:95
void _updateAnimation(float deltaTime)
Updates the animation.
Definition Game.cpp:230
void _updateGame(float deltaTime)
Updates the game.
Definition Game.cpp:284
void _draw()
Draws the elements on the screen depending on the game state.
Definition Game.cpp:514
void _promptThread()
Thread for handling user input.
Definition Client.cpp:266
void handleCommandClientsStats(const int &code, const std::string &message)
Handles the response of the command CLIENTS_STATS.
Definition ClientsStats.cpp:21
void _gameThread()
Thread for handling the game loop.
Definition Game.cpp:591
void _updateFromResponse()
Updates the game from the server responses.
Definition Game.cpp:195
Client(const Client &)=delete
Deleted copy constructor.
void handleCommandPseudo(const int &code, const std::string &message)
Handles the response of the command PSEUDO.
Definition Pseudo.cpp:22
response_t getJetpackResponse()
Receives a response from the server.
Definition Client.cpp:142
void _drawEnd()
Draws the elements of the end.
Definition Game.cpp:487
void _initMusic()
Initializes the music for the game.
Definition Game.cpp:71
void executeExit(std::vector< std::string > &command)
Executes the exit command.
Definition Exit.cpp:20
void _initClient()
Initializes the client.
Definition Client.cpp:225
void _drawGame()
Draws the elements of the game.
Definition Game.cpp:402
void _checkArgs(int ac, char **av)
Check the arguments passed to the client.
Definition Client.cpp:38
void _update(float deltaTime)
Updates the client.
Definition Game.cpp:361
void handleCommandClientsPositions(const int &code, const std::string &message)
Handles the response of the command CLIENTS_POSITIONS.
Definition ClientsPosition.cpp:21
void sendCommand(int fd, const std::vector< std::string > &command)
Sends a command to the server.
Definition Client.cpp:74
void _communicationThread()
Thread for handling communication with the server.
Definition Client.cpp:297
void _drawMenu()
Draws the elements of the menu.
Definition Game.cpp:385