-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClapTrap.cpp
More file actions
133 lines (116 loc) · 2.8 KB
/
ClapTrap.cpp
File metadata and controls
133 lines (116 loc) · 2.8 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
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
#include "ClapTrap.hpp"
ClapTrap::ClapTrap ()
: _name ("guest"), _hitPoints (10), _energyPoints (10), _attackDamage (0)
{
print ("ClapTrap default constructor called");
}
ClapTrap::ClapTrap (std::string name)
: _name (name), _hitPoints (10), _energyPoints (10), _attackDamage (0)
{
print ("ClapTrap name constructor called");
}
ClapTrap::ClapTrap (const ClapTrap &other)
{
print ("ClapTrap copy constructor called");
*this = other;
}
ClapTrap &
ClapTrap::operator= (const ClapTrap &other)
{
print ("ClapTrap assigment operator called");
if (this != &other)
{
this->setName (other.getName ());
this->setHitPoints (other.getHitPoints ());
this->setEnergyPoints (other.getEnergyPoints ());
this->setAttackDamage (other.getAttackDamage ());
}
return *this;
}
std::string
ClapTrap::getName () const
{
return _name;
}
void
ClapTrap::setName (std::string name)
{
_name = name;
}
void
ClapTrap::attack (const std::string &target)
{
if (getHitPoints () <= 0)
print ("ClapTrap " << getName () << " is dead and can't attack!");
else if (getEnergyPoints () <= 0)
print ("ClapTrap " << getName () << " is out of energy and can't attack!");
else
{
print ("ClapTrap " << getName () << " attacks " << target << ", causing "
<< getAttackDamage () << " points of damage!");
_energyPoints -= 1;
}
}
void
ClapTrap::takeDamage (unsigned int amount)
{
print ("ClapTrap " << getName () << " takes " << amount
<< " points of damage!");
_hitPoints -= amount;
}
void
ClapTrap::beRepaired (unsigned int amount)
{
if (getHitPoints () <= 0)
print ("ClapTrap " << getName () << " is dead and can't be repaired!");
else if (getEnergyPoints () <= 0)
print ("ClapTrap " << getName ()
<< " is out of energy and can't be repaired!");
else
{
print ("ClapTrap " << getName () << " is repaired by " << amount
<< " points!");
_energyPoints -= 1;
_hitPoints += amount;
}
}
int
ClapTrap::getHitPoints () const
{
return _hitPoints;
}
void
ClapTrap::setHitPoints (int amount)
{
if (amount >= 0)
_hitPoints = amount;
else
print ("ClapTrap hit points can't be negative! Previous value kept.");
}
int
ClapTrap::getEnergyPoints () const
{
return _energyPoints;
}
void
ClapTrap::setEnergyPoints (int amount)
{
if (amount >= 0)
_energyPoints = amount;
else
print ("ClapTrap energy points can't be negative! Previous value kept.");
}
void
ClapTrap::setAttackDamage (int amount)
{
if (amount >= 0)
_attackDamage = amount;
else
print ("ClapTrap attack damage can't be negative! Previous value kept.");
}
int
ClapTrap::getAttackDamage () const
{
return _attackDamage;
}
ClapTrap::~ClapTrap () { print ("ClapTrap destructor called"); }