2d80a8120432828c25c0e0360c51888900d2776e
[dungeon1] / main.c
1 /*
2 ** dungeon1
3 **
4 ** 2021-12, markus schnalke <meillo@marmaro.de>
5 */
6
7 #include "main.h"
8
9 int
10 main(void)
11 {
12         int x, y, x2, y2;
13         WINDOW *win;
14         int c;
15         char c2;
16         struct map *map, *fow;
17         int gold=0;
18
19         win = initscr();
20         noecho();
21         cbreak();
22         keypad(stdscr, TRUE);
23 /*
24         nonl();
25         intrflush(stdscr, FALSE);
26 */
27
28         fow = getblackmap();
29         showmap(fow);
30         map = readmap("map2");
31
32         findchar(map, '>', &y, &x);
33         move(y, x);
34         see(map, y, x);
35         refresh();
36
37         while ((c = getch()) != ERR) {
38                 if (c == 'q') {
39                         break;
40                 }
41                 getyx(win, y, x);
42                 x2 = x;
43                 y2 = y;
44                 switch (c) {
45                 case KEY_LEFT:
46                 case 'h':
47                         x2 = x - 1;
48                         break;
49                 case KEY_RIGHT:
50                 case 'l':
51                         x2 = x + 1;
52                         break;
53                 case KEY_UP:
54                 case 'k':
55                         y2 = y - 1;
56                         break;
57                 case KEY_DOWN:
58                 case 'j':
59                         y2 = y + 1;
60                         break;
61                 }
62                 if (y2 < 0 || y2 > H || x2 < 0 || x2 > W) {
63                         continue;
64                 }
65
66                 c2 = map->map[y2][x2];
67                 switch (c2) {
68                 case '$':
69                         gold++;
70                         map->map[y2][x2] = ' ';
71                         mvaddch(y2, x2, ' ');
72                         /* FALL */
73                 case ' ':
74                         mvprintw(0, 0, "%d:%d", x2, y2);
75                         move(y2, x2);
76                         see(map, y2, x2);
77                         break;
78                 case '*':
79                         mvprintw(H/2, 10, "AUSGANG gefunden!");
80                         goto exit;
81                 default:
82                         continue;
83                 }
84
85                 mvprintw(0, 40, "<%c>  gold:%d", c2, gold);
86                 move(y2, x2);
87
88                 refresh();
89                 napms(10);
90         }
91
92 exit:
93         mvprintw(H, 0, "press key to exit...");
94         getch();
95         endwin();
96         return 0;
97 }
98