-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClapTrap.cpp
More file actions
99 lines (90 loc) · 3.34 KB
/
ClapTrap.cpp
File metadata and controls
99 lines (90 loc) · 3.34 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ClapTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zelhajou <zelhajou@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/14 19:37:39 by zelhajou #+# #+# */
/* Updated: 2024/06/15 15:22:26 by zelhajou ### ########.fr */
/* */
/* ************************************************************************** */
#include "ClapTrap.hpp"
ClapTrap::ClapTrap() : _name("Default"), _hitPoints(10), _energyPoints(10), _attackDamage(0)
{
std::cout << "ClapTrap Default constructor called" << std::endl;
}
ClapTrap::ClapTrap(const std::string& name) : _name(name), _hitPoints(10), _energyPoints(10), _attackDamage(0)
{
std::cout << "ClapTrap " << _name << " is alive and ready for action!" << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap &src)
{
std::cout << "ClapTrap Copy constructor called" << std::endl;
*this = src;
}
ClapTrap::~ClapTrap()
{
std::cout << "ClapTrap " << _name << " is no more. RIP ClapTrap!" << std::endl;
}
ClapTrap &ClapTrap::operator=(const ClapTrap &src)
{
std::cout << "ClapTrap Assignation operator called" << std::endl;
if (this != &src)
{
_name = src._name;
_hitPoints = src._hitPoints;
_energyPoints = src._energyPoints;
_attackDamage = src._attackDamage;
}
return *this;
}
void ClapTrap::attack(const std::string& target)
{
if (_energyPoints > 0 && _hitPoints > 0)
{
std::cout << "ClapTrap " << _name << " attacks " << target << ", causing " << _attackDamage << " points of damage!" << std::endl;
_energyPoints--;
}
else if (_hitPoints <= 0)
{
std::cout << "ClapTrap " << _name << " cannot attack because it's out of hit points!" << std::endl;
}
else if (_energyPoints <= 0)
{
std::cout << "ClapTrap " << _name << " is out of energy and cannot attack!" << std::endl;
}
}
void ClapTrap::takeDamage(unsigned int amount)
{
if (_hitPoints > 0)
{
_hitPoints -= amount;
if (_hitPoints < 0)
_hitPoints = 0;
std::cout << "ClapTrap " << _name << " takes " << amount << " points of damage!" << std::endl;
if (_hitPoints == 0)
std::cout << "ClapTrap " << _name << " has died!" << std::endl;
}
else
{
std::cout << "ClapTrap " << _name << " is already out of hit points!" << std::endl;
}
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (_energyPoints > 0 && _hitPoints > 0)
{
_hitPoints += amount;
_energyPoints--;
std::cout << "ClapTrap " << _name << " repairs itself and gains " << amount << " hit points!" << std::endl;
}
else if (_hitPoints <= 0)
{
std::cout << "ClapTrap " << _name << " cannot be repaired because it's out of hit points!" << std::endl;
}
else if (_energyPoints <= 0)
{
std::cout << "ClapTrap " << _name << " is out of energy and cannot be repaired!" << std::endl;
}
}