-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
192 lines (190 loc) · 5.22 KB
/
Copy pathmain.cpp
File metadata and controls
192 lines (190 loc) · 5.22 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
#include <iostream>
#include "room.h"
#include "User.h"
#include "floor.h"
#include "BattleClass.h"
#include "Print.h"
#include "cheat.h"
int main() {
//Declare and initilize variables
User* player = new User();
int floorNum = 1;
char dir;
bool cheat = false;
bool godmode = false;
//Clear screen
clearScreen();
//Print intro
printStory();
std::cin>>dir;
cin.clear();
cin.ignore(1024, '\n');
clearScreen();
//Seed time for random generation
srand(time(0));
//Begin game
while (floorNum <= 4) {
//Generate new floor. Game should only have 4 floors.
Floor* currFloor = new Floor(floorNum);
while (true) {
//Check if player is still alive
if (player->getHealth() < 1) {
return 0;
}
//Print map
currFloor->getCurrRoom()->printMap();
//Receive input
std::cin>>dir;
//Read input for menu, minimap, and cheat input
if(dir == 'q') {
//Print menu and wait for user to hit 'q' again to close
clearScreen();
menu(player, floorNum);
while (true) {
std::cin >> dir;
if (dir == 'q') {
//Close menu
clearScreen();
break;
}
else if (dir == 'z'){
std::cout << "Are you sure? (Y/N)" << endl;
while(true){
std::cin >> dir;
if(dir == 'Y' || dir == 'y'){
return 0;
}
else if(dir == 'N' || dir == 'n'){
clearScreen();
menu(player, floorNum);
break;
}
cin.clear();
cin.ignore(1024, '\n');
}
}
cin.clear();
cin.ignore(1024, '\n');
}
continue;
}
else if (dir == 'e') {
//Open minimap and wait for user to hit 'e' again to close
clearScreen();
currFloor->printMap();
std::cout << "Enter 'e' to close" << endl;
while (true) {
std::cin >> dir;
if (dir == 'e') {
//Close minimap
clearScreen();
break;
}
cin.clear();
cin.ignore(1024, '\n');
}
continue;
}
else if (dir == '/'){
//Toggle cheats
cheat = toggle(cheat);
clearScreen();
(cheat) ? (std::cout << "Cheats enabled" << endl) : (std::cout << "Cheats disabled" << endl);
continue;
}
else if(dir == 'o' && cheat){
//Toggles godmode
player->setHealth(player->getMaxHealth());
godmode = toggle(godmode);
clearScreen();
(godmode) ? (std::cout << "Godmode enabled" << endl) : (std::cout << "Godmode disabled" << endl);
continue;
}
else if(dir == 'p' && cheat){
//Gives potion
if(player->getPotions() >= 10){
clearScreen();
cout << "You can't hold anymore notes!" << endl;
}
else{
player->addPotion();
clearScreen();
cout << "You found a packet of Smokin' Notes on the ground!" << endl;
}
continue;
}
else if(dir == 'k' && cheat){
//Kills all monsters in the room. Does not give player potions or experience, and cannot kill bosses.
if(currFloor->getCurrRoom()->isBoss()){
clearScreen();
cout << "Cannot infect the boss! The boss's internet is protected with SafeConnect!" << endl;
}
else{
currFloor->getCurrRoom()->killAllMonsters();
clearScreen();
std::cout << "A virus spread on all the enemies computers!" << endl;
}
continue;
}
else if(dir == 'l' && cheat){
//Levels up player
clearScreen();
player->levelUp();
continue;
}
else if (dir != 'w' && dir != 'a' && dir != 's' && dir != 'd' && dir != 'f'){
//Tell user invalid input was received
clearScreen();
std::cout << "Invalid input!" << endl;
cin.clear();
cin.ignore(1024, '\n');
continue;
}
if(godmode && cheat){
//Restore health if godmode and cheats are on
player->setHealth(player->getMaxHealth());
}
//Changes players location based on direction moved
player->move(dir, currFloor->getCurrRoom()->getMap());
//Sync player location with floor's knowledge of player location
currFloor->getCurrRoom()->setPlayerX(player->getXLocation());
currFloor->getCurrRoom()->setPlayerY(player->getYLocation());
//Move monsters
currFloor->getCurrRoom()->moveAllMonsters();
if (currFloor->getCurrRoom()->playerAtMonster()) {
//Initiate battle if player runs into monster
clearScreen();
cin.clear();
cin.ignore(1024, '\n');
Battle newBattle;
newBattle.battleScreen(player, player->getLevel(), floorNum, currFloor->getCurrRoom()->isBoss(), cheat, godmode);
currFloor->getCurrRoom()->killMonster(currFloor->getCurrRoom()->getPlayerLoc());
cin.clear();
cin.ignore(1024, '\n');
continue;
}
//Check if player is at door
int door = currFloor->getCurrRoom()->atDoor();
//Change room if player is at door
if (door != 0) {
//Check if door leads to new room. Change room and move player to opposite door if it does.
if (currFloor->changeRoom(door)) {
currFloor->getCurrRoom()->spawnPlayerAtDoor(-1*door);
}
int* tempPlayerLoc = currFloor->getCurrRoom()->getPlayerLoc();
player->setLocation(tempPlayerLoc[0], tempPlayerLoc[1]);
}
if (currFloor->getCurrRoom()->atStairs()) {
//Check if player is at stairs. Go up a floor if they are.
floorNum += 1;
break;
}
//Clear screen
clearScreen();
}
}
//Print victory message
clearScreen();
std::cout << "Congratulations!!! Your grade is saved!!!" << std::endl;
return 0;
}