rm findplayer but add it in read, + get all targets
This commit is contained in:
24
read.c
24
read.c
@@ -2,17 +2,17 @@
|
||||
#include <stdlib.h>
|
||||
#include "function.h"
|
||||
|
||||
void fileToTab2D(const char* name_file, unsigned short int **tab, const unsigned N)
|
||||
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 = 0;
|
||||
unsigned int x = 0, y = 1;
|
||||
while(!feof(file))
|
||||
{
|
||||
char current =fgetc(file);
|
||||
switch (current) {
|
||||
case ' ':
|
||||
tab[x][y] = EMPTY;
|
||||
break;
|
||||
case '#':
|
||||
tab[x][y] = WALL;
|
||||
break;
|
||||
@@ -20,21 +20,35 @@ void fileToTab2D(const char* name_file, unsigned short int **tab, const unsigned
|
||||
tab[x][y] = BOX;
|
||||
break;
|
||||
case '.':
|
||||
targets = realloc(targets, sizeof(vect)*(++nbr_targets[0]));
|
||||
printf("nbr %d, pointeur %p\n", nbr_targets[0], targets);
|
||||
targets[nbr_targets[0] - 1].x = x;
|
||||
printf("%d : %d\n", targets[nbr_targets[0] - 1].x, nbr_targets[0] -1 );
|
||||
targets[nbr_targets[0] - 1].y = y;
|
||||
printf("%d\n", targets[nbr_targets[0] - 1].y);
|
||||
tab[x][y] = TARGET;
|
||||
break;
|
||||
case '@':
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return targets;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user