WINDOW *win;
int c;
char c2;
- struct map *map;
+ struct map *map, *fow;
int gold=0;
win = initscr();
intrflush(stdscr, FALSE);
*/
- map = readmap("map1");
- showmap(map);
+ fow = getblackmap();
+ showmap(fow);
+ map = readmap("map2");
- mvprintw(0, 20, "%d:%d", W, H);
- move(H/2, W/2);
+ findchar(map, '>', &y, &x);
+ move(y, x);
+ see(map, y, x);
refresh();
while ((c = getch()) != ERR) {
if (y2 < 0 || y2 > H || x2 < 0 || x2 > W) {
continue;
}
- c2 = mvinch(y2, x2) & 255;
- mvprintw(0, 40, "<%c> gold:%d", c2, gold);
- move(y, x);
+ c2 = map->map[y2][x2];
switch (c2) {
case '$':
gold++;
+ map->map[y2][x2] = ' ';
mvaddch(y2, x2, ' ');
/* FALL */
case ' ':
mvprintw(0, 0, "%d:%d", x2, y2);
move(y2, x2);
+ see(map, y2, x2);
break;
- case '>':
+ case '*':
mvprintw(H/2, 10, "AUSGANG gefunden!");
goto exit;
+ default:
+ continue;
}
+ mvprintw(0, 40, "<%c> gold:%d", c2, gold);
+ move(y2, x2);
+
refresh();
napms(10);
}
exit:
+ mvprintw(H, 0, "press key to exit...");
getch();
endwin();
return 0;
#include <ncurses.h>
#define MAPDIR "maps"
+#define BLANKCHAR ':'
enum {
H = 24,
W = 80,
T = 1,
+ SEEDIST = 4,
};
struct map {
};
struct map *readmap(char *);
-void showmap(struct map*);
+struct map *getblackmap(void);
+void freemap(struct map *);
+void showmap(struct map *);
+void findchar(struct map *, char, int *, int *);
+void see(struct map *, int, int);
return map;
}
+struct map *
+getblackmap(void)
+{
+ struct map *map;
+
+ map = calloc(1, sizeof(struct map));
+ map->name = strdup("(BLACK)");
+ memset(map->map, BLANKCHAR, sizeof(map->map));
+ return map;
+}
+
+void
+see(struct map *map, int ypos, int xpos)
+{
+ int y, x;
+
+ for (y=ypos-SEEDIST; y <= ypos+SEEDIST; y++) {
+ if (y<T || y>H) {
+ continue;
+ }
+ for (x=xpos-SEEDIST; x <= xpos+SEEDIST; x++) {
+ if (x<0 || x>W) {
+ continue;
+ }
+ mvaddch(y, x, map->map[y][x]);
+ }
+ }
+ move(ypos, xpos);
+}
+
+void
+freemap(struct map *map)
+{
+ if (!map) {
+ return;
+ }
+ free(map->name);
+ free(map);
+}
+
+void
+findchar(struct map *map, char c, int *yret, int *xret)
+{
+ int y, x;
+
+ for (y=0; y<H; y++) {
+ for (x=0; x<W; x++) {
+ if (map->map[y][x] == c) {
+ *yret = y;
+ *xret = x;
+ return;
+ }
+ }
+ }
+}
+
void
-showmap(struct map* map)
+showmap(struct map *map)
{
int x, y;
- mvprintw(0, 50, "map: %s", map->name);
+ mvprintw(0, 60, "map: %s", map->name);
for (y=T; y<H; y++) {
for (x=0; x<W; x++) {
mvaddch(y, x, map->map[y][x]);
################################################################################
################################################################################
########################### ############################
-##################### H F S L C ############ : O= #########
-> ##### #### * ############ >
-########## ####### $ ######## () [=]#########
+##################### H F S L C ############ #########
+> ##### #### * ############ *
+########## ####### $ ######## #########
########################### ######## ###################
########################### ######## ###################
-########################################### ############## ###################
-############################################# ########## ###################
-############################################# ########## #####################
-############################################# ######################
+########################################### ############## ##########
+############################################# ########## ######## ##########
+############################################# ########## ########## ##########
+############################################# ####### $ ##########
################################################################################
################################################################################
################################################################################
--- /dev/null
+################################################################################
+################################################################################
+################################################################################
+################################################################################
+################################################################################
+################################################################################
+################################################################################
+################################################################################
+################################################################################
+################################################################################
+####################|++++++ ############################
+-------------.###.++' H F S L C ############ #########
+> '+++' .--. * ############ *
+---------. .--'##| $ ######## #########
+#########'----------'#####| ######## ###################
+##########################| ######## ###################
+##########################+-----########### ############## ##########
+############################################# ########## ######## ##########
+############################################# ########## ########## ##########
+############################################# ####### $ ##########
+################################################################################
+################################################################################
+################################################################################
+################################################################################