Skip to content

Commit

Permalink
upd: DiamondTrap
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuno Miguel Nuno Carvalho committed Aug 30, 2023
1 parent 1e3a3d4 commit 76b96a1
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 25 deletions.
1 change: 1 addition & 0 deletions lvl_4_5_cpp_modules/CPP03/ex03/includes/ClapTrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ClapTrap {
void attack(const std::string& target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);

protected:
std::string name;
unsigned int hit_points;
Expand Down
4 changes: 4 additions & 0 deletions lvl_4_5_cpp_modules/CPP03/ex03/includes/FragTrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class FragTrap : virtual public ClapTrap
~FragTrap(void);

void highFivesGuys(void);

static const int defaultHitPoints = 100;
static const int defaultEnergyPoints = 100;
static const int defaultAttackDamage = 30;
};

#endif // FRAGTRAP_HPP
4 changes: 4 additions & 0 deletions lvl_4_5_cpp_modules/CPP03/ex03/includes/ScavTrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class ScavTrap : virtual public ClapTrap

void attack(const std::string& target);
void guardGate(void);

static const int defaultHitPoints = 100;
static const int defaultEnergyPoints = 50;
static const int defaultAttackDamage = 20;
};

#endif // SCAVTRAP_HPP
3 changes: 2 additions & 1 deletion lvl_4_5_cpp_modules/CPP03/ex03/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using std::endl;
int main(void)
{
DiamondTrap Bozo("Bozo");
/* DiamondTrap Bozo("Bozo");
DiamondTrap Rato("Rato");
DiamondTrap Clone;
Expand Down Expand Up @@ -50,5 +51,5 @@ int main(void)
cout << endl;
return EXIT_SUCCESS;
return EXIT_SUCCESS; */
}
6 changes: 3 additions & 3 deletions lvl_4_5_cpp_modules/CPP03/ex03/srcs/DiamondTrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ DiamondTrap::DiamondTrap(std::string name)
: ClapTrap(name + "_clap_name"), FragTrap(name), ScavTrap(name)
{
this->name = name;
this->hit_points = FragTrap::hit_points;
this->energy_points = ScavTrap::energy_points;
this->attack_damage = FragTrap::attack_damage;
this->hit_points = FragTrap::defaultHitPoints;
this->energy_points = ScavTrap::defaultEnergyPoints;
this->attack_damage = FragTrap::defaultAttackDamage;

cout << "Sub Class (DiamondTrap) constructor has been called" << endl;
}
Expand Down
25 changes: 14 additions & 11 deletions lvl_4_5_cpp_modules/CPP03/ex03/srcs/FragTrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@
using std::cout;
using std::endl;

FragTrap::FragTrap(void) : ClapTrap() {};
FragTrap::FragTrap(void) : ClapTrap(){};

FragTrap::FragTrap(std::string name) : ClapTrap(name)
{
this->hit_points = 100;
this->energy_points = 100;
this->attack_damage = 30;
this->hit_points = this->defaultHitPoints;
this->energy_points = this->defaultEnergyPoints;
this->attack_damage = this->defaultAttackDamage;
cout << "Sub Class (FragTrap) constructor has been called" << endl;
}

FragTrap::~FragTrap(void) {
FragTrap::~FragTrap(void)
{
cout << "Sub Class (FragTrap) destructor has been called" << endl;
}

void FragTrap::highFivesGuys(void) {
if (this->energy_points == 0) {
cout << "FragTrap "<< this->name << " is out of energy points!" << endl;
return;
}
void FragTrap::highFivesGuys(void)
{
if (this->energy_points == 0)
{
cout << "FragTrap " << this->name << " is out of energy points!" << endl;
return;
}
cout << "FragTrap " << this->name << " says: High Fives!" << endl;
this->energy_points -= 1;
this->energy_points -= 1;
}
22 changes: 12 additions & 10 deletions lvl_4_5_cpp_modules/CPP03/ex03/srcs/ScavTrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,36 @@
using std::cout;
using std::endl;

ScavTrap::ScavTrap(void) {};
ScavTrap::ScavTrap(void){};

ScavTrap::ScavTrap(std::string name) : ClapTrap(name)
{
this->hit_points = 100;
this->energy_points = 50;
this->attack_damage = 20;
this->hit_points = this->defaultHitPoints;
this->energy_points = this->defaultEnergyPoints;
this->attack_damage = this->defaultAttackDamage;
cout << "Sub Class (ScavTrap) constructor has been called" << endl;
}

ScavTrap::~ScavTrap(void) {
ScavTrap::~ScavTrap(void)
{
cout << "Sub Class (ScavTrap) destructor has been called" << endl;
}

void ScavTrap::attack(const std::string& target)
void ScavTrap::attack(const std::string &target)
{
if (this->energy_points == 0)
{
cout << "ScavTrap is out of energy points!" << endl;
return;
}
cout << "ScavTrap " << this->name
<< " attacks " << target
<< " causing <amount> "
<< "points of damage!" << endl;
<< " attacks " << target
<< " causing <amount> "
<< "points of damage!" << endl;
this->energy_points -= 1;
}

void ScavTrap::guardGate(void) {
void ScavTrap::guardGate(void)
{
cout << "ScavTrap " << this->name << " is now in gate keeper mode" << endl;
}

0 comments on commit 76b96a1

Please sign in to comment.