forked from matijalukic/MummyMaze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgorithms.c
177 lines (169 loc) · 3.76 KB
/
algorithms.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <stdio.h>
#include <curses.h>
#include "map.h"
#define WIDTH 30
#define HEIGHT 7
#define KEY_ESC 27
#define KEY_ENTER 10
void print_alg_options(WINDOW* alg_win, int n_alg_choices, int highlight) {
int x = 2;
int y = 5;
int i;
char* alg_choices[] = {
"Kruskal",
"Recursive Divison"
};
init_pair(2, COLOR_RED, COLOR_BLACK);
init_pair(1, COLOR_WHITE, COLOR_BLACK);
wattron(alg_win, COLOR_PAIR(1));
box(alg_win, 0, 0);
for (i = 0; i < n_alg_choices; ++i) {
if (highlight == i + 1) {
wattron(alg_win, COLOR_PAIR(2));
mvwprintw(alg_win, x, y, "%s", alg_choices[i]);
wattroff(alg_win, COLOR_PAIR(2));
}
else {
wattron(alg_win, COLOR_PAIR(1));
mvwprintw(alg_win, x, y, "%s", alg_choices[i]);
wattroff(alg_win, COLOR_PAIR(1));
}
++x;
}
wrefresh(alg_win);
}
void set_alg(MAP* map_info) {
char* alg_choices[] = {
"Kruskal",
"Recursive Division"
};
int n_alg_choices = sizeof(alg_choices) / sizeof(char*);
WINDOW* alg_win;
int highlight = 1;
int choice = 0;
int c, startx, starty;
initscr();
resize_term(30, 50);
clear();
noecho();
cbreak();
start_color();
curs_set(0);
startx = (50 - WIDTH) / 2;
starty = (30 - HEIGHT) / 2;
alg_win = newwin(HEIGHT, WIDTH, starty, startx);
keypad(alg_win, TRUE);
print_alg_options(alg_win, n_alg_choices, highlight);
while (1) {
c = wgetch(alg_win);
switch (c) {
case KEY_UP:
if (highlight == 1)
highlight = n_alg_choices;
else
--highlight;
break;
case KEY_DOWN:
if (highlight == n_alg_choices)
highlight = 1;
else
++highlight;
break;
case KEY_ENTER:
choice = highlight;
break;
default: break;
}
print_alg_options(alg_win, n_alg_choices, highlight);
if (choice != 0)
break;
}
clrtoeol();
refresh();
endwin();
switch (choice) {
case 1: map_info->alg = 1; break;
case 2: map_info->alg = 2; break;
}
}
void print_draw_options(WINDOW* draw_win, int n_draw_choices, int highlight) {
int x = 2;
int y = 5;
int i;
char* draw_choices[] = {
"Show me the algorithm",
"Just let me play"
};
init_pair(2, COLOR_RED, COLOR_BLACK);
init_pair(1, COLOR_WHITE, COLOR_BLACK);
wattron(draw_win, COLOR_PAIR(1));
box(draw_win, 0, 0);
for (i = 0; i < n_draw_choices; ++i) {
if (highlight == i + 1) {
wattron(draw_win, COLOR_PAIR(2));
mvwprintw(draw_win, x, y, "%s", draw_choices[i]);
wattroff(draw_win, COLOR_PAIR(2));
}
else {
wattron(draw_win, COLOR_PAIR(1));
mvwprintw(draw_win, x, y, "%s", draw_choices[i]);
wattroff(draw_win, COLOR_PAIR(1));
}
++x;
}
wrefresh(draw_win);
}
void set_draw(MAP* map_info) {
char* draw_choices[] = {
"Show me the algorithm",
"Just let me play"
};
int n_draw_choices = sizeof(draw_choices) / sizeof(char*);
WINDOW* draw_win;
int highlight = 1;
int choice = 0;
int c, startx, starty;
initscr();
resize_term(30, 50);
clear();
noecho();
cbreak();
start_color();
curs_set(0);
startx = (50 - WIDTH) / 2;
starty = (30 - HEIGHT) / 2;
draw_win = newwin(HEIGHT, WIDTH, starty, startx);
keypad(draw_win, TRUE);
print_draw_options(draw_win, n_draw_choices, highlight);
while (1) {
c = wgetch(draw_win);
switch (c) {
case KEY_UP:
if (highlight == 1)
highlight = n_draw_choices;
else
--highlight;
break;
case KEY_DOWN:
if (highlight == n_draw_choices)
highlight = 1;
else
++highlight;
break;
case KEY_ENTER:
choice = highlight;
break;
default: break;
}
print_draw_options(draw_win, n_draw_choices, highlight);
if (choice != 0)
break;
}
clrtoeol();
refresh();
endwin();
switch (choice) {
case 1: map_info->draw = 1; break;
case 2: map_info->draw = 0; break;
}
}