41 lines
756 B
C
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);
|
|
}
|
|
}
|
|
}
|