creer un fichier nouveau pour lediteur de map

This commit is contained in:
cyjullien1
2025-01-06 12:45:46 +01:00
parent ae41297a87
commit e8c179fa83
3 changed files with 57 additions and 9 deletions

11
maps/custom_4.txt Normal file
View File

@@ -0,0 +1,11 @@
###################
#P #
# #
# #
# #
# C #
# #
# I #
# #
# #
###################

11
maps/viergemap.txt Normal file
View File

@@ -0,0 +1,11 @@
###################
#P #
# #
# #
# #
# C #
# #
# I #
# #
# #
###################

View File

@@ -10,6 +10,7 @@
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_render.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#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,6 +78,8 @@ int main ()
{
snprintf(txt, 30, "maps/custom_%d.txt", output - 4);
}
if(access(txt, F_OK)==0)
{
if (targets != NULL) free(targets);
if (tab2d != NULL) free2D(tab2d, SIZE_PLAY);
tab2d = creatArea2D(SIZE_PLAY, SIZE_PLAY);
@@ -84,6 +90,26 @@ int main ()
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;
}
}
}