/** * \file main.c * * Le main permet de stocker et de lancer les fonctions permetant de lancer le jeu. */ #include "../include/display.h" #include "../include/function.h" #include "../include/read.h" #include #include #include #include #include #define SIZE_PLAY 20 #define SIZE_MENU 200 int main () { dis display_user; display_user.size_menu = SIZE_MENU; display_user.size_box = SIZE_PLAY; display_user.size_window = getMaxSize (display_user); initSDL (&display_user); vect *playerPos = (vect *)malloc (sizeof (vect)); vect *targets = {0}; int nbr_targets; score playerScore = {0}; char **tab2d = creatArea2D (SIZE_PLAY, SIZE_PLAY); score score_user = {0, 0, 0,0}; vect dim = {SIZE_PLAY, SIZE_PLAY}; int output = -1; vect dim_menu = {0, 0}; vect pos = {4, 1}; char**menu = generatorMenu("maps", &dim_menu, &pos); vect null = {0, 0}; printf("output : %d\n", output); output = inGameLoop (menu, &dim_menu, &pos, &null , 1, &display_user, &score_user, true); nullScore(&score_user); SDL_RenderClear(display_user.renderer); while(output != 0) { SDL_RenderClear(display_user.renderer); if(output == -1) { menu = generatorMenu("maps", &dim_menu, &pos); pos.x = 4; pos.y = 1; output = inGameLoop(menu, &dim_menu, &pos, &null, 1, &display_user, &score_user, true); nullScore(&score_user); } else { char txt[30] = ""; if(output <= 3) { snprintf(txt, 30, "maps/original_%d.txt", output); } else { snprintf(txt, 30, "maps/custom_%d.txt", output - 4); } if (targets != NULL) free(targets); if (tab2d != NULL) free2D(tab2d, SIZE_PLAY); tab2d = creatArea2D(SIZE_PLAY, SIZE_PLAY); targets = fileToTab2D(txt, tab2d, SIZE_PLAY, playerPos, &nbr_targets); output = inGameLoop(tab2d, &dim, playerPos, targets, nbr_targets, &display_user, &score_user, false); SDL_RenderClear(display_user.renderer); if(output != -1000) winOrLoseLoop(&display_user, output==1); output = -1; } } //screenDisplay(tab2d, SIZE_PLAY, SIZE_PLAY); SDL_DestroyWindow (display_user.window); SDL_DestroyRenderer (display_user.renderer); if (tab2d != NULL)free2D (tab2d, SIZE_PLAY); if (playerPos != NULL)free (playerPos); if (targets != NULL)free (targets); SDL_Quit (); return 0; }