1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- /*
- * File: game.c
- * Author: Arthur Brandao
- *
- * Created on 28 novembre 2018
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include "file.h"
- #include "game.h"
- /* --- Extern --- */
- Game game[MAXGAME];
- int nbGame = 0;
- /* --- Fonctions publiques --- */
- JsonArray* list_map(){
- char** result;
- int nbResult;
- JsonArray* ja;
- //Initialisation json
- ja = malloc(sizeof(JsonArray));
- ini_array_encoder(ja);
- //Regarde les fichiers dans le dossier
- result = file_list(MAPDIR, &nbResult);
- for(int i = 0; i < nbResult; i++){
- add_array_string(ja, result[i]);
- free(result[i]);
- }
- free(result);
- return ja;
- }
- JsonArray* list_game(){
- JsonArray* ja;
- //Si il n' y a aucune game
- if(nbGame == 0){
- return NULL;
- }
- //Initialisation json
- ja = malloc(sizeof(JsonArray));
- ini_array_encoder(ja);
- //Ajoute chaque game
- for(int i = 0; i < nbGame; i++){
- //Creation objet json
- JsonEncoder je;
- ini_encoder(&je);
- add_string(&je, "name", game[i].name);
- add_integer(&je, "nbPlayer", game[i].nbPlayer);
- add_string(&je, "map", game[i].mapName);
- //Ajout dans le tableau
- add_array_object(ja, &je);
- //Suppr encoder objet
- clean_json_encoder(&je);
- }
- return ja;
- }
- int* map_size(char* map){
- int* res;
- res = malloc(sizeof(int) * 2);
- res[WIDTH] = 0;
- res[HEIGHT] = 1;
- //Parcours la 1er ligne pour compter le nombre de caractère
- while(*map != '\n' && *map != '\0'){
- res[WIDTH]++;
- map++;
- }
- if(*map == '\0'){
- return res;
- }
- //Compte les lignes
- map++;
- while(*map != '\0'){
- if(*map == '\n'){
- res[HEIGHT]++;
- }
- map++;
- }
- return res;
- }
- /**
- * Associe une map à une game
- * @param Game* La game à associé à la map
- * @param char* Le nom de la map
- */
- void get_map(Game*, char*);
|