-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClapTrap.cpp
More file actions
70 lines (65 loc) · 1.77 KB
/
Copy pathClapTrap.cpp
File metadata and controls
70 lines (65 loc) · 1.77 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
#include "ClapTrap.hpp"
ClapTrap::ClapTrap(std::string name) : name(name), hit_Points(10) , energy_Points(10), attack_Damage(0)
{
std::cout << "Default constructor called" << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap ©)
{
std::cout << "Copy constructor called" << std::endl;
*this = copy;
}
ClapTrap &ClapTrap::operator=(const ClapTrap &src)
{
std::cout << "Copy assignment operator called" << std::endl;
this->name = src.name;
this->hit_Points = src.hit_Points;
this->energy_Points = src.energy_Points;
this->attack_Damage = src.attack_Damage;
return (*this);
}
ClapTrap::~ClapTrap()
{
std::cout << "Destructor called" << std::endl;
}
void ClapTrap::attack(const std::string &target)
{
if (this->energy_Points == 0)
{
std::cout << " NO ENERGY" << std::endl;
return;
}
if (this->hit_Points <= 0)
{
std::cout << this->name << " is dead" << std::endl;
return;
}
std::cout << "ClapTrap " << this->name << " attacks " << target <<
", causing " << this->attack_Damage << " points of damage!" << std::endl;
this->energy_Points--;
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (this->energy_Points == 0)
{
std::cout << " NO ENERGY" << std::endl;
return;
}
if (this->hit_Points <= 0)
{
std::cout << this->name << " is dead" << std::endl;
return;
}
std::cout << "ClapTrap " << this->name << " repaired itself with " <<
amount << " hit points!" << std::endl;
this->hit_Points += amount;
}
void ClapTrap::takeDamage(unsigned int amount)
{
if (this->hit_Points <= 0)
{
std::cout << this->name << " is dead" << std::endl;
return;
}
std::cout << "ClapTrap " << this->name << " took " << amount << " damage!" << std::endl;
this->hit_Points -= amount;
}