X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=map.c;fp=map.c;h=4b948ff699e6329e6ece47827f88c184bbcdf587;hb=36829587f6a6c375aa2912d955f84871a098c254;hp=0000000000000000000000000000000000000000;hpb=90f60101878cc8418bbe90b323c046660d25029b;p=dungeon1 diff --git a/map.c b/map.c new file mode 100644 index 0000000..4b948ff --- /dev/null +++ b/map.c @@ -0,0 +1,46 @@ +#include "main.h" + + +struct map * +readmap(char *fname) +{ + struct map *map; + char buf[BUFSIZ]; + FILE *fp; + int x, y; + + map = calloc(1, sizeof(struct map)); + map->name = strdup(fname); + + snprintf(buf, sizeof(buf), "%s/%s", MAPDIR, fname); + if (!(fp = fopen(buf, "r"))) { + fprintf(stderr, "error fopen() %s\n", buf); + return NULL; + } + + x = y = 0; + for (y=0; ymap[y][x] = fgetc(fp); + } + if (fgetc(fp) != '\n') { + fprintf(stderr, "error file format: no NL at y=%d x=%d\n", y, x); + return NULL; + } + } + return map; +} + +void +showmap(struct map* map) +{ + int x, y; + + mvprintw(0, 50, "map: %s", map->name); + for (y=T; ymap[y][x]); + } + } +} +