read file
This commit is contained in:
40
read.c
Normal file
40
read.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user