meilleur format

This commit is contained in:
2024-12-14 15:22:51 +01:00
parent 54e7f38ff2
commit af546b8440
7 changed files with 362 additions and 447 deletions

75
read.c
View File

@@ -2,52 +2,51 @@
#include <stdio.h>
#include <stdlib.h>
vect *
fileToTab2D (const char *name_file, unsigned short int **tab, const unsigned N,
vect *player, int *nbr_targets)
vect *fileToTab2D (const char *name_file, unsigned short int **tab,
const unsigned N, vect *player, int *nbr_targets)
{
vect *targets = malloc (sizeof (vect));
(*nbr_targets) = 0;
FILE *file = fopen (name_file, "r");
unsigned int x = 0, y = 1;
while (!feof (file))
{
char current = fgetc (file);
switch (current)
{
char current = fgetc (file);
switch (current)
{
case '#':
tab[x][y] = WALL;
break;
case 'C':
tab[x][y] = BOX;
break;
case 'I':
targets = realloc (targets, sizeof (vect) * (++nbr_targets[0]));
targets[nbr_targets[0] - 1].x = x;
targets[nbr_targets[0] - 1].y = y;
tab[x][y] = TARGET;
break;
case 'P':
player->x = x;
player->y = y;
tab[x][y] = PLAYER;
break;
case '\n':
y = 0;
++x;
break;
default:
tab[x][y] = EMPTY;
break;
}
++y;
if (x >= N || y >= N)
{
perror ("Level out of range !");
exit (-1);
}
case '#':
tab[x][y] = WALL;
break;
case 'C':
tab[x][y] = BOX;
break;
case 'I':
targets = realloc (targets, sizeof (vect) * (++nbr_targets[0]));
targets[nbr_targets[0] - 1].x = x;
targets[nbr_targets[0] - 1].y = y;
tab[x][y] = TARGET;
break;
case 'P':
player->x = x;
player->y = y;
tab[x][y] = PLAYER;
break;
case '\n':
y = 0;
++x;
break;
default:
tab[x][y] = EMPTY;
break;
}
++y;
if (x >= N || y >= N)
{
perror ("Level out of range !");
exit (-1);
}
}
fclose (file);
return targets;
}