Code:
#include <stdio.h>
#define MAX_SIZE 20
enum map_tile {
F, /* Forest */
G, /* Girl */
W, /* Water */
R, /* Road */
B /* Beach */
};
struct level {
const enum map_tile map[MAX_SIZE][MAX_SIZE];
};
struct player {
int x, y; /* position in level */
};
static const struct level LEVEL[] = {
/* LEVEL 1 */
{
{{ F, F, F, G, F, B, B, B, W },
{ F, R, R, F, R, B, B, B, W },
{ F, R, R, R, R, F, F, B, W },
{ F, R, F, F, B, B, B, B, W }}
}
/* LEVEL 2 etc ... */
};
int main(void)
{
struct player player1 = {0}; /* start at top-left 0,0 */
unsigned char move;
/* aquire key input into move */
switch (move) {
case NORTH:
/* bounds checking omitted */
++player1.y;
break;
case SOUTH:
/* bounds checking omitted */
--player1.y;
break;
case EAST:
/* bounds checking omitted */
++player1.x;
break;
case WEST:
/* bounds checking omitted */
--player1.x;
break;
default:
/* invalid input */
}
/* now you use the coordinates of player (x, y) in the LEVEL[0].map to find out where he is in the level */
return 0;
}