-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathHealthPoints.cpp
More file actions
109 lines (85 loc) · 2.24 KB
/
HealthPoints.cpp
File metadata and controls
109 lines (85 loc) · 2.24 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
#include "HealthPoints.h"
#include <iostream>
using std::cout;
using std::endl;
HealthPoints:: HealthPoints(int maxHP)
{
/* InvalidArgument exception is thrown if the recieved maxHP is smaller or equal to zero.*/
if(maxHP <= MIN_HP)
{
throw HealthPoints::InvalidArgument();
}
m_maxHealthPoints=maxHP;
m_cuurentHP=maxHP;
}
HealthPoints& HealthPoints::operator=(HealthPoints h)
{
this->m_cuurentHP= h.get_m_currentHP();
this->m_maxHealthPoints= h.get_m_maxHealthPoints();
return *this;
}
int HealthPoints::get_m_currentHP() const
{
return this->m_cuurentHP;
}
int HealthPoints::get_m_maxHealthPoints() const
{
return this->m_maxHealthPoints;
}
HealthPoints& HealthPoints:: operator+=(const int num)
{
m_cuurentHP = m_cuurentHP + num;
if (m_cuurentHP > m_maxHealthPoints)
{
m_cuurentHP = m_maxHealthPoints;
}
if (m_cuurentHP < MIN_HP)
{
m_cuurentHP = MIN_HP;
}
return *this;
}
HealthPoints& HealthPoints:: operator-=(const int num)
{
return *this += -num;
}
HealthPoints operator+(const HealthPoints& healthPoints, const int num)
{
return HealthPoints(healthPoints) += num;
}
HealthPoints operator+(const int num, const HealthPoints& healthPoints)
{
return HealthPoints(healthPoints) += num;
}
HealthPoints operator-(const HealthPoints& healthPoints, const int num)
{
return HealthPoints(healthPoints) -= num;
}
bool operator==(const HealthPoints& first, const HealthPoints& other)
{
return first.get_m_currentHP()== other.get_m_currentHP();
}
bool operator!=(const HealthPoints& first, const HealthPoints& other)
{
return !(first == other);
}
bool operator<(const HealthPoints& first, const HealthPoints& other)
{
return (first.get_m_currentHP() < other.get_m_currentHP());
}
bool operator<=(const HealthPoints& first, const HealthPoints& other)
{
return !(other < first);
}
bool operator>(const HealthPoints& first, const HealthPoints& other)
{
return (other < first);
}
bool operator>=(const HealthPoints& first, const HealthPoints& other)
{
return other <= first;
}
std::ostream& operator<<(std::ostream& os, const HealthPoints& first)
{
return os << first.get_m_currentHP() << "(" << first.get_m_maxHealthPoints() << ")" ;
}