-
Notifications
You must be signed in to change notification settings - Fork 0
/
room.Solve.h
413 lines (359 loc) · 10.2 KB
/
room.Solve.h
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#include "room.Solve.NthDegreeEquation.h"
#include "room.Solve.SetOfEquations.h"
//-----------------------------------------------declaration------------------------------------------------------------------//
// functions for creating interface
void createInterfaceSolve(int x0, int y0, int step, int row, char* str[6][3], int firstColor);
void highlightSolve(int x0, int y0, int step, int x, int y, char* str[6][3], int secondColor);
void unhighlightSolve(int x0, int y0, int step, int x, int y, char* str[6][3], int firstColor);
void printNthDegreeEquation(int y0, int step, char* str[6][3]);
void deleteNthDegreeEquation(int y0, int step, char* str[6][3], int firstColor);
void printSetOfNEquations(int y0, int step, char* str[6][3]);
void deleteSetOfNEquations(int y0, int step, char* str[6][3], int firstColor);
// get optional degree & number of equations
int inputDegree(int* pX, int *pNum, int y0, int step, char* str[6][3], int firstColor, int secondColor);
int inputSetNum(int* pX, int* pNum, int y0, int step, char* str[6][3], int firstColor, int secondColor);
// room.Solve main
void roomSolve(int firstColor, int secondColor);
//----------------------------------------------------------------------------------------------------------------------------//
// create interface for room.Solve
void createInterfaceSolve(int x0, int y0, int step, int row, char* str[6][3], int firstColor){
// print title
textColor(firstColor);
system("cls");
goToXY(0, 0); printf("Press Esc to back");
goToXY(28, 2); printf(" __ _ __");
goToXY(28, 3); printf(" ___ ___ ___ _____ _/ /_(_)__ ___ ___ ___ / / _____ ____");
goToXY(28, 4); printf("/ -_) _ `/ // / _ `/ __/ / _ \\/ _ \\ (_-</ _ \\/ / |/ / -_) __/");
goToXY(28, 5); printf("\\__/\\_, /\\_,_/\\_,_/\\__/_/\\___/_//_/ /___/\\___/_/|___/\\__/_/");
goToXY(28, 6); printf(" /_/");
goToXY(119, 29);
// print menu
int i;
for (i = 1; i <= row; i++){
goToXY(x0, y0 + (i - 1)*step);
printf("%s", str[1][i]);
}
}
// highlight current part
void highlightSolve(int x0, int y0, int step, int x, int y, char* str[6][3], int secondColor){
// highlight
textColor(secondColor);
if (x == 1) goToXY(x0, y0 + (y - 1)*step);
else goToXY(16 + x*16, y0 + (y - 1)*step);
printf("%s", str[x][y]);
// move the cusor to the bottom right corner
goToXY(119, 29);
}
// unhighlight current part
void unhighlightSolve(int x0, int y0, int step, int x, int y, char* str[6][3], int firstColor){
// unhighlight
textColor(firstColor);
if (x == 1) goToXY(x0, y0 + (y - 1)*step);
else goToXY(16 + x*16, y0 + (y - 1)*step);
printf("%s", str[x][y]);
}
// print n-th degree equation section
void printNthDegreeEquation(int y0, int step, char* str[6][3]){
int x;
for (x = 2; x <= 5; x++){
goToXY(16 + x*16, y0);
printf("%s", str[x][1]);
}
}
// delete n-th degree equation section
void deleteNthDegreeEquation(int y0, int step, char* str[6][3], int firstColor){
textColor(0);
int x;
for (x = 2; x <= 5; x++){
goToXY(16 + x*16, y0);
printf("%s", str[x][1]);
}
textColor(firstColor);
}
// print n-th degree equation section
void printSetOfNEquations(int y0, int step, char* str[6][3]){
int x;
for (x = 2; x <= 5; x++){
goToXY(16 + x*16, y0 + step);
printf("%s", str[x][2]);
}
}
// delete n-th degree equation section
void deleteSetOfNEquations(int y0, int step, char* str[6][3], int firstColor){
textColor(0);
int x;
for (x = 2; x <= 5; x++){
goToXY(16 + x*16, y0 + step);
printf("%s", str[x][2]);
}
textColor(firstColor);
}
// get optional degree
int inputDegree(int* pX, int *pNum, int y0, int step, char* str[6][3], int firstColor, int secondColor){
// display
int x = 96, y = 12;
textColor(firstColor);
goToXY(x, y + 1); printf(" input ");
textColor(secondColor);
goToXY(x, y); printf(" ");
goToXY(x + 5, y);
// get input
char ch;
int numStr[3], count = 0, num;
do{
ch = getch();
loopWithoutGetch:
// esc
if (ch == 27) return 0;
// backspace
if ((ch == 8) && (count > 0)){
count--;
goToXY(x + 6 + count, y); printf(" ");
goToXY(x + 6 + count, y);
}
// numbers
if ((ch >= '0') && (ch <= '9') && (count <= 1)){
goToXY(x + 6 + count, y); printf("%c", ch);
count++;
numStr[count] = ch;
}
// enter
if (ch == 13){
if (count >= 1){
num = numStr[count] - '0';
if (count == 2) num += (numStr[1] - '0') * 10;
if (num <= 1){
textColor(firstColor);
goToXY(x, y + 1);
if (num <= 0) printf(" error! ");
else printf(" seriously? ");
goToXY(119, 29);
ch = getch();
goToXY(x, y + 1);
printf(" input ");
goToXY(x + 6 + count, y);
textColor(secondColor);
goto loopWithoutGetch;
}
else{
*pNum = num;
return 1;
}
}
}
// arrow keys
if (ch == -32){
ch = getch();
// arrow left
if (ch == 75){
*pNum = 0;
*pX -= 1;
textColor(firstColor);
goToXY(x, y + 1); printf(" ");
return 1;
}
}
} while (1);
}
// get optional number of equation
int inputSetNum(int* pX, int* pNum, int y0, int step, char* str[6][3], int firstColor, int secondColor){
// display
int x = 96, y = 18;
textColor(firstColor);
goToXY(x, y + 1); printf(" input ");
textColor(secondColor);
goToXY(x, y); printf(" ");
goToXY(x + 5, y);
// get input
char ch;
int numStr[3], count = 0, num;
do{
ch = getch();
loopWithoutGetch:
// esc
if (ch == 27) return 0;
// backspace
if ((ch == 8) && (count > 0)){
count--;
goToXY(x + 6 + count, y); printf(" ");
goToXY(x + 6 + count, y);
}
// numbers
if ((ch >= '0') && (ch <= '9') && (count <= 1)){
goToXY(x + 6 + count, y); printf("%c", ch);
count++;
numStr[count] = ch;
}
// enter
if (ch == 13){
if (count >= 1){
num = numStr[count] - '0';
if (count == 2) num += (numStr[1] - '0') * 10;
if (num <= 1){
textColor(firstColor);
goToXY(x, y + 1);
if (num <= 0) printf(" error! ");
else printf(" seriously? ");
goToXY(119, 29);
ch = getch();
goToXY(x, y + 1);
printf(" input ");
goToXY(x + 6 + count, y);
textColor(secondColor);
goto loopWithoutGetch;
}
else{
*pNum = num;
return 1;
}
}
}
// arrow keys
if (ch == -32){
ch = getch();
// arrow left
if (ch == 75){
*pNum = 0;
*pX -= 1;
textColor(firstColor);
goToXY(x, y + 1); printf(" ");
return 1;
}
}
} while (1);
}
// room.Solve main
void roomSolve(int firstColor, int secondColor){
// declare vars
int x0 = 15, y0 = 12, step = 6, row = 2, column = 5;
char strReal[11][50], tmp = '\0';
char* str[6][3]; // store address of those strings
// assign all the strings '\0'
int i, j;
for (i = 0; i <= column + 1; i++)
for (j = 0; j <= row + 1; j++) str[i][j] = &tmp;
// assign values to the strings
strcpy(&strReal[1][0], " N-TH DEGREE EQUATION >");
strcpy(&strReal[2][0], " 2 ");
strcpy(&strReal[3][0], " 3 ");
strcpy(&strReal[4][0], " 4 ");
strcpy(&strReal[5][0], " other ");
strcpy(&strReal[6][0], " SET OF N EQUATIONS >");
strcpy(&strReal[7][0], " 2 ");
strcpy(&strReal[8][0], " 3 ");
strcpy(&strReal[9][0], " 4 ");
strcpy(&strReal[10][0], " other ");
// store addresses
str[1][1] = &strReal[1][0];
str[2][1] = &strReal[2][0];
str[3][1] = &strReal[3][0];
str[4][1] = &strReal[4][0];
str[5][1] = &strReal[5][0];
str[1][2] = &strReal[6][0];
str[2][2] = &strReal[7][0];
str[3][2] = &strReal[8][0];
str[4][2] = &strReal[9][0];
str[5][2] = &strReal[10][0];
// create interface
createInterfaceSolve(x0, y0, step, row, str, firstColor);
// using arrow keys to control
highlightSolve(x0, y0, step, 1, 1, str, secondColor);
int num, x = 1, y = 1; // store coordinates
char ch;
do{
ch = getch();
// esc
if (ch == 27) return;
// arrow keys
if (ch == -32){
unhighlightSolve(x0, y0, step, x, y, str, firstColor);
ch = getch();
// arrow up
if (ch == 72){
y--;
if (y == 0) y = 1;
else if ((y == 1) && (x != 1)) y = 2;
}
// arrow down
if (ch == 80){
y++;
if (y == row + 1) y = row;
else if ((y == 2) && (x != 1)) y = 1;
}
// arrow left
if (ch == 75){
x--;
if (x == 0) x = 1;
else if (x == 1) switch (y){
case 1: deleteNthDegreeEquation(y0, step, str, firstColor); break;
case 2: deleteSetOfNEquations(y0, step, str, firstColor); break;
default: break;
}
}
// arrow right
if (ch == 77){
x++;
if (x == column + 1) x = column;
else if (x == 2) switch (y){
case 1: printNthDegreeEquation(y0, step, str); break;
case 2: printSetOfNEquations(y0, step, str); break;
default: break;
}
else if (x == 5){
switch (y){
case 1:
if (inputDegree(&x, &num, y0, step, str, firstColor, secondColor) == 0) return;
if (num > 0){
x = num;
goto solve;
}
break;
case 2:
if (inputSetNum(&x, &num, y0, step, str, firstColor, secondColor) == 0) return;
if (num > 0){
x = num;
goto solve;
}
break;
default: break;
}
unhighlightSolve(x0, y0, step, 5, y, str, firstColor);
}
}
highlightSolve(x0, y0, step, x, y, str, secondColor);
}
// enter
if ((ch == 13) && (x >= 2)){
solve:
// delete menu
textColor(0);
for (i = 1; i <= row; i++){
goToXY(x0, y0 + (i - 1)*step);
printf("%s", str[1][i]);
}
goToXY(96, 13);
printf(" ");
textColor(firstColor);
// n-th degree equation section
if (y == 1){
deleteNthDegreeEquation(y0, step, str, firstColor);
solveNthDegreeEquation(x, firstColor, secondColor);
}
// set of n equations section
if (y == 2){
deleteSetOfNEquations(y0, step, str, firstColor);
solveSetOfNEquations(x, firstColor, secondColor);
}
// print menu, reset
textColor(firstColor);
goToXY(0, 10);
for (i = 1; i < 120*18; i++) printf(" ");
for (i = 1; i <= row; i++){
goToXY(x0, y0 + (i - 1)*step);
printf("%s", str[1][i]);
}
highlightSolve(x0, y0, step, 1, 1, str, secondColor);
x = 1; y = 1;
}
} while (1);
}