Files
Sokoban/read.c
2024-12-12 13:02:55 +01:00

41 lines
756 B
C

#include <stdio.h>
#include <stdlib.h>
#include "function.h"
void fileToTab2D(const char* name_file, unsigned short int **tab, const unsigned N)
{
FILE *file = fopen(name_file, "r");
unsigned int x = 0, y = 0;
while(!feof(file))
{
char current =fgetc(file);
switch (current) {
case ' ':
tab[x][y] = EMPTY;
break;
case '#':
tab[x][y] = WALL;
break;
case '$':
tab[x][y] = BOX;
break;
case '.':
tab[x][y] = TARGET;
break;
case '@':
tab[x][y] = PLAYER;
break;
case '\n':
y = 0;
++x;
break;
}
++y;
if (x >= N || y >= N)
{
perror("Level out of range !");
exit(-1);
}
}
}