-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClapTrap.cpp
More file actions
89 lines (71 loc) · 2.75 KB
/
Copy pathClapTrap.cpp
File metadata and controls
89 lines (71 loc) · 2.75 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ClapTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dpoveda- <me@izenynn.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/16 00:22:05 by dpoveda- #+# #+# */
/* Updated: 2022/02/16 03:00:37 by dpoveda- ### ########.fr */
/* */
/* ************************************************************************** */
#include "ClapTrap.hpp"
#include <iostream>
ClapTrap::ClapTrap()
: _name("ScavTrap")
, _hitPoints(10)
, _energyPoints(10)
, _attackDamage(0) {
std::cout << this->_name << " ClapTrap created" << std::endl;
}
ClapTrap::ClapTrap(std::string name)
: _name(name)
, _hitPoints(10)
, _energyPoints(10)
, _attackDamage(0) {
std::cout << this->_name << " ClapTrap created" << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap& other) {
*this = other;
std::cout << this->_name << " ClapTrap copy created" << std::endl;
}
ClapTrap::~ClapTrap() {
std::cout << this->_name << " ClapTrap destroyed" << std::endl;
}
ClapTrap& ClapTrap::operator=(const ClapTrap& other) {
this->_name = other._name;
this->_hitPoints = other._hitPoints;
this->_energyPoints = other._energyPoints;
this->_attackDamage = other._attackDamage;
std::cout << this->_name << " ClapTrap = " << other._name << std::endl;
return *this;
}
void ClapTrap::attack(const std::string &target) const {
if (this->_hitPoints == 0) {
std::cout << this->_name << " ClapTrap can't attack because is dead" << std::endl;
return;
}
std::cout
<< this->_name << " ClapTrap attack " << target
<< ", causing " << this->_attackDamage << " damage"
<< std::endl;
}
void ClapTrap::takeDamage(unsigned int amount) {
if (this->_hitPoints == 0) {
std::cout << this->_name << " ClapTrap can't take damage because is dead" << std::endl;
return;
}
if (amount > this->_hitPoints) {
amount = this->_hitPoints;
}
this->_hitPoints -= amount;
std::cout << this->_name << " ClapTrap has taken " << amount << " damage" << std::endl;
}
void ClapTrap::beRepaired(unsigned int amount) {
if (this->_hitPoints == 0) {
std::cout << this->_name << " ClapTrap can't be repaired because is dead" << std::endl;
return;
}
this->_hitPoints += amount;
std::cout << this->_name << " ClapTrap has repaired " << amount << " hit points" << std::endl;
}