forked from NoaAmsalem/ex3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHealthPoints.cpp
More file actions
75 lines (64 loc) · 1.82 KB
/
Copy pathHealthPoints.cpp
File metadata and controls
75 lines (64 loc) · 1.82 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
#include "HealthPoints.h"
HealthPoints::HealthPoints(int maxHP):m_maxHP(maxHP),
m_currentHP(maxHP)
{
if(maxHP<=0)
{
throw HealthPoints::InvalidArgument();
}
}
HealthPoints& HealthPoints:: operator+=(const int add){
m_currentHP+= add;
if(m_currentHP < 0){
m_currentHP = 0;
}
if(m_currentHP > m_maxHP){
m_currentHP = m_maxHP;
}
return *this;
}
HealthPoints& HealthPoints:: operator-=(const int sub){
*this+= -sub;
return *this;
}
HealthPoints HealthPoints:: operator+(const int add){
HealthPoints result = *this;
return result+=add;
}
HealthPoints HealthPoints:: operator-(const int sub){
HealthPoints result = *this;
return result-=sub;
}
HealthPoints operator+(const int add, const HealthPoints& hp){
HealthPoints result = hp;
return result+=add;
}
HealthPoints operator-(const int sub, const HealthPoints& hp){
HealthPoints result = hp;
return result-=sub;
}
std::ostream& operator<<(std::ostream& os, const HealthPoints& hp){
os<<hp.m_currentHP <<"(" << hp.m_maxHP<<")";
return os;
}
bool operator==(const HealthPoints& hp1, const HealthPoints& hp2){
if(hp1.m_currentHP == hp2.m_currentHP) return true;
else return false;
}
bool operator!=(const HealthPoints& hp1, const HealthPoints& hp2){
return !(hp1==hp2);
}
bool operator>=(const HealthPoints&hp1, const HealthPoints&hp2){
if(hp1.m_currentHP >= hp2.m_currentHP) return true;
else return false;
}
bool operator>(const HealthPoints& hp1, const HealthPoints& hp2){
if((hp1 >= hp2) &&(hp1 != hp2)) return true;
else return false;
}
bool operator<=(const HealthPoints& hp1, const HealthPoints& hp2){
return !(hp1 > hp2);
}
bool operator<(const HealthPoints& hp1, const HealthPoints& hp2){
return!(hp1 >= hp2);
}