std::cout << "ClapTrap " << m_name << " has spawned.\n";
}
-ClapTrap::ClapTrap(const ClapTrap &other)
-{
- std::cout << "ClapTrap " << m_name << " has spawned.\n";
- *this = other;
-}
-
ClapTrap::~ClapTrap()
{
std::cout << "ClapTrap " << m_name << " has despawned.\n";
}
-ClapTrap &ClapTrap::operator=(const ClapTrap &other)
-{
- if (this == &other)
- return (*this);
- m_name = other.m_name;
- m_hp = other.m_hp;
- m_energy = other.m_energy;
- m_attack = other.m_attack;
- return (*this);
-}
-
void ClapTrap::attack(const std::string &target)
{
if (m_hp == 0)
unsigned int m_energy;
unsigned int m_attack;
- public:
- ClapTrap(std::string name = "DEFAULT");
+ ClapTrap();
ClapTrap(const ClapTrap &other);
- ~ClapTrap();
ClapTrap &operator=(const ClapTrap &other);
+ public:
+ ClapTrap(std::string name);
+ ~ClapTrap();
+
void attack(const std::string &target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
int main()
{
ClapTrap a("Alen");
- ClapTrap def;
+ ClapTrap b("Boris");
- def.attack("foo");
- def.takeDamage(9);
- def.takeDamage(0);
- def.beRepaired(6);
- def.takeDamage(5);
- def.takeDamage(1);
- def.takeDamage(1);
- def.takeDamage(1);
- def.attack("foo");
- def.beRepaired(10);
+ b.attack("foo");
+ b.takeDamage(9);
+ b.takeDamage(0);
+ b.beRepaired(6);
+ b.takeDamage(5);
+ b.takeDamage(1);
+ b.takeDamage(1);
+ b.takeDamage(1);
+ b.attack("foo");
+ b.beRepaired(10);
for (int i(0); i < 10; ++i)
a.attack("bar");
a.takeDamage(9);
std::cout << "ClapTrap " << m_name << " has spawned.\n";
}
-ClapTrap::ClapTrap(const ClapTrap &other)
-{
- std::cout << "ClapTrap " << m_name << " has spawned.\n";
- *this = other;
-}
-
ClapTrap::~ClapTrap()
{
std::cout << "ClapTrap " << m_name << " has despawned.\n";
}
-ClapTrap &ClapTrap::operator=(const ClapTrap &other)
-{
- if (this == &other)
- return (*this);
- m_name = other.m_name;
- m_hp = other.m_hp;
- m_energy = other.m_energy;
- m_attack = other.m_attack;
- return (*this);
-}
-
void ClapTrap::attack(const std::string &target)
{
if (m_hp == 0)
void ClapTrap::takeDamage(unsigned int amount)
{
if (m_hp == 0)
- std::cout << m_name <<
+ std::cout << "ClapTrap " << m_name <<
" is already dead and cannot be damaged further.\n";
else if (amount >= m_hp)
{
- std::cout << m_name
+ std::cout << "ClapTrap " << m_name
<< " takes " << amount << " damage and dies\n";
m_hp = 0;
}
else
{
- std::cout << m_name
+ std::cout << "ClapTrap " << m_name
<< " takes " << amount << " damage.\n";
m_hp -= amount;
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (m_hp == 0)
- std::cout << m_name
+ std::cout << "ClapTrap " << m_name
<< " is dead, hence cannot repair itself.\n";
else if (m_energy == 0)
- std::cout << m_name
+ std::cout << "ClapTrap " << m_name
<< " does not have enough energy to repair itself.\n";
else
{
- std::cout << m_name
+ std::cout << "ClapTrap " << m_name
<< " repairs iself for " << amount << " hit points.\n";
m_hp += amount;
}
unsigned int m_energy;
unsigned int m_attack;
- public:
- ClapTrap(std::string name = "DEFAULT");
+ ClapTrap();
ClapTrap(const ClapTrap &other);
- ~ClapTrap();
ClapTrap &operator=(const ClapTrap &other);
+ public:
+ ClapTrap(std::string name);
+ ~ClapTrap();
+
void attack(const std::string &target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
m_is_guarding = 0;
}
-ScavTrap::ScavTrap(const ScavTrap &other)
-{
- *this = other;
-}
-
ScavTrap::~ScavTrap()
{
std::cout << "ScavTrap " << m_name << " has despawned.\n";
}
-ScavTrap &ScavTrap::operator=(const ScavTrap &other)
-{
- if (this == &other)
- return (*this);
- ClapTrap::operator=(other);
- m_is_guarding = other.m_is_guarding;
- return (*this);
-}
-
void ScavTrap::attack(const std::string &target)
{
if (m_hp == 0)
private:
bool m_is_guarding;
- public:
- ScavTrap(std::string name = "DEFAULT");
+ ScavTrap();
ScavTrap(const ScavTrap &other);
- ~ScavTrap();
ScavTrap &operator=(const ScavTrap &other);
+ public:
+ ScavTrap(std::string name);
+ ~ScavTrap();
+
void attack(const std::string &target);
void guardGate();
};
int main()
{
- ScavTrap a("Alen");
- ClapTrap def;
+ ClapTrap a("Alen");
+ ScavTrap b("Boris");
- def.attack("foo");
- def.takeDamage(9);
- def.takeDamage(0);
- def.beRepaired(6);
- def.takeDamage(5);
- def.takeDamage(1);
- def.takeDamage(1);
- def.takeDamage(1);
- def.attack("foo");
- def.beRepaired(10);
+ b.attack("foo");
+ b.takeDamage(9);
+ b.takeDamage(0);
+ b.beRepaired(6);
+ b.takeDamage(5);
+ b.takeDamage(1);
+ b.takeDamage(1);
+ b.takeDamage(1);
+ b.attack("foo");
+ b.beRepaired(10);
for (int i(0); i < 50; ++i)
a.attack("bar");
a.takeDamage(9);
std::cout << "ClapTrap " << m_name << " has spawned.\n";
}
-ClapTrap::ClapTrap(const ClapTrap &other)
-{
- std::cout << "ClapTrap " << m_name << " has spawned.\n";
- *this = other;
-}
-
ClapTrap::~ClapTrap()
{
std::cout << "ClapTrap " << m_name << " has despawned.\n";
}
-ClapTrap &ClapTrap::operator=(const ClapTrap &other)
-{
- if (this == &other)
- return (*this);
- m_name = other.m_name;
- m_hp = other.m_hp;
- m_energy = other.m_energy;
- m_attack = other.m_attack;
- return (*this);
-}
-
void ClapTrap::attack(const std::string &target)
{
if (m_hp == 0)
void ClapTrap::takeDamage(unsigned int amount)
{
if (m_hp == 0)
- std::cout << m_name <<
+ std::cout << "ClapTrap " << m_name <<
" is already dead and cannot be damaged further.\n";
else if (amount >= m_hp)
{
- std::cout << m_name
+ std::cout << "ClapTrap " << m_name
<< " takes " << amount << " damage and dies\n";
m_hp = 0;
}
else
{
- std::cout << m_name
+ std::cout << "ClapTrap " << m_name
<< " takes " << amount << " damage.\n";
m_hp -= amount;
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (m_hp == 0)
- std::cout << m_name
+ std::cout << "ClapTrap " << m_name
<< " is dead, hence cannot repair itself.\n";
else if (m_energy == 0)
- std::cout << m_name
+ std::cout << "ClapTrap " << m_name
<< " does not have enough energy to repair itself.\n";
else
{
- std::cout << m_name
+ std::cout << "ClapTrap " << m_name
<< " repairs iself for " << amount << " hit points.\n";
m_hp += amount;
}
unsigned int m_energy;
unsigned int m_attack;
- public:
- ClapTrap(std::string name = "DEFAULT");
+ ClapTrap();
ClapTrap(const ClapTrap &other);
- ~ClapTrap();
ClapTrap &operator=(const ClapTrap &other);
+ public:
+ ClapTrap(std::string name);
+ ~ClapTrap();
+
void attack(const std::string &target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
m_is_guarding = 0;
}
-FragTrap::FragTrap(const FragTrap &other)
-{
- *this = other;
-}
-
FragTrap::~FragTrap()
{
std::cout << "FragTrap " << m_name << " has despawned.\n";
}
-FragTrap &FragTrap::operator=(const FragTrap &other)
-{
- if (this == &other)
- return (*this);
- ClapTrap::operator=(other);
- m_is_guarding = other.m_is_guarding;
- return (*this);
-}
-
void FragTrap::attack(const std::string &target)
{
if (m_hp == 0)
private:
bool m_is_guarding;
- public:
- FragTrap(std::string name = "DEFAULT");
+ FragTrap();
FragTrap(const FragTrap &other);
- ~FragTrap();
FragTrap &operator=(const FragTrap &other);
+ public:
+ FragTrap(std::string name);
+ ~FragTrap();
+
+
void attack(const std::string &target);
void highFivesGuys();
};
m_is_guarding = 0;
}
-ScavTrap::ScavTrap(const ScavTrap &other)
-{
- *this = other;
-}
-
ScavTrap::~ScavTrap()
{
std::cout << "ScavTrap " << m_name << " has despawned.\n";
}
-ScavTrap &ScavTrap::operator=(const ScavTrap &other)
-{
- if (this == &other)
- return (*this);
- ClapTrap::operator=(other);
- m_is_guarding = other.m_is_guarding;
- return (*this);
-}
-
void ScavTrap::attack(const std::string &target)
{
if (m_hp == 0)
private:
bool m_is_guarding;
- public:
- ScavTrap(std::string name = "DEFAULT");
+ ScavTrap();
ScavTrap(const ScavTrap &other);
- ~ScavTrap();
ScavTrap &operator=(const ScavTrap &other);
+ public:
+ ScavTrap(std::string name);
+ ~ScavTrap();
+
void attack(const std::string &target);
void guardGate();
};
int main()
{
- ScavTrap a("Alen");
- ClapTrap def;
- FragTrap b("Glenn");
+ ClapTrap a("Alen");
+ ScavTrap b("Boris");
+ FragTrap c("Charles");
- def.attack("foo");
- def.takeDamage(9);
- def.takeDamage(0);
- def.beRepaired(6);
- def.takeDamage(5);
- def.takeDamage(1);
- def.takeDamage(1);
- def.takeDamage(1);
- def.attack("foo");
- def.beRepaired(10);
+ a.attack("foo");
a.takeDamage(9);
- a.guardGate();
- a.guardGate();
- a.attack("bar");
- a.beRepaired(1);
- a.takeDamage(100);
+ a.takeDamage(0);
+ a.beRepaired(6);
+ a.takeDamage(5);
a.takeDamage(1);
- a.guardGate();
- a.attack("bar");
- a.beRepaired(1);
- b.highFivesGuys();
+ a.takeDamage(1);
+ a.takeDamage(1);
+ a.attack("foo");
+ a.beRepaired(10);
+ b.takeDamage(9);
+ b.guardGate();
+ b.guardGate();
+ b.attack("bar");
+ b.beRepaired(1);
+ b.takeDamage(100);
+ b.takeDamage(1);
+ b.guardGate();
+ b.attack("bar");
+ b.beRepaired(1);
+ c.highFivesGuys();
return (0);
}