-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.h
269 lines (175 loc) · 5.28 KB
/
Game.h
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
#ifndef GAME_H_
#define GAME_H_
#include <sstream>
#include <iostream>
#include <string>
#include <memory>
#include <vector>
using std::string;
class Player; // forward declaration so that Object can refer to Player
// ------------------ Object and its subclasses -------------------
class Object {
public:
// Default constructor, just to make this release version compilable.
// If your implementation is correct this should be removed
Object();
// Constructor, specifying the name and the value of an object.
Object(string name, int value);
// Destructor
virtual ~Object();
// Return the name of the object.
string getName() const;
// Return the value of the object.
int getValue() const;
// Return a string giving details of the object, as specified in
// the assignment webpage.
virtual string print() const;
virtual string getType() const = 0;
private:
// Use this object.
// This function should not be public; it only makes sense to be
// called from within a Player object (the player who owns it)
virtual void use() = 0;
protected:
// You probably want to have something like this.
// For technical reason it may be easier to just use a raw pointer
Player* owner_;
string name_;
int value_;
// TODO: add any other protected/private member variables
// Overloaded output stream redirection operator, printing the object to the
// given output stream
friend std::ostream& operator<<(std::ostream& os, const Object& o);
// You can "friend" other classes
friend class Player;
};
class Food : public Object {
public:
// Constructor
Food(string name, int value);
// Destructor
~Food();
// Add any member functions if needed
string getType() const override;
private:
// Add any member variables if needed
void use() override final;
};
class Weapon : public Object {
public:
// Constructor
Weapon(string name, int value);
// Destructor
~Weapon();
// Add any member functions if needed
string getType() const override;
private:
// Add any member variables if needed
void use() override final;
};
class Armour : public Object {
public:
// Constructor
Armour(string name, int value);
// Destructor
~Armour();
// Add any member functions if needed
std::string getType() const override;
private:
// Add any member variables if needed
void use() override final;
};
// ----------------- Player and its subclasses --------------------
class Player {
public:
// Default constructor, just to make this release version compilable.
// If your implementation is correct this should be removed
Player();
// Constructor, specifying the name of the player
// Set the health and stamina both to 100
Player(string name);
// Destructor
virtual ~Player() = 0;
// Return the name of the player
string getName() const;
// Return the current health of the player
int getHealth() const;
// Return the current stamina of the player
int getStamina() const;
// Add the object pointed to by the unique pointer to the
// inventory of objects this player carries.
// As this is a unique pointer, it has to be "moved" into this
// function using std::move().
void pickup(std::unique_ptr<Object> obj);
// Return a string listing all objects this player owns, in
// the format specified in the assignment page
string getInventory() const;
// Return a string that contains all details of a player, as
// specified in the assignment page
string print() const;
// Use the object with the given name. If the player does not
// own any object of this name, return false and do nothing,
// otherwise return true.
bool use(string name);
virtual string getType() const = 0;
void equip(string name);
bool isDead();
void setHealth(int health);
protected:
// TODO: add any protected or private member variables
string name_;
int health_;
int stamina_;
std::vector<std::unique_ptr<Object>> items_;
std::vector<std::shared_ptr<Object>> inventory_;
Weapon* weapon_in_use_;
std::vector <Armour*> armours_in_use_;
bool dead_;
// Player equipped armour
std::vector<string> armour_;
private:
//std::vector<std::shared_ptr<Object>> inventory;
// Overloaded stream redirection operator, that prints the contents of
// the player to the given output stream
friend std::ostream& operator<<(std::ostream& os, const Player& p);
// You can "friend" other classes
friend class Food;
friend class Weapon;
friend class Armour;
friend class Fighter;
friend class Healer;
};
class Fighter : public Player {
public:
// Constructor
Fighter(string name);
// Destructor
~Fighter();
// Attack the specified player, following the rules in the
// assignment page
bool attack(Player& other);
using Player::getInventory;
// Add any other functions if needed
string getType() const override;
//std::string getInventory() const override;
//string print() const override final;
private:
// add any member variables if needed
};
class Healer : public Player {
public:
// Constructor
Healer(string name);
// Destructor
~Healer();
// Heal the specified player, following the rules in the
// assignment page
bool heal(Player& other);
using Player::getInventory;
string getType() const override;
//string print() const override;
//std::string getInventory() const override;
private:
// add any member variables if needed
};
#endif /* GAME_H_ */