-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
250 lines (223 loc) · 10.1 KB
/
Copy pathGame.cpp
File metadata and controls
250 lines (223 loc) · 10.1 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
#include "Game.h"
Game::Game()
{
}
Game::~Game()
{
}
//Rychlejsi vykreslovani do konzole
static void ClearScreen()
{
HANDLE hStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };
hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (hStdOut == INVALID_HANDLE_VALUE) return;
if (!GetConsoleScreenBufferInfo(hStdOut, &csbi)) return;
cellCount = csbi.dwSize.X *csbi.dwSize.Y;
if (!FillConsoleOutputCharacter(
hStdOut,
(TCHAR) ' ',
cellCount,
homeCoords,
&count
)) return;
if (!FillConsoleOutputAttribute(
hStdOut,
csbi.wAttributes,
cellCount,
homeCoords,
&count
)) return;
SetConsoleCursorPosition(hStdOut, homeCoords);
}
bool Game::startGame() {
map = new Map();
player = new Player();
player->setHealth(20);
string response = "";
bool hasResponse = false;
bool startgame = true;
while (true) {
ClearScreen();
//If player died
if (player->getHealth() < 1) {
delete map;
return false;
}
//If player won
if (map->getActualRoom()->getLabel() == "END" && map->getActualRoom()->isMonsterDead()) {
delete map;
return true;
}
//Print player health
cout << endl
<< "\t==== Hrac" << endl
<< "\t* Zivoty: " << player->getHealth() << endl;
//Print player damage
int* playerDmg = player->getWeaponDamage();
cout << "\t* Utok: " << player->getWeapon()->getName() << " (" << playerDmg[0] << "-" << playerDmg[1] << ")" << endl;
//Print player inventory
cout << "\t* Inventar: " << player->getInvetoryList() << endl
<< "\t====" << endl << endl;
//Print legend
cout << "\t==== Legenda"
<< map->getActualRoom()->getLegend()
<< "\t====" << endl << endl;
//Print response
if (startgame) {
response = map->getActualRoom()->getInitText();
response.append("\n");
}
if (hasResponse || startgame) {
cout << "\t==== Informace" << endl
<< "\t* " << endl
<< "\t* " << response
<< "\t* " << endl
<< "\t====" << endl;
startgame = false;
}
else {
cout << "\t==== Informace" << endl
<< "\t* " << endl
<< "\t* " << endl
<< "\t* " << endl
<< "\t====" << endl;
}
//Print map
map->printMap();
response = "";
//Wait for input
response = map->getActualRoom()->waitForAction(player);
//If has text/info response
hasResponse = response != "top" && response != "right" && response != "bottom" && response != "left";
if (map->getActualRoom()->getStatusDoor(response)) {
response = map->moveActualPlaPos(response)->getInitText();
response.append("\n");
hasResponse = true;
}
}
}
void Game::startMenu() {
int n = -1;
while (true) {
ClearScreen();
cout << endl
<< "\t ======================================================================= " << endl
<< "\t* *" << endl
<< "\t* ____ ___ _____ _ _ *" << endl
<< "\t* | \\ _ _ ___ ___ ___ ___ ___ ___| _| | __ |_ _ _| |_|_ _ *" << endl
<< "\t* | | | | | | . | -_| . | | | . | _| | -| | | . | |_'_| *" << endl
<< "\t* |____/|___|_|_|_ |___|___|_|_| |___|_| |__|__|___|___|_|_,_| *" << endl
<< "\t* |___| *" << endl
<< "\t* *" << endl
<< "\t*_______________________________________________________________________*" << endl
<< "\t* *" << endl
<< "\t* *" << endl
<< "\t* 0: Zacit hru *" << endl
<< "\t* 1: Jak se hra hraje *" << endl
<< "\t* 2: O autorovi *" << endl
<< "\t* *" << endl
<< "\t* *" << endl
<< "\t*=======================================================================*" << endl;
n = readInput->read();
if (n == 0) {
break;
}
else if (n == 1) {
while (n != 3) {
ClearScreen();
cout << endl
<< "\t ======================================================================= " << endl
<< "\t* *" << endl
<< "\t* ____ ___ _____ _ _ *" << endl
<< "\t* | \\ _ _ ___ ___ ___ ___ ___ ___| _| | __ |_ _ _| |_|_ _ *" << endl
<< "\t* | | | | | | . | -_| . | | | . | _| | -| | | . | |_'_| *" << endl
<< "\t* |____/|___|_|_|_ |___|___|_|_| |___|_| |__|__|___|___|_|_,_| *" << endl
<< "\t* |___| *" << endl
<< "\t* *" << endl
<< "\t*_______________________________________________________________________*" << endl
<< "\t* *" << endl
<< "\t* *" << endl
<< "\t* Cela hra se ovlada pomoci cisel. *" << endl
<< "\t* Cislicemi 8, 6, 5, 4 se ovlada smer pohybu *" << endl
<< "\t* Cislice 0, 1, 2, 3 jsou ovladani akci, ktere jsou *" << endl
<< "\t* vysvetlene v legende *" << endl
<< "\t* *" << endl
<< "\t* Ukolem hry je se dostat do mistnosti s napisem END *" << endl
<< "\t* Po ceste ziskavas predmety a zabijis monstra *" << endl
<< "\t* *" << endl
<< "\t* *" << endl
<< "\t* 3: zpet *" << endl
<< "\t*=======================================================================*" << endl;
n = readInput->read();
}
}
else if (n == 2) {
while (n != 3) {
ClearScreen();
cout << endl
<< "\t ======================================================================= " << endl
<< "\t* *" << endl
<< "\t* ____ ___ _____ _ _ *" << endl
<< "\t* | \\ _ _ ___ ___ ___ ___ ___ ___| _| | __ |_ _ _| |_|_ _ *" << endl
<< "\t* | | | | | | . | -_| . | | | . | _| | -| | | . | |_'_| *" << endl
<< "\t* |____/|___|_|_|_ |___|___|_|_| |___|_| |__|__|___|___|_|_,_| *" << endl
<< "\t* |___| *" << endl
<< "\t* *" << endl
<< "\t*_______________________________________________________________________*" << endl
<< "\t* *" << endl
<< "\t* *" << endl
<< "\t* Autorem teto hry je Pavel Seps, kdy tuto hru vytvoril jako *" << endl
<< "\t* semestralni praci. *" << endl
<< "\t* Cely projekt je k nahlednuti na githabu: *" << endl
<< "\t* https://github.com/pavelseps/DoR *" << endl
<< "\t* *" << endl
<< "\t* *" << endl
<< "\t* 3: zpet *" << endl
<< "\t*=======================================================================*" << endl;
n = readInput->read();
}
}
}
}
bool Game::endGame(bool victory) {
string response = "";
if (victory) {
response = "Gratuluji! Vyhral jsi a porazil jsi Rudixe";
}
else {
response = "Dungeon te porazil ";
}
int n = -1;
while (true) {
ClearScreen();
cout << endl
<< "\t ======================================================================= " << endl
<< "\t* *" << endl
<< "\t* ____ ___ _____ _ _ *" << endl
<< "\t* | \\ _ _ ___ ___ ___ ___ ___ ___| _| | __ |_ _ _| |_|_ _ *" << endl
<< "\t* | | | | | | . | -_| . | | | . | _| | -| | | . | |_'_| *" << endl
<< "\t* |____/|___|_|_|_ |___|___|_|_| |___|_| |__|__|___|___|_|_,_| *" << endl
<< "\t* |___| *" << endl
<< "\t* *" << endl
<< "\t*_______________________________________________________________________*" << endl
<< "\t* *" << endl
<< "\t* " << response << " *" << endl
<< "\t* Prejes si zacit znovu? *" << endl
<< "\t* *" << endl
<< "\t* 0: Ano *" << endl
<< "\t* 1: Ne, hra se vypne *" << endl
<< "\t* *" << endl
<< "\t*=======================================================================*" << endl;
n = readInput->read();
if (n == 0) {
return 1;
}
else if (n == 1) {
return 0;
}
}
}