-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
138 lines (126 loc) · 3.85 KB
/
Copy pathMenu.cpp
File metadata and controls
138 lines (126 loc) · 3.85 KB
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
#include "Menu.hpp"
void Menu::writeTitle() {
//prima linea
wmove(this-> win, yMax/4, xMax/2 - 22 + 1);
titleAttributes(14, "_____ ");
titleAttributes(13, "_____ ");
titleAttributes(11, "_____ ");
titleAttributes(12, "____ ");
titleAttributes(15, "___ ");
titleAttributes(16, "____");
//seconda linea
wmove(this-> win, yMax/4 + 1, xMax/2 - 22);
titleAttributes(14, "|_ _| ");
titleAttributes(13, "| ____| ");
titleAttributes(11, "|_ _| ");
titleAttributes(12, "| _ \\ ");
titleAttributes(15,"|_ _| ");
titleAttributes(16, "/ ___|");
//terza linea
wmove(this-> win, yMax/4 + 2, xMax/2 - 22 + 2);
titleAttributes(14, "| | ");
titleAttributes(13, "| _| ");
titleAttributes(11, "| | ");
titleAttributes(12, "| |_) | ");
titleAttributes(15, "| | ");
titleAttributes(16, "\\___ \\");
//quarta linea
wmove(this-> win, yMax/4 + 3, xMax/2 - 22 + 2);
titleAttributes(14, "| | ");
titleAttributes(13, "| |___ ");
titleAttributes(11, "| | ");
titleAttributes(12, "| _ < ");
titleAttributes(15,"| | ");
titleAttributes(16, "___) |");
//quinta linea
wmove(this-> win, yMax/4 + 4, xMax/2 - 22 + 2);
titleAttributes(14, "|_| ");
titleAttributes(13, "|_____| ");
titleAttributes(11, "|_| ");
titleAttributes(12, "|_| \\_\\ ");
titleAttributes(15,"|___| ");
titleAttributes(16, "|____/");
}
void Menu::titleAttributes(int n, const char* c) {
wattron(this->win, COLOR_PAIR(n));
wprintw(this-> win, c);
wattroff(this->win,COLOR_PAIR(n));
}
void Menu::writeOptions() {
string a;
a='>';
for ( int i = 0; i < OPTIONS; i++ ) {
int l = strlen(options[i]);
wmove(this-> win, (yMax /4 + 8) +(i *2), (xMax/2) - (l/2) );
if ( i == this-> index ) {
wprintw(this-> win, a.c_str());
}
wprintw(this-> win, options[i]);
}
}
void Menu::init() {
getmaxyx(stdscr, this-> yMax, this-> xMax);
this-> index = 0;
this-> win = newwin(yMax, xMax, 0, 0);
update();
}
Menu::Menu() {
strcpy(this-> options[0], "Play");
strcpy(this-> options[1], "Leaderboard");
strcpy(this-> options[2], "Exit");
this-> win = NULL;
// nothing to see here;
}
int Menu::getInput() {
switch (getch()) {
case KEY_DOWN:
if ( index < OPTIONS -1 ) {
index++;
} else {
index = 0;
}
update();
break;
case KEY_UP:
if ( index > 0 ) {
index--;
} else {
index = OPTIONS -1;
}
update();
break;
case KEY_RIGHT:
case '\n':
return this-> index;
case 27:
return 2;
default:
break;
}
return -1;
}
void Menu::update() {
wclear(this-> win);
char c;
c = ' ';
// wborder(this-> win, int(c), int(c), int(c), int(c), int(c), int(c), int(c), int(c));
writeTitle();
writeOptions();
refresh();
wrefresh(this-> win);
}
void Menu::reload() {
if ( this-> win != NULL ) {
remove();
}
init();
}
void Menu::remove() {
if ( this-> win != NULL ) {
wclear(this-> win);
wrefresh(this-> win);
delwin(this-> win);
this-> win = NULL;
refresh();
}
}