Add map readings and movements based on map stuff
[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;
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         map = readmap("map1");
29         showmap(map);
30
31         mvprintw(0, 20, "%d:%d", W, H);
32         move(H/2, W/2);
33         refresh();
34
35         while ((c = getch()) != ERR) {
36                 if (c == 'q') {
37                         break;
38                 }
39                 getyx(win, y, x);
40                 x2 = x;
41                 y2 = y;
42                 switch (c) {
43                 case KEY_LEFT:
44                 case 'h':
45                         x2 = x - 1;
46                         break;
47                 case KEY_RIGHT:
48                 case 'l':
49                         x2 = x + 1;
50                         break;
51                 case KEY_UP:
52                 case 'k':
53                         y2 = y - 1;
54                         break;
55                 case KEY_DOWN:
56                 case 'j':
57                         y2 = y + 1;
58                         break;
59                 }
60                 if (y2 < 0 || y2 > H || x2 < 0 || x2 > W) {
61                         continue;
62                 }
63                 c2 = mvinch(y2, x2) & 255;
64                 mvprintw(0, 40, "<%c>  gold:%d", c2, gold);
65                 move(y, x);
66
67                 switch (c2) {
68                 case '$':
69                         gold++;
70                         mvaddch(y2, x2, ' ');
71                         /* FALL */
72                 case ' ':
73                         mvprintw(0, 0, "%d:%d", x2, y2);
74                         move(y2, x2);
75                         break;
76                 case '>':
77                         mvprintw(H/2, 10, "AUSGANG gefunden!");
78                         goto exit;
79                 }
80
81                 refresh();
82                 napms(10);
83         }
84
85 exit:
86         getch();
87         endwin();
88         return 0;
89 }
90