-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.cpp
More file actions
125 lines (94 loc) · 1.74 KB
/
menu.cpp
File metadata and controls
125 lines (94 loc) · 1.74 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
#include "menu.h"
#include "ConsoleUtils.h"
#include <conio.h>
#define UP_ARROW 72
#define DWN_ARROW 80
#define ENTER 13
enum {
NEW,
LOAD,
QUIT
};
using namespace std;
Menu::Menu() {
Console::ShowConsoleCursor(false);
show();
}
Menu::~Menu() {
Console::ShowConsoleCursor(true);
Console::resetColor();
system("cls");
system("color");
}
void Menu::run() {
int key = 0;
while (!quit) {
key = _getch();
/* getch () function returns two keycodes for arrow keys. Arrow put to getch '\033' and '[' and letter from A to D (up, down, right, left).
Check if the first value is escape and skip */
if (key == 224)
key = _getch();
switch (key) {
case UP_ARROW:
selIndex--;
if (selIndex == -1)
selIndex = 2;
show();
break;
case DWN_ARROW:
selIndex++;
if (selIndex == 3)
selIndex = 0;
show();
break;
case ENTER:
selOption();
show();
break;
default:
break;
}
}
}
void Menu::show() {
Console::resetColor();
system("cls");
switch (selIndex) {
case 0:
Console::setColor(HIGHLIGHT_TXT);
cout << "New game\n";
Console::resetColor();
cout << "Load game\n";
cout << "Quit\n";
break;
case 1:
cout << "New game" << endl;
Console::setColor(HIGHLIGHT_TXT);
cout << "Load game" << endl;
Console::resetColor();
cout << "Quit" << endl;
break;
case 2:
cout << "New game" << endl;
cout << "Load game" << endl;
Console::setColor(HIGHLIGHT_TXT);
cout << "Quit" << endl;
break;
default:
break;
}
}
void Menu::selOption() {
switch (selIndex) {
case NEW:
cout << "New game selected" << endl;
break;
case LOAD:
cout << "Load game selected" << endl;
break;
default: // QUIT
// Console::resetColor();
quit = true;
break;
}
}