forked from matijalukic/MummyMaze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.c
112 lines (100 loc) · 2.13 KB
/
menu.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
#include <stdio.h>
#include <curses.h>
#define WIDTH 75
#define HEIGHT 34
#define KEY_ENTER 10
char *choices[] = {
"New Game",
"Continue",
"Load Game",
"High Scores",
"Options",
"Help",
"About",
"Authors",
"Exit"
};
int n = sizeof(choices) / sizeof(char *);
void print_menu(WINDOW *menu_win, int highlight);
int menu() {
WINDOW *menu_win;
int highlight = 1;
int choice = 0;
int c, startx, starty, i = 0;
initscr();
resize_term(34, 75);
clear();
noecho();
cbreak();
start_color();
curs_set(0);
//startx = (80 - WIDTH) / 2;
//starty = (40 - HEIGHT) / 2;
menu_win = newwin(HEIGHT, WIDTH, 0, 0);
keypad(menu_win, TRUE);
refresh();
print_menu(menu_win, highlight);
while (1){
c = wgetch(menu_win);
switch (c){
case KEY_UP:
if (highlight == 1)
highlight = n;
else
--highlight;
break;
case KEY_DOWN:
if (highlight == n)
highlight = 1;
else
++highlight;
break;
case KEY_ENTER:
choice = highlight;
break;
default: break;
}
print_menu(menu_win, highlight);
if (choice != 0)
break;
}
clrtoeol();
endwin(menu_win);
return choice;
}
void print_menu(WINDOW *menu_win, int highlight){
int x, y, i = 0;
x = 16;
y = 4;
init_pair(2, COLOR_RED, COLOR_BLACK);
init_pair(1, COLOR_WHITE, COLOR_BLACK);
wattron(menu_win,COLOR_PAIR(1));
FILE* text = fopen("text.txt", "r"), *picture = fopen("pyramid.txt", "r");
char linija[250];
i = 0;
while (feof(text) == 0) {
fgets(linija, 250, text);
mvwprintw(menu_win, (i++) , 6, "%s", linija);
}
fclose(text);
//box(menu_win, 0, 0);
for (i = 0; i < n; ++i){
if (highlight == i + 1) {
wattron(menu_win, COLOR_PAIR(2));
mvwprintw(menu_win, x, y, "%s", choices[i]);
wattroff(menu_win, COLOR_PAIR(2));
}
else {
wattron(menu_win, COLOR_PAIR(1));
mvwprintw(menu_win, x, y, "%s", choices[i]);
wattroff(menu_win, COLOR_PAIR(1));
}
++x;
}
while (feof(picture) == 0) {
fgets(linija, 250, picture);
mvwprintw(menu_win, (i++) , 21, "%s", linija);
}
fclose(picture);
wrefresh(menu_win);
}