creer un fichier nouveau pour lediteur de map
This commit is contained in:
11
maps/custom_4.txt
Normal file
11
maps/custom_4.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
###################
|
||||
#P #
|
||||
# #
|
||||
# #
|
||||
# #
|
||||
# C #
|
||||
# #
|
||||
# I #
|
||||
# #
|
||||
# #
|
||||
###################
|
||||
11
maps/viergemap.txt
Normal file
11
maps/viergemap.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
###################
|
||||
#P #
|
||||
# #
|
||||
# #
|
||||
# #
|
||||
# C #
|
||||
# #
|
||||
# I #
|
||||
# #
|
||||
# #
|
||||
###################
|
||||
@@ -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,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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user