-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCombatNarrative.cpp
More file actions
318 lines (292 loc) · 14.4 KB
/
Copy pathCombatNarrative.cpp
File metadata and controls
318 lines (292 loc) · 14.4 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
315
316
317
318
#include <iostream>
#include <string>
#include "Characters.cpp"
#include "SFML/Graphics.hpp"
#include "Button.cpp"
using namespace sf;
using namespace std;
class CombatNarrative{
public:
CharacterSuper* character;
Text instruction[10];
Button choice[3];
Font font;
Time time;
CombatNarrative(CharacterSuper* characterType){
time = seconds(2);
if (!font.loadFromFile("arial.ttf")) {}
character = characterType;
for(int i = 0; i < 10; i++ ){
instruction[i].setFont(font);
instruction[i].setFillColor(sf::Color::White);
}
}
//Displays fight with dragon. Returns true if the character wins and false if they lose
bool fightDragon(RenderWindow &window){
int dragonHealth = 100;
bool won = false;
while(1){
window.clear();
instruction[0].setPosition(Vector2f(10, 50));
instruction[0].setString("Dragon's health is " + to_string(dragonHealth));
instruction[1].setPosition(Vector2f(10, 150));
instruction[1].setString("Your health is " + to_string(character->getHealth()));
instruction[2].setPosition(Vector2f(10,200));
instruction[2].setString("Choose your next action:");
choice[0] = Button(Vector2f(50, 300), 600, 50, font, "Attack the dragon with your weapon");
choice[1] = Button(Vector2f(50, 400), 300, 50, font, "Heal Yourself");
choice[2] = Button(Vector2f(50, 500), 200, 50, font, "Hide");
window.draw(instruction[0]);
window.draw(instruction[1]);
window.draw(instruction[2]);
choice[0].drawButton(window);
choice[1].drawButton(window);
choice[2].drawButton(window);
window.display();
Event event;
while (window.pollEvent(event)){
switch (event.type){
case Event::Closed:
window.close();
break;
case Event::MouseButtonPressed:
if(event.mouseButton.button == Mouse::Left) {
Vector2f mousePos = window.mapPixelToCoords(Mouse::getPosition(window));
if(choice[0].isClicked(mousePos)){
window.clear();
int damageToDragon = (int)((25*(character->getStrength()/100.0))+(5*(character->getWeaponStrength()/100.0)));
dragonHealth-=damageToDragon;
instruction[3].setPosition(Vector2f(10,200));
instruction[3].setString("Your blow lands! The dragon loses " + to_string(damageToDragon) + " health.");
window.draw(instruction[3]);
window.display();
sleep(time);
}else if(choice[1].isClicked(mousePos)){
window.clear();
if((character->getHealth()+25)<100){
character->gainHealth(25);
}else{
character->maxHealth();
}
instruction[4].setPosition(Vector2f(10,200));
instruction[4].setString("You patch up your wounds. You gain 25 health");
window.draw(instruction[4]);
window.display();
sleep(time);
}else if(choice[2].isClicked(mousePos)){
window.clear();
int damageToCharacter = (int)(25*(1-(character->getArmor()/100.0)))+5;
character->loseHealth(damageToCharacter);
instruction[5].setPosition(Vector2f(10,200));
instruction[5].setString("You attempt to run away.\nThe dragon attacks and you lose " + to_string(damageToCharacter) + " health.");
window.draw(instruction[5]);
window.display();
sleep(time);
}
}
break;
default:
break;
}
}
if(character->getHealth()<=0){
window.clear();
won = false;
instruction[6].setPosition(Vector2f(10,200));
instruction[6].setString("The Dragon Killed You.\n\nGAME END\n");
window.draw(instruction[6]);
window.display();
sleep(time);
window.close();
}else if(dragonHealth<=0){
window.clear();
won = true;
instruction[7].setPosition(Vector2f(10, 200));
instruction[7].setString("You defeat the dragon! Your armor has been increased by 10.");
character->gainArmor(10);
window.draw(instruction[7]);
window.display();
sleep(time);
return won;
}
}
}
//Displays fight with lake monster. Returns true if the character wins and false if they lose
bool fightLakeMonster(RenderWindow &window){
int lakeMonsterHealth = 150;
bool won = false;
while(1){
window.clear();
instruction[0].setPosition(Vector2f(10, 50));
instruction[0].setString("Lake monster's health is " + to_string(lakeMonsterHealth));
instruction[1].setPosition(Vector2f(10, 150));
instruction[1].setString("Your health is " + to_string(character->getHealth()));
instruction[2].setPosition(Vector2f(10,200));
instruction[2].setString("Choose your next action:");
choice[0] = Button(Vector2f(50, 300), 600, 50, font, "Attack the lake monster with your weapon");
choice[1] = Button(Vector2f(50, 400), 300, 50, font, "Heal Yourself");
choice[2] = Button(Vector2f(50, 500), 200, 50, font, "Hide");
window.draw(instruction[0]);
window.draw(instruction[1]);
window.draw(instruction[2]);
choice[0].drawButton(window);
choice[1].drawButton(window);
choice[2].drawButton(window);
window.display();
Event event;
while (window.pollEvent(event)){
switch (event.type) {
case Event::Closed:
window.close();
break;
case Event::MouseButtonPressed:
if(event.mouseButton.button == Mouse::Left) {
Vector2f mousePos = window.mapPixelToCoords(Mouse::getPosition(window));
if(choice[0].isClicked(mousePos)){
window.clear();
int damageToLakeMonster = (int)(25*(character->getStrength()/100.0))+(5*(character->getWeaponStrength()/100.0));
lakeMonsterHealth-=damageToLakeMonster;
instruction[3].setPosition(Vector2f(10,200));
instruction[3].setString("Your blow lands! The lake monster loses " + to_string(damageToLakeMonster) + " health.");
window.draw(instruction[3]);
window.display();
sleep(time);
}else if(choice[1].isClicked(mousePos)){
window.clear();
if((character->getHealth()+25)<100){
character->gainHealth(25);
}else{
character->maxHealth();
}
instruction[4].setPosition(Vector2f(10,200));
instruction[4].setString("You patch up your wounds. You gain 25 health");
window.draw(instruction[4]);
window.display();
sleep(time);
}else if(choice[2].isClicked(mousePos)){
window.clear();
character->loseHealth(25);
instruction[5].setPosition(Vector2f(10,200));
instruction[5].setString("You attempt to run away.\nThe dragon attacks and you lose 25 health.");
window.draw(instruction[5]);
window.display();
sleep(time);
}
}
break;
default:
break;
}
}
if(character->getHealth()<=0){
window.clear();
won = false;
instruction[6].setPosition(Vector2f(10,200));
instruction[6].setString("The Lake Monster Killed You.\n\nGAME END\n");
window.draw(instruction[6]);
window.display();
sleep(time);
window.close();
}else if(lakeMonsterHealth<=0){
window.clear();
won = true;
instruction[7].setPosition(Vector2f(10, 200));
instruction[7].setString("You defeat the lake monster! Your strength has been increased.");
character->gainArmor(10);
window.draw(instruction[7]);
window.display();
sleep(time);
return won;
}
}
}
//Displays fight with king. Returns true if the character wins and false if they lose
bool fightKing(RenderWindow &window){
int kingHealth = 200;
bool won = false;
while(1){
window.clear();
instruction[0].setPosition(Vector2f(10, 50));
instruction[0].setString("The kings's health is " + to_string(kingHealth));
instruction[1].setPosition(Vector2f(10, 150));
instruction[1].setString("Your health is " + to_string(character->getHealth()));
instruction[2].setPosition(Vector2f(10,200));
instruction[2].setString("Choose your next action:");
choice[0] = Button(Vector2f(50, 300), 600, 50, font, "Attack the king with your weapon");
choice[1] = Button(Vector2f(50, 400), 300, 50, font, "Heal Yourself");
choice[2] = Button(Vector2f(50, 500), 200, 50, font, "Hide");
window.draw(instruction[0]);
window.draw(instruction[1]);
window.draw(instruction[2]);
choice[0].drawButton(window);
choice[1].drawButton(window);
choice[2].drawButton(window);
window.display();
Event event;
while (window.pollEvent(event)){
switch (event.type){
case Event::Closed:
window.close();
break;
case Event::MouseButtonPressed:
if(event.mouseButton.button == Mouse::Left) {
Vector2f mousePos = window.mapPixelToCoords(Mouse::getPosition(window));
if(choice[0].isClicked(mousePos)){
window.clear();
int damageToKing = (int)(25*(character->getStrength()/100.0))+(5*(character->getWeaponStrength()/100.0));
kingHealth-=damageToKing;
instruction[3].setPosition(Vector2f(10,200));
instruction[3].setString("Your blow lands! The king loses " + to_string(damageToKing) + " health.");
window.draw(instruction[3]);
window.display();
sleep(time);
}else if(choice[1].isClicked(mousePos)){
window.clear();
if((character->getHealth()+25)<100){
character->gainHealth(25);
}else{
character->maxHealth();
}
instruction[4].setPosition(Vector2f(10,200));
instruction[4].setString("You patch up your wounds. You gain 25 health");
window.draw(instruction[4]);
window.display();
sleep(time);
}else if(choice[2].isClicked(mousePos)){
window.clear();
character->loseHealth(25);
instruction[5].setPosition(Vector2f(10,200));
instruction[5].setString("You attempt to run away.\nThe king attacks and you lose 25 health.");
window.draw(instruction[5]);
window.display();
sleep(time);
}
}
break;
default:
break;
}
}
if(character->getHealth()<=0){
window.clear();
won = false;
instruction[6].setPosition(Vector2f(10,200));
instruction[6].setString("The King Killed You.\nBetter Luck Next Time.\n\nGAME END\n");
window.draw(instruction[6]);
window.display();
sleep(time);
window.close();
}else if(kingHealth<=0){
window.clear();
won = true;
instruction[7].setPosition(Vector2f(10, 200));
instruction[7].setString("You defeat the King! Your strength has been increased.");
character->gainArmor(10);
window.draw(instruction[7]);
window.display();
sleep(time);
return won;
}
}
}
};