game.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * File: game.c
  3. * Author: Arthur Brandao
  4. *
  5. * Created on 28 novembre 2018
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include "file.h"
  10. #include "game.h"
  11. /* --- Extern --- */
  12. Game game[MAXGAME];
  13. int nbGame = 0;
  14. /* --- Fonctions publiques --- */
  15. JsonArray* list_map(){
  16. char** result;
  17. int nbResult;
  18. JsonArray* ja;
  19. //Initialisation json
  20. ja = malloc(sizeof(JsonArray));
  21. ini_array_encoder(ja);
  22. //Regarde les fichiers dans le dossier
  23. result = file_list(MAPDIR, &nbResult);
  24. for(int i = 0; i < nbResult; i++){
  25. add_array_string(ja, result[i]);
  26. free(result[i]);
  27. }
  28. return ja;
  29. }
  30. JsonArray* list_game(){
  31. JsonArray* ja;
  32. //Si il n' y a aucune game
  33. if(nbGame == 0){
  34. return NULL;
  35. }
  36. //Initialisation json
  37. ja = malloc(sizeof(JsonArray));
  38. ini_array_encoder(ja);
  39. //Ajoute chaque game
  40. for(int i = 0; i < nbGame; i++){
  41. //Creation objet json
  42. JsonEncoder je;
  43. ini_encoder(&je);
  44. add_string(&je, "name", game[i].name);
  45. add_integer(&je, "nbPlayer", game[i].nbPlayer);
  46. add_string(&je, "map", game[i].mapName);
  47. //Ajout dans le tableau
  48. add_array_object(ja, &je);
  49. //Suppr encoder objet
  50. clean_json_encoder(&je);
  51. }
  52. return ja;
  53. }
  54. /**
  55. * Associe une map à une game
  56. * @param Game* La game à associé à la map
  57. * @param char* Le nom de la map
  58. */
  59. void get_map(Game*, char*);