Skip to content

Commit 42b4824

Browse files
committed
bug fixes
1 parent a132ff3 commit 42b4824

File tree

1 file changed

+58
-34
lines changed

1 file changed

+58
-34
lines changed

src/adventure.cpp

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ using namespace libeo;
2424
vector<string> enemies = { "Zombie", "Ghost", "Ghoul", "Skeleton", "Demon", "Soldier", "Giant" };
2525

2626
u_char input;
27-
bool has_completed = false;
2827
int rand_e;
2928

29+
typedef enum {
30+
Completed,
31+
Died,
32+
Exited
33+
} completions;
34+
35+
short completion_status;
36+
3037
typedef short Health;
3138

3239
class Character
@@ -66,19 +73,29 @@ void log_completion()
6673
ofstream logfile;
6774
logfile.open("LOGS.txt");
6875

69-
if(has_completed)
76+
77+
switch(completion_status)
7078
{
71-
logfile << "Congratulations!\n" <<
72-
"Your character, " << Player.name << ", defeated leagues of enemies and claimed the treasure!\n" <<
73-
"They were level " << Player.level << ", with " << Player.exp << " exp points and a remaining health of " << Player.cur_h << " after defeating all of the enemies!\n" <<
74-
"\nI owe you my thanks for playing my game!\no7\n";
75-
} else {
76-
logfile << "Yikes..\n" <<
77-
"Your character, " << Player.name << ", entered the dungeon looking for some enemies to kill and some treasure to find.\n" <<
78-
"Unfortunately, the cave dwellers had other plans.\n" <<
79-
"After defeating " << Player.enemies_defeated << " enemies, " << Player.name << " died!\n" <<
80-
"They were level " << Player.level << ", with " << Player.exp << " exp points.\n" <<
81-
"\nI owe you my thanks for playing my game!\no7\n";
79+
case Completed:
80+
logfile << "Congratulations!\n" <<
81+
"Your character, " << Player.name << ", defeated leagues of enemies and claimed the treasure!\n" <<
82+
"They were level " << Player.level << ", with " << Player.exp << " exp points and a remaining health of " << Player.cur_h << " after defeating all of the enemies!\n" <<
83+
"\nI owe you my thanks for playing my game!\no7\n";
84+
break;
85+
case Died:
86+
logfile << "Yikes..\n" <<
87+
"Your character, " << Player.name << ", entered the dungeon looking for some enemies to kill and some treasure to find.\n" <<
88+
"Unfortunately, the cave dwellers had other plans.\n" <<
89+
"After defeating " << Player.enemies_defeated << " enemies, " << Player.name << " died!\n" <<
90+
"They were level " << Player.level << ", with " << Player.exp << " exp points.\n" <<
91+
"\nI owe you my thanks for playing my game!\no7\n";
92+
break;
93+
case Exited:
94+
logfile << "Your character, " << Player.name << ", entered the dungeon searching for treasure." << endl <<
95+
"After defeating" << Player.enemies_defeated << " enemies, they decided they had enough." << endl <<
96+
"They were level " << Player.level << ", with " << Player.exp << " exp points.\n" <<
97+
"\nI owe you my thanks for playing my game!\no7\n";
98+
break;
8299
}
83100

84101
logfile.close();
@@ -228,6 +245,7 @@ void battle(string e_name)
228245
cout << "You collapsed...";
229246
sleep_for(milliseconds(1500));
230247
cout << "you died!" << endl;
248+
completion_status = Died;
231249

232250
sleep_for(milliseconds(2500));
233251

@@ -329,34 +347,40 @@ int main(int argc, char *argv[])
329347
cout << "With the last enemy defeated, you have found your way to the treasure!" << endl;
330348
cout << "Congratulations for completing the game!" << endl;
331349

332-
has_completed = true;
350+
completion_status = Completed;
333351
sleep_for(milliseconds(3000));
334352
break;
335353
}
336354

337-
SELECTION:
338-
cout << "\nWhat is next? Do you:" << endl <<
339-
" 1. Continue deeper into the dungeon" << endl <<
340-
" 2. Check your info" << endl <<
341-
" 3. Exit" << endl;
355+
input = NULL;
356+
while(input != '1' && input != '3') {
342357

343-
cin >> input;
358+
cout << "\nWhat is next? Do you:" << endl <<
359+
" 1. Continue deeper into the dungeon" << endl <<
360+
" 2. Check your info" << endl <<
361+
" 3. Exit" << endl;
344362

345-
new_line();
363+
cin >> input;
346364

347-
switch (input)
348-
{
349-
case '1': default:
350-
cout << "You decide to continue deeper into the dungeon..." << endl;
351-
break;
352-
case '2':
353-
present_info(Player.name, Player.cur_h, Player.level, Player.exp, Player.enemies_defeated);
354-
goto SELECTION;
355-
case '3':
356-
cout << "You exit the dungeon, leaving your sword behind..." << endl;
357-
sleep_for(milliseconds(3000));
358-
is_playing = false;
359-
break;
365+
new_line();
366+
367+
switch (input)
368+
{
369+
case '1':
370+
cout << "You decide to continue deeper into the dungeon..." << endl;
371+
break;
372+
case '2':
373+
present_info(Player.name, Player.cur_h, Player.level, Player.exp, Player.enemies_defeated);
374+
break;
375+
case '3':
376+
cout << "You exit the dungeon, leaving your sword behind..." << endl;
377+
sleep_for(milliseconds(3000));
378+
is_playing = false;
379+
completion_status = Exited;
380+
break;
381+
default:
382+
cout << "Please specify one of the specified options!" << endl;
383+
}
360384
}
361385
}
362386

0 commit comments

Comments
 (0)