-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.h
More file actions
104 lines (94 loc) · 3.05 KB
/
Copy pathproject.h
File metadata and controls
104 lines (94 loc) · 3.05 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
#include <iostream>
#include <string>
#include <random>
using namespace std;
//this is the base class for items contained in containers.
class item {
public:
string name;
int attack_strength;
void setItem(string _name, int _attack_strength) {
name = _name;
attack_strength = _attack_strength;
}
virtual ~item() {};
};
//this is the base class for containers that are in room objects (environment objects)
class container {
public:
string name;
string description;
item items[10];
bool isLocked;
void setContainer(string _name, string _description, bool _isLocked) {
isLocked = _isLocked;
description = _description;
name = _name;
}
void addItems(int index, string name, int attack_strength) {
items[index].setItem(name, attack_strength);
}
virtual ~container() {};
};
//this is the class that room objects all inherit from. so far we
//just have rooms, but we can also have other types of environments.
//if we want, we can have specific types of environments like rooms
//or dungeons or underground things etc, but for now it's just rooms
class environment {
public:
string name;
string intro;
container containers[10];
environment* east; environment* west;
environment* north; environment* south;
//constructor
environment(string _name, string _intro) {
name = _name;
intro = _intro;
}
//destructor
virtual ~environment() {};
//add references to other environment objects that are in the
//cardinal directions from the environment object in question
void setSurroundings(environment* _north, environment* _south,
environment* _east, environment* _west) {
north = _north;
south = _south;
east = _east;
west = _west;
}
//spawns containers in the container list for the
//environment object you call this from. add up to 10.
void addContainers(int index, string name, string description, bool isLocked) {
containers[index].setContainer(name, description, isLocked);
}
//note that inspect works only on containers, not items. (for now)
int inspect(string input) {
int i = 0;
int j = 0;
//iterate through this list of items in container.
//error checking to make sure it doesn't segfault if given
//bad container name.
while(containers[i].name.compare(input) && i < 10) {
i++;
}
if (i == 10) {
cout<<"No such container to open." << endl;
}
else {
cout << "Inspecting " << containers[i].name << ".\n"
<< containers[i].description << "\n"<<endl;
if (containers[i].isLocked == true) {
cout<<"Unfortunately, it seems to be locked.\n"<< endl;
}
else {
cout<<"It contains:"<< endl;
while (containers[i].items[j].name != "") {
cout<<containers[i].items[j].name<<endl;
j++;
}
}
}
return 0;
}
};