f11e1ee3a9afaae638ecb3231660470b8d0a480c
[dungeon1] / main.c
1 /*
2 ** dungeon1
3 **
4 ** 2021-12, markus schnalke <meillo@marmaro.de>
5 */
6
7 #include "main.h"
8
9 static void draw(void);
10 static void wboxborder(WINDOW *);
11
12 int
13 main(void)
14 {
15         int x, y, x2, y2;
16         int c;
17         char c2;
18         struct map *map, *fow;
19         int gold=0;
20         char *title = "****   DUNGEON1   ****";
21
22         initscr();
23         noecho();
24         cbreak();
25         keypad(stdscr, TRUE);
26
27         w_title = newwin(1, COLS-1, 0, 0);
28         mvwprintw(w_title, 0, MAPW/2 - strlen(title)/2, "%s", title);
29
30         w_mapborder = newwin(MAPH+2*BORDER, MAPW+2*BORDER, 1, 0);
31         wboxborder(w_mapborder);
32         w_map = subwin(w_mapborder, MAPH, MAPW, 2, 1);
33
34         w_info = newwin(4, MAPW+2*BORDER, MAPH+2*BORDER+1, 0);
35         wboxborder(w_info);
36         w_gold = subwin(w_info, 1, 10, MAPH+2*BORDER+1+2, 50);
37         w_pos = subwin(w_info, 1, 20, MAPH+2*BORDER+1+2, 10);
38 /*
39 */
40
41
42         fow = getblackmap();
43         showmap(fow);
44         map = readmap("map1");
45
46         findchar(map, '>', &y, &x);
47         wmove(w_map, y, x);
48         see(map, y, x);
49         draw();
50
51         while ((c = getch()) != ERR) {
52                 if (c == 'q') {
53                         break;
54                 }
55                 getyx(w_map, y, x);
56                 x2 = x;
57                 y2 = y;
58                 switch (c) {
59                 case KEY_LEFT:
60                 case 'h':
61                         x2 = x - 1;
62                         break;
63                 case KEY_RIGHT:
64                 case 'l':
65                         x2 = x + 1;
66                         break;
67                 case KEY_UP:
68                 case 'k':
69                         y2 = y - 1;
70                         break;
71                 case KEY_DOWN:
72                 case 'j':
73                         y2 = y + 1;
74                         break;
75                 }
76                 if (y2 < 0 || y2 > H || x2 < 0 || x2 > W) {
77                         continue;
78                 }
79
80                 c2 = map->map[y2][x2];
81                 switch (c2) {
82                 case '$':
83                         gold++;
84                         map->map[y2][x2] = ' ';
85                         mvwaddch(w_map, y2, x2, ' ');
86                         mvwprintw(w_gold, 0, 0, "gold:%d", gold);
87                         /* FALL */
88                 case ' ':
89                         mvwprintw(w_pos, 0, 0, "pos: %d,%d", x2, y2);
90                         wmove(w_map, y2, x2);
91                         see(map, y2, x2);
92                         break;
93                 case '*':
94                         mvwprintw(w_map, H-5, 10, "AUSGANG gefunden!");
95                         goto exit;
96                 default:
97                         continue;
98                 }
99
100                 mvwprintw(w_pos, 0, 10, "<%c>", c2);
101                 wmove(w_map, y2, x2);
102
103                 draw();
104         }
105
106 exit:
107 /*
108         mvprintw(H, 0, "press key to exit...");
109         getch();
110 */
111         endwin();
112         return 0;
113 }
114
115 static void
116 draw(void)
117 {
118 /*
119 */
120         refresh();
121         wrefresh(w_info);
122         wrefresh(w_gold);
123         wrefresh(w_pos);
124         overlay(w_gold, w_info);
125         overlay(w_pos, w_info);
126         wrefresh(w_title);
127         wrefresh(w_mapborder);
128         overlay(w_map, w_mapborder);
129         wrefresh(w_map);
130 }
131
132 static void
133 wboxborder(WINDOW *win)
134 {
135         wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
136 }
137