From 551144b30d51532c343aa7585ccf0f1ba3df48ee Mon Sep 17 00:00:00 2001 From: Aubin DORIVAL Date: Sat, 28 Dec 2024 23:44:18 +0100 Subject: [PATCH] =?UTF-8?q?choix=20map=20fonctionne,=20a=20faire=20:=20sco?= =?UTF-8?q?re=20,=20affichage=20lose=20et=20win,=20custom.=20Petit=20fix?= =?UTF-8?q?=20pour=20la=20lose=201=20touch=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/function.h | 1 + script/function.c | 15 +++++++++--- script/main.c | 59 ++++++++++++++++++++++++++++++++++------------ 3 files changed, 57 insertions(+), 18 deletions(-) diff --git a/include/function.h b/include/function.h index 3cedfb9..315bf78 100644 --- a/include/function.h +++ b/include/function.h @@ -51,5 +51,6 @@ vect plusVect (vect one, vect two); int inGameLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets, int nbr_targets, dis *display_user, score *score_user, bool menu); char *timeToText(time_t time); +void nullScore(score *player_score); #endif // FONCTION_H diff --git a/script/function.c b/script/function.c index e44943f..87459d9 100644 --- a/script/function.c +++ b/script/function.c @@ -307,6 +307,8 @@ int inGameLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets, switch (input) { case SDL_SCANCODE_ESCAPE: + if(menu) return 0; + return -1; finish = true; break; case SDL_SCANCODE_D: @@ -396,10 +398,9 @@ int inGameLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets, vect size_txt = { display_user->size_menu, display_user->size_window }; char txt_empty[100] - = " " - " "; + = "Echap pour quitter "; displayTextSDL (display_user, txt_empty, coor_time, - size_txt, 100); + size_txt, 80); } } } @@ -614,3 +615,11 @@ char *timeToText (time_t time) snprintf (result, 20, "Time : %02d:%02d", min, sec); return result; } + +void nullScore(score *player_score) +{ + player_score->after = 0; + player_score->before = 0; + player_score->move_box = 0; + player_score->move_player = 0; +} diff --git a/script/main.c b/script/main.c index c339633..c8f8d7f 100644 --- a/script/main.c +++ b/script/main.c @@ -24,37 +24,66 @@ int main () initSDL (&display_user); vect *playerPos = (vect *)malloc (sizeof (vect)); - vect *targets; + vect *targets = {0}; int nbr_targets; - score playerScore; + 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); - printf("x %d, y %d\n", dim_menu.x, dim_menu.y); - - screenDisplay(menu, dim_menu.x, dim_menu.y); - - targets - = fileToTab2D ("maps/original_1.txt", tab2d, SIZE_PLAY, playerPos, &nbr_targets); - inGameLoop (menu, &dim_menu, &pos, targets, nbr_targets, + + 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); - vect dim = {SIZE_PLAY, SIZE_PLAY}; - inGameLoop (tab2d, &dim, playerPos, targets, nbr_targets, - &display_user, &score_user, false); + + + 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); + } + } + //screenDisplay(tab2d, SIZE_PLAY, SIZE_PLAY); SDL_DestroyWindow (display_user.window); SDL_DestroyRenderer (display_user.renderer); - free2D (tab2d, SIZE_PLAY); - free (playerPos); - free (targets); + if (tab2d != NULL)free2D (tab2d, SIZE_PLAY); + if (playerPos != NULL)free (playerPos); + if (targets != NULL)free (targets); SDL_Quit (); + return 0; }