-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdungeon.cpp
More file actions
105 lines (97 loc) · 2.51 KB
/
dungeon.cpp
File metadata and controls
105 lines (97 loc) · 2.51 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
#include "dungeon.h"
void Dungeon::play() {
int i, j;
while (true) {
i = ch->getCurrentFloor();
std::cout << *(dungeon[i]);
std::cout << std::setfill('-') << std::setw(10) << "" << "Controls" << std::setfill('-') << std::setw(10) << "" << std::setfill(' ') << std::endl;
std::cout << "UP - W, DOWN - S, RIGHT - D, LEFT - A, OPEN INVENTORY - O\n" << std::endl;
std::cout << "Your Command: ";
std::cin >> in;
//First five conditionals are for backdoor presentation purposes
if (in[0] == 'f' && isdigit(in[1])) {
int f;
std::stringstream s(in.substr(1));
s >> f;
ch->setCurrentFloor(f - 1); //to account for vector 0 - based counting (make more user-friendly)
std::cout << std::endl;
continue;
}
else if (in == "tank") {
ch->setHP(9999999);
ch->setMana(9999999);
ch->setCurrHP(9999999);
ch->setCurrMana(9999999);
std::cout << std::endl;
continue;
}
else if (in == "reveal") {
dungeon[ch->getCurrentFloor()]->revealAll();
std::cout << std::endl;
continue;
}
else if (in == "hide") {
dungeon[ch->getCurrentFloor()]->hideAll();
std::cout << std::endl;
continue;
}
else if (in == "atk") {
ch->setATK(ch->getATK() + 10);
std::cout << std::endl;
continue;
}
else if (in.length() != 1) {
std::cout << std::endl;
continue;
}
std::cin.ignore(1000, '\n');
std::cout << std::endl;
input = tolower(in[0]);
try {
if (input == 'w' || input == 's' || input == 'a' || input == 'd') {
dungeon[i]->moveCharacter(input);
j = ch->getCurrentFloor();
if (j == 10) {
f.performEvent();
}
else if (i != j) { //Character moved up a floor
ch->setCoor(4, 0); //so reset to entrance coors for new floor
}
}
else if (input == 'o') {
try {
inv.useInventory();
}
catch (const Lamp& l) {
dungeon[ch->getCurrentFloor()]->revealLadder();
}
}
}
catch (std::string err) {
std::cout << err << std::endl;
if (err.find("WIN") != std::string::npos)
printVictory();
return;
}
}
}
void Dungeon::printVictory() const {
std::cout << std::endl << R"(
_______________
|@@@@| |####|
|@@@@| |####|
|@@@@| |####|
\@@@@| |####/
\@@@| |###/
`@@|_____|##'
(O)
.-'''''-.
.' * * * `.
: * * :
: ~ Y O U ~ :
: ~ W I N ! ~ :
: * * :
`. * * * .'
`-.....-'
)" << std::endl;
}