game.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * File: game.h
  3. * Author: Arthur Brandao
  4. *
  5. * Created on 28 novembre 2018
  6. */
  7. #ifndef GAME_H
  8. #define GAME_H
  9. /* --- Include --- */
  10. #include <pthread.h>
  11. #include "constante.h"
  12. #include "player.h"
  13. #include "json.h"
  14. #include "object.h"
  15. /* --- Constante --- */
  16. #define WIDTH 0
  17. #define HEIGHT 1
  18. /* --- Struct --- */
  19. typedef struct{
  20. boolean active;
  21. int index;
  22. char* name; //Nom
  23. int nbPlayer; //Nombre de joueur
  24. char* mapName; //Nom de la map
  25. char* mapContent; //La map en string
  26. int width; //Largeur de la map
  27. int height; //Hauteur de la map
  28. char** map; //Map
  29. Player* player[MAXPLAYER]; //Les joueurs actuels
  30. Object* object; //Les objets sur la map
  31. }Game;
  32. /* --- Extern --- */
  33. extern Game game[MAXGAME];
  34. extern int nbGame;
  35. extern pthread_mutex_t gameMutex[MAXGAME];
  36. extern pthread_mutex_t playerMutex[MAXGAME * MAXPLAYER];
  37. /* --- Fonctions --- */
  38. /**
  39. * Initialise les structures des parties
  40. */
  41. boolean ini_games();
  42. /**
  43. * Liste le nom de toutes les maps sous forme de JSON
  44. * @param JsonArray* Structure de reponse pour les maps existantes
  45. */
  46. void list_map(JsonArray*);
  47. /**
  48. * Liste les game en cours en JSON
  49. * @param JsonArray* Structure de reponse pour les games existantes
  50. * @return int Le nombre de game active
  51. */
  52. int list_game(JsonArray*);
  53. /**
  54. * Donne les dimension d'une carte
  55. * @param char* La carte
  56. * @return int* Tableau de resultat
  57. */
  58. int* map_size(char*);
  59. int create_game(char*, char*);
  60. int add_player(Game*, int);
  61. void describe_game(Game*, int, JsonEncoder*);
  62. boolean notify_player(Game*, char*, char*, JsonEncoder*, int);
  63. boolean player_collision(Game*, int, int);
  64. boolean player_collision_index(Game*, int, int, int*);
  65. boolean bomb_explode(Game*, int, int, int, JsonEncoder*);
  66. void bomb_chain(Game*, int, int, int, JsonArray*);
  67. int spawn_object(Game*, int, int, JsonEncoder*);
  68. void remove_player(Game*, int);
  69. void stop_game(Game*);
  70. void clean_games();
  71. #endif /* GAME_H */