-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChoiceMovement.cpp
More file actions
238 lines (177 loc) · 4.32 KB
/
ChoiceMovement.cpp
File metadata and controls
238 lines (177 loc) · 4.32 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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include <iostream>
#include <string>
#include <ncurses.h>
#include "nfunctions.h"
using namespace std;
// Create a window that asks for two choices. One is to access a moving window that has a message stamped on it. The other is to just exit the program.
int main()
{
initscr(); // start ncurses mode
cbreak(); // Allows CTRL + C as a command that allows to exit programs
noecho(); // Key presses are no longer recorded to the terminal
curs_set(0); // Makes cursor invisible
keypad(stdscr,TRUE); // Allows larger variety of key presses to the standard/default ncurses window. May call this multiple times, as new windows are created.
WINDOW * menu;
WINDOW * movingWin;
WINDOW * trapdoor;
WINDOW * question;
int height, width, starty, startx;
starty = LINES - 10;
startx = 75;
width = COLS - 150;
height = 10;
refresh();
menu = create_newwin(height, width, starty, startx);
keypad(menu, TRUE);
string choices[2] = {"1. Deploy Character", "2. Exit Program"};
int choice;
int highlight = 0;
while(1)
{
for(int i = 0; i < 2; i++)
{
if(i == highlight)
wattron(menu, A_STANDOUT);
mvwprintw(menu, i + 1, 1, "%s", choices[i].c_str());
wattroff(menu, A_STANDOUT);
}
choice = wgetch(menu);
switch(choice)
{
case KEY_UP:
highlight--;
if(highlight == -1)
highlight = 0;
break;
case KEY_DOWN:
highlight++;
if(highlight == 2)
highlight = 1;
break;
default:
break;
}
if(choice == 10)
break;
}
int movement;
height = 1;
width = 2;
starty = (LINES - height)/2;
startx = (COLS - width)/2;
int y;
int x;
refresh();
if(highlight == 0)
{
int local_while1_answer;
int local_while1_highL;
wclear(menu);
destroy_win(menu);
refresh();
movingWin = create_newwin(height, width, starty, startx);
trapdoor = create_newwin(5, 10, LINES - 20, COLS - 20);
keypad(movingWin, TRUE);
while((movement = getch()) != KEY_F(1))
{
mvwprintw(trapdoor, 0, 0, "##########");
mvwprintw(trapdoor, 1, 0, "##########");
mvwprintw(trapdoor, 2, 0, "##########");
mvwprintw(trapdoor, 3, 0, "##########");
mvwprintw(trapdoor, 4, 0, "##########");
wrefresh(trapdoor);
wrefresh(movingWin);
switch(movement)
{
case KEY_UP:
destroy_win(movingWin);
movingWin = create_newwin(height, width, --starty, startx);
break;
case KEY_DOWN:
destroy_win(movingWin);
movingWin = create_newwin(height, width, ++starty, startx);
break;
case KEY_RIGHT:
destroy_win(movingWin);
movingWin = create_newwin(height, width, starty, ++startx);
break;
case KEY_LEFT:
destroy_win(movingWin);
movingWin = create_newwin(height, width, starty, --startx);
break;
default:
break;
}
if(movement == 10 && starty >= LINES - 20 && starty <= LINES - 20 + 5 && startx >= COLS - 20 && startx <= COLS - 20 + 10)
{
refresh();
question = create_newwin(10, COLS - 150, LINES - 10, 75);
keypad(question, TRUE);
string questions[2] = {"1. Go through the trapdoor.", "2. Not yet."};
int answer;
int highL = 0;
while(1)
{
for(int i = 0; i < 2; i++)
{
if(i == highL)
wattron(question, A_STANDOUT);
mvwprintw(question, i + 1, 1, "%s", questions[i].c_str());
wattroff(question, A_STANDOUT);
}
answer = wgetch(question);
switch(answer)
{
case KEY_UP:
highL--;
if(highL == -1)
highL = 0;
break;
case KEY_DOWN:
highL++;
if(highL == 2);
highL = 1;
break;
default:
break;
}
local_while1_answer = answer;
local_while1_highL = highL;
if(answer == 10 && highL == 1)
{
wclear(question);
destroy_win(question);
wrefresh(movingWin);
break;
}
else if(answer == 10 && highL == 0)
{
wclear(movingWin);
wclear(trapdoor);
wclear(question);
destroy_win(movingWin);
destroy_win(trapdoor);
destroy_win(question);
break;
}
if(local_while1_answer == 10 && local_while1_highL == 0)
break;
}
if(local_while1_answer == 10 && local_while1_highL == 0)
break;
}
}
}
if(highlight != 1)
{char message[44] = {'H','e','l','l','o',' ','S','e','v','e','r','i','a','n', ',' ,' ','w','e','l','c','o','m','e',' ','b','a','c','k',' ','t','o',' ','T','h','e',' ','C','i','t','a','d','e','l','.'};
for(int i = 0; i < 44; i++)
{
addch(message[i]);
napms(125);
refresh();
}
getch();
}
endwin(); // end ncurses mode and dellocate memory
return 0; // return 0 if program has compiled correctly
}