diff --git a/maps/custom_4.txt b/maps/custom_4.txt new file mode 100644 index 0000000..cd5eb58 --- /dev/null +++ b/maps/custom_4.txt @@ -0,0 +1,11 @@ +################### +#P # +# # +# # +# # +# C # +# # +# I # +# # +# # +################### \ No newline at end of file diff --git a/maps/viergemap.txt b/maps/viergemap.txt new file mode 100644 index 0000000..cd5eb58 --- /dev/null +++ b/maps/viergemap.txt @@ -0,0 +1,11 @@ +################### +#P # +# # +# # +# # +# C # +# # +# I # +# # +# # +################### \ No newline at end of file diff --git a/script/main.c b/script/main.c index 531e832..986cb6a 100644 --- a/script/main.c +++ b/script/main.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #define SIZE_PLAY 20 @@ -60,10 +61,13 @@ int main () } else if(output == -2) { + printf("editeur de map"); + //newmap output = inEditorLoop(menu, &dim_menu, &pos, &null, 1, &display_user, &score_user); } else { + printf("editeur de map : %d" ,output); score_user.before = time(NULL); char txt[30] = ""; if(output <= 3) @@ -74,15 +78,37 @@ int main () { 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); - score_user.after = time(NULL); - if(output != -1000) winOrLoseLoop(&display_user, &score_user, output==1); - output = -1; + if(access(txt, F_OK)==0) + { + 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); + score_user.after = time(NULL); + if(output != -1000) winOrLoseLoop(&display_user, &score_user, output==1); + output = -1; + } + else{ + char path[256]; + snprintf(path, sizeof(path), "maps/custom_%d.txt", output-4); + FILE *src = fopen("maps/viergemap.txt", "r"); + FILE *file = fopen(path, "w"); + + + char buffer[1024]; // Tampon pour lire le contenu + size_t bytesRead; + + // Lire le contenu du fichier source et l'écrire dans le fichier destination + while ((bytesRead = fread(buffer, 1, sizeof(buffer), src)) > 0) { + fwrite(buffer, 1, bytesRead, file); + } + + fclose(src); + fclose(file); + output = -2; + } } }