96 lines
3.2 KiB
C++
96 lines
3.2 KiB
C++
#include "FragTrap.hpp"
|
|
#include "ClapTrap.hpp"
|
|
#include <iostream>
|
|
|
|
FragTrap::FragTrap() : ClapTrap()
|
|
{
|
|
}
|
|
|
|
FragTrap::FragTrap(std::string name) : ClapTrap(name)
|
|
{
|
|
_hitpoints = 100;
|
|
_energy_points = 100;
|
|
_attack_damage = 30;
|
|
|
|
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
|
}
|
|
FragTrap::FragTrap(FragTrap const &src) : ClapTrap(src)
|
|
{
|
|
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created by copy constructor" << std::endl;
|
|
}
|
|
|
|
FragTrap::~FragTrap()
|
|
{
|
|
status();
|
|
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
|
}
|
|
|
|
FragTrap &FragTrap::operator=(FragTrap const &other)
|
|
{
|
|
if (this == &other)
|
|
return (*this);
|
|
|
|
_name = other._name;
|
|
_hitpoints = other._hitpoints;
|
|
_energy_points = other._energy_points;
|
|
_attack_damage = other._attack_damage;
|
|
|
|
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created by assignation operator" << std::endl;
|
|
|
|
return (*this);
|
|
}
|
|
|
|
void FragTrap::highFivesGuys(void)
|
|
{
|
|
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " common guys lets do high fives!!" << std::endl;
|
|
}
|
|
|
|
void FragTrap::status(void) const
|
|
{
|
|
std::cout << COLOR14 << "FragTrap " << COLOR10 << _name << " has " << _hitpoints
|
|
<< " hitpoints, " << _energy_points << " energy points and "
|
|
<< _attack_damage << " attack damage." << std::endl;
|
|
}
|
|
|
|
void fragtrap_test()
|
|
{
|
|
std::cout << BOLD_UNDERLINE << COLOR9 << "FragTrap tests" << COLOR_RESET << std::endl;
|
|
std::cout << std::endl;
|
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
|
std::cout << BOLD_UNDERLINE << COLOR10 << "FragTrap Charlie with parameter constructor" << COLOR_RESET << std::endl;
|
|
FragTrap charlie("Charlie");
|
|
std::cout << std::endl;
|
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Fragtrap charlie_copy with copy constructor of Charlie" << COLOR_RESET << std::endl;
|
|
FragTrap charlie_copy(charlie);
|
|
std::cout << std::endl;
|
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_fragtrap with default constructor" << COLOR_RESET << std::endl;
|
|
FragTrap default_fragtrap;
|
|
std::cout << std::endl;
|
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_fragtrap = charlie" << COLOR_RESET << std::endl;
|
|
default_fragtrap = charlie;
|
|
std::cout << std::endl;
|
|
|
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: charlie" << COLOR_RESET << std::endl;
|
|
charlie.attack("enemy");
|
|
charlie.takeDamage(5);
|
|
charlie.beRepaired(3);
|
|
std::cout << std::endl;
|
|
|
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: charlie_copy" << COLOR_RESET << std::endl;
|
|
charlie_copy.attack("enemy");
|
|
charlie_copy.takeDamage(15);
|
|
charlie_copy.attack("the sun");
|
|
for (int i = 0; i < 10; i++)
|
|
charlie_copy.beRepaired(1);
|
|
charlie_copy.attack("the moon");
|
|
charlie_copy.highFivesGuys();
|
|
std::cout << std::endl;
|
|
|
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: default_fragtrap" << COLOR_RESET << std::endl;
|
|
default_fragtrap.attack("enemy");
|
|
default_fragtrap.takeDamage(5);
|
|
default_fragtrap.highFivesGuys();
|
|
std::cout << std::endl;
|
|
|
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
|
} |