67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
#include "ClapTrap.hpp"
|
|
|
|
ClapTrap::ClapTrap() {
|
|
this->name = "Default";
|
|
this->hp = 10;
|
|
this->energy = 10;
|
|
this->damage = 0;
|
|
std::cout << "ClapTrap " + this->name + " is created" << std::endl;
|
|
}
|
|
|
|
ClapTrap::ClapTrap(std::string name) {
|
|
this->name = name;
|
|
this->hp = 10;
|
|
this->energy = 10;
|
|
this->damage = 0;
|
|
std::cout << "ClapTrap " + this->name + " is created" << std::endl;
|
|
}
|
|
|
|
ClapTrap::ClapTrap(const ClapTrap &clap) {
|
|
*this = clap;
|
|
std::cout << "ClapTrap " + this->name + " is created" << std::endl;
|
|
}
|
|
|
|
ClapTrap::~ClapTrap() {
|
|
std::cout << "ClapTrap " + this->name + " is destroyed" << std::endl;
|
|
}
|
|
|
|
ClapTrap& ClapTrap::operator=(const ClapTrap &clap) {
|
|
if (this != &clap) {
|
|
this->name = clap.name;
|
|
this->hp = clap.hp;
|
|
this->energy = clap.energy;
|
|
this->damage = clap.damage;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
void ClapTrap::attack(const std::string& target) {
|
|
if (this->energy > 0 && this->hp > 0) {
|
|
std::cout << "ClapTrap " + this->name + " attacks " + target + ", causing "
|
|
<< this->damage << " points of damage! " << std::endl;
|
|
this->energy--;
|
|
}
|
|
else
|
|
std::cout << this->name + " is out of combat" << std::endl;
|
|
}
|
|
|
|
void ClapTrap::takeDamage(unsigned int amount) {
|
|
if (this->hp > 0) {
|
|
std::cout << this->name + " takes " << amount << " damages" << std::endl;
|
|
this->energy--;
|
|
this->hp -= amount;
|
|
}
|
|
else
|
|
std::cout << this->name + " is out of combat" << std::endl;
|
|
}
|
|
|
|
void ClapTrap::beRepaired(unsigned int amount) {
|
|
if (this->energy > 0 && this->hp > 0) {
|
|
std::cout << this->name + " is repaired by " << amount << std::endl;
|
|
this->energy--;
|
|
this->hp += amount;
|
|
}
|
|
else
|
|
std::cout << this->name + " is out of combat" << std::endl;
|
|
}
|