Repository navigation
Expand file tree
/
Copy pathutilities.cpp
More file actions
314 lines (275 loc) · 16.7 KB
/
Copy pathutilities.cpp
File metadata and controls
314 lines (275 loc) · 16.7 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
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
#include <iostream>
#include <Windows.h>
#include <conio.h>
#include <vector>
#include "utilities.h"
#include <string>
using namespace std;
bool utilities::colorSwitch = false;
int utilities::BARRELS_SPAWN_TIMER = 0;
void utilities::setColor(int color) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, color);
}
void utilities::gotoxy(int x, int y) {
HANDLE hConsole;
COORD pos ={ 0, 0 };
cout.flush();
pos.X = x;
pos.Y = y;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsole, pos);
}
// Function to draw a single character at a specific location
void utilities::drawCharInLocation(int x, int y, char c) {
gotoxy(x, y); // Move the cursor to the specified position
std::cout << c; // Print the character
}
void utilities::ShowConsoleCursor(bool showFlag) {
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursorInfo;
GetConsoleCursorInfo(out, &cursorInfo);
cursorInfo.bVisible = showFlag;
SetConsoleCursorInfo(out, &cursorInfo);
}
bool utilities::isFloor(char board) {
return (board == '<' || board == '>' || board == '=');
}
bool utilities::isLadder(char board) {
return (board == 'H');
}
void utilities::showMenu() {
system("cls");
if (colorSwitch) setColor(11); // Light cyan
const char* menuText[] = {
"********************************************************************************",
"* *",
"* _____ _ _ __ *",
"* | __ \\ | | | |/ / *",
"* | | | | ___ _ __ | | __ ___ _ _ | ' / ___ _ __ __ _ *",
"* | | | | / _ \\ | '_ \\ | |/ // _ \\| | | | | < / _ \\ | '_ \\ / _` | *",
"* | |__| || (_) || | | || <| __/| |_| | | . \\| (_) || | | || (_| | *",
"* |_____/ \\___/ |_| |_||_|\\_\\\\___| \\__, | |_| \_\\\\___/ |_| |_| \\__, | *",
"* __/ | __/ | *",
"* |___/ |___/ *",
"* *",
"********************************************************************************",
"* *",
"* START A NEW GAME - (press 1) *",
"* SELECT STAGE - (press 3) *",
"* SWITCH COLOR - (press 7) *",
"* PRESENT INSTRUCTIONS AND KEYS - (press 8) *",
"* EXIT - (press 9) *",
"* *",
"********************************************************************************",
"* *",
"* @ Amit Oved @ *",
"* & Ziv Balassiano & *",
"* *",
"********************************************************************************"
};
for (int i = 0; i < 25; ++i) { // Adjusted to fill the screen height
gotoxy(0, i);
cout << menuText[i];
Sleep(80); // Pause for 80 milliseconds
}
setColor(7); // Reset to default color
}
void utilities::showStageSelectionMenu(const std::vector<std::string>& screenFiles) {
system("cls");
if (colorSwitch) setColor(13); // Light magenta
// Header
const char* headerText[] = {
"********************************************************************************",
"* SELECT A STAGE *",
"********************************************************************************"
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"********************************************************************************",
"* Select a stage number or press '8' to return to the main menu *",
"********************************************************************************"
};
for (int i = 0; i < 24; ++i) {
gotoxy(0, i);
cout << headerText[i];
Sleep(80);
}
// Display the list of stages dynamically
int line = 3; // Start listing stages from line 6
for (size_t i = 0; i < screenFiles.size(); ++i) {
gotoxy(1, line++);
cout << " " << (i + 1) << ". " << screenFiles[i];
Sleep(80);
}
setColor(7); // Reset to default color
}
void utilities::showErrorScreen(const std::string& message) {
system("cls"); // Clear screen
if (colorSwitch)setColor(12); // Red color for errors
std::cout << std::string(80, '*') << "\n"; // Top border
for (int i = 0; i < 10; ++i) {
std::cout << "*" << std::string(78, utilities::SPACE) << "*\n";
}
int padding = (78 - static_cast<int>(message.length())) / 2;
std::cout << "*" << std::string(padding, utilities::SPACE)
<< message
<< std::string(78 - padding - message.length(), utilities::SPACE)
<< "*\n";
for (int i = 0; i < 10; ++i) {
std::cout << "*" << std::string(78, utilities::SPACE) << "*\n";
}
std::cout << std::string(80, '*') << "\n"; // Bottom border
Sleep(3000); // Pause for user to read the error message
}
void utilities::presentInstructions() {
system("cls");
if (colorSwitch) setColor(14); // Yellow
const char* instructionsText[] = {
"********************************************************************************",
"* *Instructions* *",
"********************************************************************************",
"* !Welcome Hero! *",
"* *",
"* You're playing as Mario(@), Use the keyboard keys to move: *",
"* *",
"* 'A|a' - LEFT, 'D|d' - RIGHT, 'W|w' - UP, 'X|x' - DOWN, 'S|s' - STAY. *",
"* *",
"* Avoid Ghosts(x) and barrels(O) thrown from the Donkey Kong(&) *",
"* *",
"* The barrels move in the directions of the floor (<,>,=) *",
"* *",
"* Be careful, they might explode if they fall 5 feet or higher *",
"* *",
"* Use the Hammer (p) to strike the enemy by pressing 'P/p' *",
"* *",
"* Climb the Ladders(H), and rescue Princess Pauline($) *",
"* *",
"* You have 3 lives each game, collect (~) for bonus live *",
"* *",
"* Press 'ESC' to pause during the game.('8' - MainMenu,'ESC' - Resmue playing) *",
"* *",
"* Press '8' to return to the main menu *",
"********************************************************************************"
};
for (int i = 0; i < 25; ++i) { // Adjusted to fill the screen height
gotoxy(0, i);
cout << instructionsText[i];
Sleep(80); // Pause for 80 milliseconds
}
setColor(7); // Reset to default color
}
void utilities::gameOver() {
system("cls");
if (colorSwitch) setColor(12); // Light red
const char* gameOverText[] = {
"********************************************************************************",
"* *",
"* _____ ____ *",
"* / ____| / __ \\ *",
"* | | __ __ _ _ __ ___ ___ | | | |_ _____ _ __ *",
"* | | |_ |/ _` | '_ ` _ \\ / _ \\ | | | \\ \\ / / _ \\ '__| *",
"* | |__| | (_| | | | | | | __/ | |__| |\\ V / __/ | *",
"* \\_____|\\__,_|_| |_| |_|\\___| \\____/ \\_/ \\___|_| *",
"* *",
"* *",
"********************************************************************************",
"* *",
"* *",
"* Thank you for playing! *",
"* *",
"* Unfortunately, Mario could not save Princess Pauline this time. *",
"* *",
"* Better luck next time, Hero! *",
"* *",
"* *",
"********************************************************************************",
"* *",
"* Press '8' to return to the main menu *",
"* *",
"********************************************************************************"
};
for (int i = 0; i < 25; ++i) {
gotoxy(0, i);
cout << gameOverText[i];
Sleep(80); // Pause for 80 milliseconds
}
setColor(7); // Reset to default color
}
void utilities::displayRoundWinScreen(int stageNumber) {
system("cls"); // Clear the screen
if(colorSwitch) setColor(10); // Light green
// Display a border around the screen
std::cout << std::string(80, '*') << "\n"; // Top border
for (int i = 0; i < 10; ++i) {
std::cout << "*" << std::string(78, utilities::SPACE) << "*\n";
}
// Center-align the message
std::string message = "Congratulations! You completed Stage " + std::to_string(stageNumber) + "!";
int padding = (78 - static_cast<int>(message.length())) / 2;
std::cout << "*" << std::string(padding, utilities::SPACE)
<< message
<< std::string(78 - padding - message.length(), utilities::SPACE)
<< "*\n";
for (int i = 0; i < 10; ++i) {
std::cout << "*" << std::string(78, utilities::SPACE) << "*\n";
}
std::cout << std::string(80, '*') << "\n"; // Bottom border
Sleep(3000); // Pause for 3 seconds before transitioning
setColor(7); // Reset to default color
}
void utilities::displayWinnerScreen(int score) {
system("cls");
if (colorSwitch) setColor(10); //light green
const char* winnerText[] = {
"********************************************************************************",
"* *",
"* YOU ARE THE WINNER! *",
"* *",
"********************************************************************************",
"* |@@@@| |####| *",
"* |@@@@| |####| *",
"* |@@@@| |####| Thank you for playing! *",
"* \\@@@@| |####/ *",
"* \\@@@| |###/ Mario has successfully saves Princess Pauline *",
"* `@@|_____|##' *",
"* (O) You have proven yourself to be a true hero! *",
"* .-'''''-. *",
"* .' * * * `. *",
"* : * * : Score : *",
"* : ~ CONGRATS ~ : *",
"* : ~ YOU WON! ~ : *",
"* : * * : *",
"* `. * * * .' *",
"* `-.....-' *",
"* *",
"* *",
"* Press '8' to return to the main menu *",
"* *",
"********************************************************************************"
};
for (int i = 0; i < 25; ++i) {
gotoxy(0, i);
cout << winnerText[i];
Sleep(80); // Pause for 80 milliseconds
}
gotoxy(40, 14); // Move the cursor to the score position
cout << score; // Display the score
setColor(7); // Reset to default color
}