-
Notifications
You must be signed in to change notification settings - Fork 72
/
HealthPoints.h
224 lines (182 loc) · 5.82 KB
/
HealthPoints.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
#ifndef HEALTHPOINTS_H
#define HEALTHPOINTS_H
#include <iostream>
using std::cout;
using std::endl;
static const int DEFAULT_MAX_HP = 100;
static const int MIN_HP = 0;
class HealthPoints
{
public:
/*
* C'tor of HealthPoints class
*
* @param maxHP - The maximum HealthPoints of the player.
* @return
* A new instance of HealthPoints.
*/
HealthPoints(int maxHP = DEFAULT_MAX_HP);
/*
* Copy c'tor of Player class
*
* @param h - A reference of an existing HealthPoints instance.
* @return
* A copied instance of h.
*/
HealthPoints(const HealthPoints& h) = default;
/*
* D'tor of HealthPoints class
*
* @return
* Deletes this instance of HealthPoints.
*/
~HealthPoints()=default;
/*
* Assignment operator
*
* @param h - The HealthPoints to assign from.
* @return
* default
*/
HealthPoints& operator=(HealthPoints h);
/*
* adds num to the currentHP and returns the new currentHP.
*
* @param num - The number of health points to add to the currentHP.
*
* @return
* currentHP after adding num.
*/
HealthPoints& operator+=(const int num);
/*
* substracts num from the currentHP and returns the new currentHP.
*
* @param num - The number of health points to substract from the currentHP.
*
* @return
* currentHP after substracting num.
*/
HealthPoints& operator-=(const int num);
/*
* Compares between the currentHP of two given instances of HealthPoints.
*
* @param first - An instance of HealthPoints.
* @param other - An instance of HealthPoints.
* @return
* True if the currentHP of the two instances is the same.
* False otherwise
*/
friend bool operator==(const HealthPoints& first, const HealthPoints& other);
/*
* Compares between the currentHP of two given instances of HealthPoints.
*
* @param first - An instance of HealthPoints.
* @param other - An instance of HealthPoints.
* @return
* True if the currentHP of the other instance's currentHP is bigger than the first's.
* False otherwise
*/
friend bool operator<(const HealthPoints& first, const HealthPoints& other);
/*
* Prints the values of currentHP and maxHealthPoints to a given file.
*
* @param os - the file to print to.
* @param first - An instance of HealthPoints.
* @return
* A print.
*/
friend std::ostream& operator<<(std::ostream& os, const HealthPoints& first);
/*
* This exception will be thrown
* if an invalid argument is received in the constructor of HealthPoints.
*/
class InvalidArgument {};
private:
int m_maxHealthPoints;
int m_cuurentHP;
/*
* Returns the currentHP of the HealthPoints instance.
*
* @return
* The maxHealthPoints.
*/
int get_m_currentHP() const;
/*
* Returns the maxHealthPoints of the HealthPoints instance.
*
* @return
* The maxHealthPoints.
*/
int get_m_maxHealthPoints() const;
};
/*
* Compares between the currentHP of two given instances of HealthPoints.
*
* @param first - An instance of HealthPoints.
* @param other - An instance of HealthPoints.
* @return
* True if the currentHP of the two instances is different.
* False otherwise
*/
bool operator!=(const HealthPoints& first, const HealthPoints& other);
/*
* Compares between the currentHP of two given instances of HealthPoints.
*
* @param first - An instance of HealthPoints.
* @param other - An instance of HealthPoints.
* @return
* True if the currentHP of the other instance's currentHP is bigger than or equal to the first's.
* False otherwise
*/
bool operator<=(const HealthPoints& first, const HealthPoints& other);
/*
* Compares between the currentHP of two given instances of HealthPoints.
*
* @param first - An instance of HealthPoints.
* @param other - An instance of HealthPoints.
* @return
* True if the currentHP of the first instance's currentHP is bigger than the other's.
* False otherwise
*/
bool operator>(const HealthPoints& first, const HealthPoints& other);
/*
* Compares between the currentHP of two given instances of HealthPoints.
*
* @param first - An instance of HealthPoints.
* @param other - An instance of HealthPoints.
* @return
* True if the currentHP of the first instance's currentHP is bigger than or equal to the other's.
* False otherwise
*/
bool operator>=(const HealthPoints& first, const HealthPoints& other);
/*
* adds a given num to the currentHP of a given HealthPoints instance.
*
* @param healthPoints - The HealthPoints instance to add the given num to.
* @param num - The number of health points to add to the currentHP of the given healthPoints.
*
* @return
* The healthPoints instance after the adding.
*/
HealthPoints operator+(const HealthPoints& healthPoints, const int num);
/*
* adds a given number to the currentHP of a given HealthPoints instance.
*
* @param healthPoints - The HealthPoints instance to add the given number to.
* @param num - The number of health points to add to the currentHP of the given healthPoints.
*
* @return
* The healthPoints instance after the adding.
*/
HealthPoints operator+(const int num, const HealthPoints& healthPoints);
/*
* subtracts a given number from the currentHP of a given HealthPoints instance.
*
* @param healthPoints - The HealthPoints instance to subtract the given num from.
* @param num - The number of health points to subtract from the currentHP of the given healthPoints.
*
* @return
* The healthPoints instance after the subtracting.
*/
HealthPoints operator-(const HealthPoints& healthPoints, const int num);
#endif