made diamondTrap and made some colors
This commit is contained in:
parent
e2d4f0a731
commit
d11f1bd317
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/27 16:26:32 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/27 16:29:00 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/04/07 15:35:26 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,6 +14,26 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#define COLOR0 "\033[38;5;0m"
|
||||
#define COLOR1 "\033[38;5;1m"
|
||||
#define COLOR2 "\033[38;5;2m"
|
||||
#define COLOR3 "\033[38;5;3m"
|
||||
#define COLOR4 "\033[38;5;4m"
|
||||
#define COLOR5 "\033[38;5;5m"
|
||||
#define COLOR6 "\033[38;5;6m"
|
||||
#define COLOR7 "\033[38;5;7m"
|
||||
#define COLOR8 "\033[38;5;8m"
|
||||
#define COLOR9 "\033[38;5;9m"
|
||||
#define COLOR10 "\033[38;5;10m"
|
||||
#define COLOR11 "\033[38;5;11m"
|
||||
#define COLOR12 "\033[38;5;12m"
|
||||
#define COLOR13 "\033[38;5;13m"
|
||||
#define COLOR14 "\033[38;5;14m"
|
||||
#define COLOR15 "\033[38;5;15m"
|
||||
#define COLOR_RESET "\033[m"
|
||||
|
||||
|
||||
|
||||
class ClapTrap
|
||||
{
|
||||
private:
|
||||
@ -30,6 +50,7 @@ public:
|
||||
|
||||
ClapTrap &operator=(ClapTrap const &rhs);
|
||||
|
||||
void status() const;
|
||||
void attack(std::string const &target);
|
||||
void takeDamage(unsigned int amount);
|
||||
void beRepaired(unsigned int amount);
|
||||
|
||||
@ -1,37 +1,30 @@
|
||||
#include "ClapTrap.hpp"
|
||||
#include <iostream>
|
||||
|
||||
ClapTrap::ClapTrap()
|
||||
ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0)
|
||||
{
|
||||
std::cout << "A nameless ClapTrap is created!" << std::endl;
|
||||
_name = "a Nameless ClapTrap";
|
||||
_hitpoints = 10;
|
||||
_energy_points = 10;
|
||||
_attack_damage = 0;
|
||||
_name = "Noname";
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap::ClapTrap(std::string name)
|
||||
ClapTrap::ClapTrap(std::string name) : _name(name), _hitpoints(10), _energy_points(10), _attack_damage(0)
|
||||
{
|
||||
std::cout << "ClapTrap " << name << " is created!" << std::endl;
|
||||
_name = name;
|
||||
_hitpoints = 10;
|
||||
_energy_points = 10;
|
||||
_attack_damage = 0;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << name << " is created!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap::ClapTrap(ClapTrap const &src)
|
||||
{
|
||||
std::cout << "ClapTrap " << src._name << " is copied!" << std::endl;
|
||||
_name = src._name;
|
||||
_hitpoints = src._hitpoints;
|
||||
_energy_points = src._energy_points;
|
||||
_attack_damage = src._attack_damage;
|
||||
|
||||
*this = src;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is copied!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap::~ClapTrap()
|
||||
{
|
||||
std::cout << "ClapTrap " << _name << " is destroyed!" << std::endl;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap &ClapTrap::operator=(ClapTrap const &rhs)
|
||||
@ -39,11 +32,14 @@ ClapTrap &ClapTrap::operator=(ClapTrap const &rhs)
|
||||
if (this == &rhs)
|
||||
return *this;
|
||||
|
||||
std::cout << "ClapTrap " << rhs._name << " is assigned to ClapTrap formely known as " << _name << "!" << std::endl;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << rhs._name
|
||||
<< " is assigned to ClapTrap formely known as " << _name << "!"
|
||||
<< std::endl;
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
status();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -51,27 +47,47 @@ void ClapTrap::attack(std::string const &target)
|
||||
{
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << "ClapTrap " << _name << " is too tired to attack!" << std::endl;
|
||||
return ;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR9 << _name << " is too tired to attack!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
if (_hitpoints < 1)
|
||||
{
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR9 << _name << " should be repaired before it can attack!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
_energy_points -= 1;
|
||||
std::cout << "ClapTrap " << _name << " attacks " << target << ", causing " << _attack_damage << " points of damage!" << std::endl;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " attacks " << target << ", causing "
|
||||
<< _attack_damage << " points of damage!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
void ClapTrap::takeDamage(unsigned int amount)
|
||||
{
|
||||
_hitpoints -= amount;
|
||||
std::cout << "ClapTrap " << _name << " takes " << amount << " points of damage!" << std::endl;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " takes " << amount
|
||||
<< " points of damage!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
void ClapTrap::beRepaired(unsigned int amount)
|
||||
{
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << "ClapTrap " << _name << " is too tired to repair!" << std::endl;
|
||||
return ;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR9 << _name << " is too tired to repair!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
_hitpoints += amount;
|
||||
_energy_points -= 1;
|
||||
std::cout << "ClapTrap " << _name << " is repaired for " << amount << " points!" << std::endl;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is repaired for " << amount
|
||||
<< " points!" << std::endl;
|
||||
status();
|
||||
}
|
||||
void ClapTrap::status() const
|
||||
{
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR10 << _name << " has " << _hitpoints << " hitpoints, "
|
||||
<< _energy_points << " energy points and " << _attack_damage
|
||||
<< " attack damage!" << COLOR_RESET << std::endl;
|
||||
}
|
||||
|
||||
@ -6,34 +6,55 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/27 16:56:23 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/27 17:02:31 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/04/07 15:45:50 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ClapTrap.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
||||
std::cout << COLOR10 << "claptrap with parameter constructor" << COLOR_RESET << std::endl;
|
||||
ClapTrap claptrap("Rudolph");
|
||||
std::cout << COLOR10 << "claptrap2 with copy constructor" << COLOR_RESET << std::endl;
|
||||
ClapTrap claptrap2(claptrap);
|
||||
std::cout << COLOR10 << "Claptrap3 with default constructor" << COLOR_RESET << std::endl;
|
||||
ClapTrap claptrap3;
|
||||
std::cout << COLOR10 << "claptrap3 = claptrap" << COLOR_RESET << std::endl;
|
||||
claptrap3 = claptrap;
|
||||
std::cout << COLOR10 << "claptrap4 with parameter constructor" << COLOR_RESET << std::endl;
|
||||
ClapTrap claptrap4("Eduard");
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap" << COLOR_RESET << std::endl;
|
||||
claptrap.attack("enemy");
|
||||
claptrap.takeDamage(5);
|
||||
claptrap.beRepaired(3);
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap2" << COLOR_RESET << std::endl;
|
||||
claptrap2.attack("enemy");
|
||||
claptrap2.takeDamage(5);
|
||||
claptrap2.beRepaired(3);
|
||||
claptrap2.takeDamage(15);
|
||||
claptrap2.attack("the sun");
|
||||
for(int i = 0; i < 10; i++)
|
||||
claptrap2.beRepaired(1);
|
||||
claptrap2.attack("the moon");
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap3" << COLOR_RESET << std::endl;
|
||||
claptrap3.attack("enemy");
|
||||
claptrap3.takeDamage(5);
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap4" << COLOR_RESET << std::endl;
|
||||
claptrap4.attack("itself");
|
||||
claptrap4.takeDamage(5);
|
||||
claptrap4.beRepaired(4);
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/27 16:26:32 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 11:35:08 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/04/07 15:49:00 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,6 +14,26 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#define COLOR0 "\033[38;5;0m"
|
||||
#define COLOR1 "\033[38;5;1m"
|
||||
#define COLOR2 "\033[38;5;2m"
|
||||
#define COLOR3 "\033[38;5;3m"
|
||||
#define COLOR4 "\033[38;5;4m"
|
||||
#define COLOR5 "\033[38;5;5m"
|
||||
#define COLOR6 "\033[38;5;6m"
|
||||
#define COLOR7 "\033[38;5;7m"
|
||||
#define COLOR8 "\033[38;5;8m"
|
||||
#define COLOR9 "\033[38;5;9m"
|
||||
#define COLOR10 "\033[38;5;10m"
|
||||
#define COLOR11 "\033[38;5;11m"
|
||||
#define COLOR12 "\033[38;5;12m"
|
||||
#define COLOR13 "\033[38;5;13m"
|
||||
#define COLOR14 "\033[38;5;14m"
|
||||
#define COLOR15 "\033[38;5;15m"
|
||||
#define COLOR_RESET "\033[m"
|
||||
|
||||
|
||||
|
||||
class ClapTrap
|
||||
{
|
||||
protected:
|
||||
@ -30,6 +50,7 @@ public:
|
||||
|
||||
ClapTrap &operator=(ClapTrap const &rhs);
|
||||
|
||||
void status() const;
|
||||
void attack(std::string const &target);
|
||||
void takeDamage(unsigned int amount);
|
||||
void beRepaired(unsigned int amount);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 11:28:29 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 11:54:16 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/04/07 16:19:46 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -30,4 +30,5 @@ public:
|
||||
|
||||
void attack(std::string const &target);
|
||||
void guardGate();
|
||||
void status() const;
|
||||
};
|
||||
@ -1,38 +1,30 @@
|
||||
#include "ClapTrap.hpp"
|
||||
#include <iostream>
|
||||
|
||||
ClapTrap::ClapTrap()
|
||||
ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0)
|
||||
{
|
||||
_name = "a Nameless ClapTrap";
|
||||
_hitpoints = 10;
|
||||
_energy_points = 10;
|
||||
_attack_damage = 0;
|
||||
|
||||
std::cout << "ClapTrap:: " << _name <<" is created!" << std::endl;
|
||||
_name = "Noname";
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap::ClapTrap(std::string name)
|
||||
ClapTrap::ClapTrap(std::string name) : _name(name), _hitpoints(10), _energy_points(10), _attack_damage(0)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << name << " is created!" << std::endl;
|
||||
_name = name;
|
||||
_hitpoints = 10;
|
||||
_energy_points = 10;
|
||||
_attack_damage = 0;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << name << " is created!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap::ClapTrap(ClapTrap const &src)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << src._name << " is copied!" << std::endl;
|
||||
_name = src._name;
|
||||
_hitpoints = src._hitpoints;
|
||||
_energy_points = src._energy_points;
|
||||
_attack_damage = src._attack_damage;
|
||||
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is copied!" << std::endl;
|
||||
*this = src;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap::~ClapTrap()
|
||||
{
|
||||
std::cout << "ClapTrap:: " << _name << " is destroyed!" << std::endl;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap &ClapTrap::operator=(ClapTrap const &rhs)
|
||||
@ -40,11 +32,14 @@ ClapTrap &ClapTrap::operator=(ClapTrap const &rhs)
|
||||
if (this == &rhs)
|
||||
return *this;
|
||||
|
||||
std::cout << "ClapTrap:: " << rhs._name << " is assigned to ClapTrap formely known as " << _name << "!" << std::endl;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << rhs._name
|
||||
<< " is assigned to ClapTrap formely known as " << _name << "!"
|
||||
<< std::endl;
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
status();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -52,27 +47,47 @@ void ClapTrap::attack(std::string const &target)
|
||||
{
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << _name << " is too tired to attack!" << std::endl;
|
||||
return ;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR9 << _name << " is too tired to attack!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
if (_hitpoints < 1)
|
||||
{
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR9 << _name << " should be repaired before it can attack!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
_energy_points -= 1;
|
||||
std::cout << "ClapTrap:: " << _name << " attacks " << target << ", causing " << _attack_damage << " points of damage!" << std::endl;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " attacks " << target << ", causing "
|
||||
<< _attack_damage << " points of damage!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
void ClapTrap::takeDamage(unsigned int amount)
|
||||
{
|
||||
_hitpoints -= amount;
|
||||
std::cout << "ClapTrap:: " << _name << " takes " << amount << " points of damage!" << std::endl;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " takes " << amount
|
||||
<< " points of damage!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
void ClapTrap::beRepaired(unsigned int amount)
|
||||
{
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << _name << " is too tired to repair!" << std::endl;
|
||||
return ;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR9 << _name << " is too tired to repair!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
_hitpoints += amount;
|
||||
_energy_points -= 1;
|
||||
std::cout << "ClapTrap:: " << _name << " is repaired for " << amount << " points!" << std::endl;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is repaired for " << amount
|
||||
<< " points!" << std::endl;
|
||||
status();
|
||||
}
|
||||
void ClapTrap::status() const
|
||||
{
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR10 << _name << " has " << _hitpoints << " hitpoints, "
|
||||
<< _energy_points << " energy points and " << _attack_damage
|
||||
<< " attack damage!" << COLOR_RESET << std::endl;
|
||||
}
|
||||
|
||||
@ -6,65 +6,88 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 11:32:48 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 11:56:03 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/04/07 16:21:49 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include "ClapTrap.hpp"
|
||||
#include "ScavTrap.hpp"
|
||||
|
||||
ScavTrap::ScavTrap() : ClapTrap()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ScavTrap::ScavTrap(std::string name) : ClapTrap(name), _guard_mode(false)
|
||||
ScavTrap::ScavTrap() : ClapTrap(), _guard_mode(false)
|
||||
{
|
||||
_hitpoints = 100;
|
||||
_energy_points = 50;
|
||||
_attack_damage = 20;
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " has been created" << std::endl;
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||
}
|
||||
|
||||
ScavTrap::ScavTrap(std::string name) : ClapTrap(name), _guard_mode(false)
|
||||
{
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||
}
|
||||
|
||||
ScavTrap::ScavTrap(ScavTrap const &src) : ClapTrap(src)
|
||||
{
|
||||
*this = src;
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " has been created by copy constructor" << std::endl;
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created by copy constructor" << std::endl;
|
||||
}
|
||||
|
||||
ScavTrap::~ScavTrap()
|
||||
{
|
||||
std::cout << "ScavTrap:: " << _name << " has been destroyed" << std::endl;
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
||||
}
|
||||
|
||||
ScavTrap &ScavTrap::operator=(ScavTrap const &rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
}
|
||||
if (this == &rhs)
|
||||
return (*this);
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " has been created by assignation operator" << std::endl;
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created by assignment operator" << std::endl;
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void ScavTrap::attack(std::string const &target)
|
||||
{
|
||||
std::cout << "ScavTrap:: " << _name << " attack " << target << ", causing " << _attack_damage << " points of damage!" << std::endl;
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << COLOR13 << "ScavTrap " << COLOR9 << _name << " is too tired to attack!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
if (_hitpoints < 1)
|
||||
{
|
||||
std::cout << COLOR13 << "ScavTrap " << COLOR9 << _name << " should be repaired before it can attack!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
_energy_points -= 1;
|
||||
std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " attacks " << target << " without weapon, causing "
|
||||
<< _attack_damage << " points of damage!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
|
||||
void ScavTrap::guardGate()
|
||||
{
|
||||
_guard_mode = true;
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " in Gate keeper mode" << std::endl;
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " is in Gate keeper mode" << std::endl;
|
||||
}
|
||||
|
||||
void ScavTrap::status() const
|
||||
{
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR10 << _name << " has " << _hitpoints << " hitpoints, "
|
||||
<< _energy_points << " energy points, " << _attack_damage << " attack damage ";
|
||||
if (_guard_mode)
|
||||
std::cout << "and is in Gate keeper mode" << COLOR_RESET << std::endl;
|
||||
else
|
||||
std::cout << "and is not in Gate keeper mode" << COLOR_RESET << std::endl;
|
||||
}
|
||||
@ -6,20 +6,69 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 11:35:59 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 11:36:16 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/04/07 16:22:19 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <iostream>
|
||||
#include "ClapTrap.hpp"
|
||||
#include "ScavTrap.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
ScavTrap scav("ScavTrap");
|
||||
std::cout << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
||||
std::cout << COLOR10 << "claptrap with parameter constructor" << COLOR_RESET << std::endl;
|
||||
ScavTrap claptrap("Rudolph");
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "claptrap2 with copy constructor" << COLOR_RESET << std::endl;
|
||||
ScavTrap claptrap2(claptrap);
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "Claptrap3 with default constructor" << COLOR_RESET << std::endl;
|
||||
ScavTrap claptrap3;
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "claptrap3 = claptrap" << COLOR_RESET << std::endl;
|
||||
claptrap3 = claptrap;
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "claptrap4 with parameter constructor" << COLOR_RESET << std::endl;
|
||||
ScavTrap claptrap4("Eduard");
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap" << COLOR_RESET << std::endl;
|
||||
claptrap.attack("enemy");
|
||||
claptrap.takeDamage(5);
|
||||
claptrap.beRepaired(3);
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap2" << COLOR_RESET << std::endl;
|
||||
claptrap2.attack("enemy");
|
||||
claptrap2.takeDamage(15);
|
||||
claptrap2.attack("the sun");
|
||||
for(int i = 0; i < 10; i++)
|
||||
claptrap2.beRepaired(1);
|
||||
claptrap2.attack("the moon");
|
||||
claptrap2.guardGate();
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap3" << COLOR_RESET << std::endl;
|
||||
claptrap3.attack("enemy");
|
||||
claptrap3.takeDamage(5);
|
||||
claptrap3.guardGate();
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap4" << COLOR_RESET << std::endl;
|
||||
claptrap4.attack("itself");
|
||||
claptrap4.takeDamage(5);
|
||||
claptrap4.beRepaired(4);
|
||||
claptrap4.guardGate();
|
||||
claptrap4.attack("enemy");
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
||||
|
||||
scav.attack("target");
|
||||
scav.takeDamage(10);
|
||||
scav.beRepaired(5);
|
||||
scav.guardGate();
|
||||
return (0);
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/27 16:26:32 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 11:35:08 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/04/07 15:49:00 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,6 +14,26 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#define COLOR0 "\033[38;5;0m"
|
||||
#define COLOR1 "\033[38;5;1m"
|
||||
#define COLOR2 "\033[38;5;2m"
|
||||
#define COLOR3 "\033[38;5;3m"
|
||||
#define COLOR4 "\033[38;5;4m"
|
||||
#define COLOR5 "\033[38;5;5m"
|
||||
#define COLOR6 "\033[38;5;6m"
|
||||
#define COLOR7 "\033[38;5;7m"
|
||||
#define COLOR8 "\033[38;5;8m"
|
||||
#define COLOR9 "\033[38;5;9m"
|
||||
#define COLOR10 "\033[38;5;10m"
|
||||
#define COLOR11 "\033[38;5;11m"
|
||||
#define COLOR12 "\033[38;5;12m"
|
||||
#define COLOR13 "\033[38;5;13m"
|
||||
#define COLOR14 "\033[38;5;14m"
|
||||
#define COLOR15 "\033[38;5;15m"
|
||||
#define COLOR_RESET "\033[m"
|
||||
|
||||
|
||||
|
||||
class ClapTrap
|
||||
{
|
||||
protected:
|
||||
@ -30,6 +50,7 @@ public:
|
||||
|
||||
ClapTrap &operator=(ClapTrap const &rhs);
|
||||
|
||||
void status() const;
|
||||
void attack(std::string const &target);
|
||||
void takeDamage(unsigned int amount);
|
||||
void beRepaired(unsigned int amount);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 15:44:08 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 15:46:21 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/04/07 17:26:42 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -26,4 +26,5 @@ public:
|
||||
FragTrap &operator=(FragTrap const &rhs);
|
||||
|
||||
void highFivesGuys(void);
|
||||
void status(void) const;
|
||||
};
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 11:28:29 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 11:54:16 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/04/07 16:19:46 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -30,4 +30,5 @@ public:
|
||||
|
||||
void attack(std::string const &target);
|
||||
void guardGate();
|
||||
void status() const;
|
||||
};
|
||||
@ -1,38 +1,30 @@
|
||||
#include "ClapTrap.hpp"
|
||||
#include <iostream>
|
||||
|
||||
ClapTrap::ClapTrap()
|
||||
ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0)
|
||||
{
|
||||
_name = "a Nameless ClapTrap";
|
||||
_hitpoints = 10;
|
||||
_energy_points = 10;
|
||||
_attack_damage = 0;
|
||||
|
||||
std::cout << "ClapTrap:: " << _name <<" is created!" << std::endl;
|
||||
_name = "Noname";
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap::ClapTrap(std::string name)
|
||||
ClapTrap::ClapTrap(std::string name) : _name(name), _hitpoints(10), _energy_points(10), _attack_damage(0)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << name << " is created!" << std::endl;
|
||||
_name = name;
|
||||
_hitpoints = 10;
|
||||
_energy_points = 10;
|
||||
_attack_damage = 0;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << name << " is created!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap::ClapTrap(ClapTrap const &src)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << src._name << " is copied!" << std::endl;
|
||||
_name = src._name;
|
||||
_hitpoints = src._hitpoints;
|
||||
_energy_points = src._energy_points;
|
||||
_attack_damage = src._attack_damage;
|
||||
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is copied!" << std::endl;
|
||||
*this = src;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap::~ClapTrap()
|
||||
{
|
||||
std::cout << "ClapTrap:: " << _name << " is destroyed!" << std::endl;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap &ClapTrap::operator=(ClapTrap const &rhs)
|
||||
@ -40,11 +32,14 @@ ClapTrap &ClapTrap::operator=(ClapTrap const &rhs)
|
||||
if (this == &rhs)
|
||||
return *this;
|
||||
|
||||
std::cout << "ClapTrap:: " << rhs._name << " is assigned to ClapTrap formely known as " << _name << "!" << std::endl;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << rhs._name
|
||||
<< " is assigned to ClapTrap formely known as " << _name << "!"
|
||||
<< std::endl;
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
status();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -52,27 +47,47 @@ void ClapTrap::attack(std::string const &target)
|
||||
{
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << _name << " is too tired to attack!" << std::endl;
|
||||
return ;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR9 << _name << " is too tired to attack!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
if (_hitpoints < 1)
|
||||
{
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR9 << _name << " should be repaired before it can attack!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
_energy_points -= 1;
|
||||
std::cout << "ClapTrap:: " << _name << " attacks " << target << ", causing " << _attack_damage << " points of damage!" << std::endl;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " attacks " << target << ", causing "
|
||||
<< _attack_damage << " points of damage!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
void ClapTrap::takeDamage(unsigned int amount)
|
||||
{
|
||||
_hitpoints -= amount;
|
||||
std::cout << "ClapTrap:: " << _name << " takes " << amount << " points of damage!" << std::endl;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " takes " << amount
|
||||
<< " points of damage!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
void ClapTrap::beRepaired(unsigned int amount)
|
||||
{
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << "ClapTrap:: " << _name << " is too tired to repair!" << std::endl;
|
||||
return ;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR9 << _name << " is too tired to repair!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
_hitpoints += amount;
|
||||
_energy_points -= 1;
|
||||
std::cout << "ClapTrap:: " << _name << " is repaired for " << amount << " points!" << std::endl;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is repaired for " << amount
|
||||
<< " points!" << std::endl;
|
||||
status();
|
||||
}
|
||||
void ClapTrap::status() const
|
||||
{
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR10 << _name << " has " << _hitpoints << " hitpoints, "
|
||||
<< _energy_points << " energy points and " << _attack_damage
|
||||
<< " attack damage!" << COLOR_RESET << std::endl;
|
||||
}
|
||||
|
||||
@ -12,35 +12,42 @@ FragTrap::FragTrap(std::string name) : ClapTrap(name)
|
||||
_energy_points = 100;
|
||||
_attack_damage = 30;
|
||||
|
||||
std::cout << "FragTrap:: " << _name << " has been created" << std::endl;
|
||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||
}
|
||||
FragTrap::FragTrap(FragTrap const &src)
|
||||
{
|
||||
*this = src;
|
||||
std::cout << "FragTrap:: " << _name << " has been created by copy constructor" << std::endl;
|
||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created by copy constructor" << std::endl;
|
||||
}
|
||||
|
||||
FragTrap::~FragTrap()
|
||||
{
|
||||
std::cout << "FragTrap:: " << _name << " has been destroyed" << std::endl;
|
||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
||||
}
|
||||
|
||||
FragTrap &FragTrap::operator=(FragTrap const &rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
}
|
||||
if (this == &rhs)
|
||||
return (*this);
|
||||
|
||||
std::cout << "FragTrap:: " << _name << " has been created by assignation operator" << std::endl;
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._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 << "FragTrap:: " << _name << " high fives guys!" << std::endl;
|
||||
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;
|
||||
}
|
||||
@ -6,66 +6,88 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 11:32:48 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 15:49:38 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/04/07 16:21:49 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include "ClapTrap.hpp"
|
||||
#include "ScavTrap.hpp"
|
||||
|
||||
ScavTrap::ScavTrap() : ClapTrap()
|
||||
ScavTrap::ScavTrap() : ClapTrap(), _guard_mode(false)
|
||||
{
|
||||
_hitpoints = 100;
|
||||
_energy_points = 50;
|
||||
_attack_damage = 20;
|
||||
|
||||
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||
}
|
||||
|
||||
ScavTrap::ScavTrap(std::string name) : ClapTrap(name), _guard_mode(false)
|
||||
{
|
||||
_hitpoints = 100;
|
||||
_energy_points = 100;
|
||||
_attack_damage = 30;
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " has been created" << std::endl;
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||
}
|
||||
|
||||
ScavTrap::ScavTrap(ScavTrap const &src) : ClapTrap(src)
|
||||
{
|
||||
*this = src;
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " has been created by copy constructor" << std::endl;
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created by copy constructor" << std::endl;
|
||||
}
|
||||
|
||||
ScavTrap::~ScavTrap()
|
||||
{
|
||||
std::cout << "ScavTrap:: " << _name << " has been destroyed" << std::endl;
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
||||
}
|
||||
|
||||
ScavTrap &ScavTrap::operator=(ScavTrap const &rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
}
|
||||
if (this == &rhs)
|
||||
return (*this);
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " has been created by assignation operator" << std::endl;
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created by assignment operator" << std::endl;
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void ScavTrap::attack(std::string const &target)
|
||||
{
|
||||
std::cout << "ScavTrap:: " << _name << " attack " << target << ", causing " << _attack_damage << " points of damage!" << std::endl;
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << COLOR13 << "ScavTrap " << COLOR9 << _name << " is too tired to attack!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
if (_hitpoints < 1)
|
||||
{
|
||||
std::cout << COLOR13 << "ScavTrap " << COLOR9 << _name << " should be repaired before it can attack!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
_energy_points -= 1;
|
||||
std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " attacks " << target << " without weapon, causing "
|
||||
<< _attack_damage << " points of damage!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
|
||||
void ScavTrap::guardGate()
|
||||
{
|
||||
_guard_mode = true;
|
||||
|
||||
std::cout << "ScavTrap:: " << _name << " in Gate keeper mode" << std::endl;
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " is in Gate keeper mode" << std::endl;
|
||||
}
|
||||
|
||||
void ScavTrap::status() const
|
||||
{
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR10 << _name << " has " << _hitpoints << " hitpoints, "
|
||||
<< _energy_points << " energy points, " << _attack_damage << " attack damage ";
|
||||
if (_guard_mode)
|
||||
std::cout << "and is in Gate keeper mode" << COLOR_RESET << std::endl;
|
||||
else
|
||||
std::cout << "and is not in Gate keeper mode" << COLOR_RESET << std::endl;
|
||||
}
|
||||
@ -6,45 +6,70 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 11:35:59 by whaffman #+# #+# */
|
||||
/* Updated: 2025/03/28 15:53:41 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/04/07 16:32:00 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <iostream>
|
||||
#include "ScavTrap.hpp"
|
||||
#include "ClapTrap.hpp"
|
||||
#include "ScavTrap.hpp"
|
||||
#include "FragTrap.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
// Test ClapTrap
|
||||
std::cout << "Testing ClapTrap \"Amelie\"" << std::endl;
|
||||
ClapTrap clap("Amelie");
|
||||
clap.attack("target");
|
||||
clap.takeDamage(5);
|
||||
clap.beRepaired(3);
|
||||
std::cout << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
||||
std::cout << COLOR10 << "claptrap with parameter constructor" << COLOR_RESET << std::endl;
|
||||
FragTrap claptrap("Rudolph");
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "claptrap2 with copy constructor" << COLOR_RESET << std::endl;
|
||||
FragTrap claptrap2(claptrap);
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "Claptrap3 with default constructor" << COLOR_RESET << std::endl;
|
||||
FragTrap claptrap3;
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "claptrap3 = claptrap" << COLOR_RESET << std::endl;
|
||||
claptrap3 = claptrap;
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "claptrap4 with parameter constructor" << COLOR_RESET << std::endl;
|
||||
FragTrap claptrap4("Eduard");
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
// Test ScavTrap
|
||||
std::cout << "Testing ScavTrap \"Brent\"" << std::endl;
|
||||
ScavTrap scav("Brent");
|
||||
scav.attack("target");
|
||||
scav.takeDamage(10);
|
||||
scav.beRepaired(7);
|
||||
scav.guardGate();
|
||||
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap" << COLOR_RESET << std::endl;
|
||||
claptrap.attack("enemy");
|
||||
claptrap.takeDamage(5);
|
||||
claptrap.beRepaired(3);
|
||||
std::cout << std::endl;
|
||||
|
||||
// Test FragTrap
|
||||
std::cout << "Testing FragTrap \"Charlie\"" << std::endl;
|
||||
FragTrap frag("Charlie");
|
||||
frag.attack("target");
|
||||
frag.takeDamage(15);
|
||||
frag.beRepaired(10);
|
||||
frag.highFivesGuys();
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap2" << COLOR_RESET << std::endl;
|
||||
claptrap2.attack("enemy");
|
||||
claptrap2.takeDamage(15);
|
||||
claptrap2.attack("the sun");
|
||||
for(int i = 0; i < 10; i++)
|
||||
claptrap2.takeDamage(15);
|
||||
claptrap2.attack("the moon");
|
||||
claptrap2.highFivesGuys();
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << std::endl << "The World is Ending!!" <<std::endl <<std::endl;
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap3" << COLOR_RESET << std::endl;
|
||||
claptrap3.attack("enemy");
|
||||
claptrap3.takeDamage(5);
|
||||
claptrap3.highFivesGuys();
|
||||
std::cout << std::endl;
|
||||
|
||||
return 0;
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap4" << COLOR_RESET << std::endl;
|
||||
claptrap4.attack("itself");
|
||||
claptrap4.takeDamage(5);
|
||||
claptrap4.beRepaired(4);
|
||||
claptrap4.highFivesGuys();
|
||||
claptrap4.attack("enemy");
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -6,11 +6,11 @@
|
||||
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
||||
# +#+ #
|
||||
# Created: 2025/03/24 15:14:58 by whaffman #+# #+# #
|
||||
# Updated: 2025/03/27 16:21:13 by whaffman ######## odam.nl #
|
||||
# Updated: 2025/04/07 17:21:50 by whaffman ######## odam.nl #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME=
|
||||
SRC=
|
||||
NAME= DiamondTrap
|
||||
SRC= main.cpp ClapTrap.cpp ScavTrap.cpp FragTrap.cpp DiamondTrap.cpp
|
||||
|
||||
-include ../common.mk
|
||||
|
||||
57
ex03/inc/ClapTrap.hpp
Normal file
57
ex03/inc/ClapTrap.hpp
Normal file
@ -0,0 +1,57 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* ClapTrap.hpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/27 16:26:32 by whaffman #+# #+# */
|
||||
/* Updated: 2025/04/07 15:49:00 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#define COLOR0 "\033[38;5;0m"
|
||||
#define COLOR1 "\033[38;5;1m"
|
||||
#define COLOR2 "\033[38;5;2m"
|
||||
#define COLOR3 "\033[38;5;3m"
|
||||
#define COLOR4 "\033[38;5;4m"
|
||||
#define COLOR5 "\033[38;5;5m"
|
||||
#define COLOR6 "\033[38;5;6m"
|
||||
#define COLOR7 "\033[38;5;7m"
|
||||
#define COLOR8 "\033[38;5;8m"
|
||||
#define COLOR9 "\033[38;5;9m"
|
||||
#define COLOR10 "\033[38;5;10m"
|
||||
#define COLOR11 "\033[38;5;11m"
|
||||
#define COLOR12 "\033[38;5;12m"
|
||||
#define COLOR13 "\033[38;5;13m"
|
||||
#define COLOR14 "\033[38;5;14m"
|
||||
#define COLOR15 "\033[38;5;15m"
|
||||
#define COLOR_RESET "\033[m"
|
||||
|
||||
|
||||
|
||||
class ClapTrap
|
||||
{
|
||||
protected:
|
||||
std::string _name;
|
||||
int _hitpoints;
|
||||
int _energy_points;
|
||||
int _attack_damage;
|
||||
|
||||
public:
|
||||
ClapTrap();
|
||||
ClapTrap(std::string name);
|
||||
ClapTrap(ClapTrap const &src);
|
||||
~ClapTrap();
|
||||
|
||||
ClapTrap &operator=(ClapTrap const &rhs);
|
||||
|
||||
void status() const;
|
||||
void attack(std::string const &target);
|
||||
void takeDamage(unsigned int amount);
|
||||
void beRepaired(unsigned int amount);
|
||||
};
|
||||
34
ex03/inc/DiamondTrap.hpp
Normal file
34
ex03/inc/DiamondTrap.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* DiamondTrap.hpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/07 17:02:52 by whaffman #+# #+# */
|
||||
/* Updated: 2025/04/07 17:37:06 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
#include "FragTrap.hpp"
|
||||
#include "ScavTrap.hpp"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class DiamondTrap : public FragTrap, public ScavTrap
|
||||
{
|
||||
private:
|
||||
std::string _name;
|
||||
|
||||
public:
|
||||
DiamondTrap();
|
||||
DiamondTrap(std::string name);
|
||||
DiamondTrap(DiamondTrap const &src);
|
||||
~DiamondTrap();
|
||||
|
||||
DiamondTrap &operator=(DiamondTrap const &rhs);
|
||||
|
||||
void whoAmI(void);
|
||||
void status(void) const;
|
||||
};
|
||||
30
ex03/inc/FragTrap.hpp
Normal file
30
ex03/inc/FragTrap.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* FragTrap.hpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 15:44:08 by whaffman #+# #+# */
|
||||
/* Updated: 2025/04/07 17:28:32 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ClapTrap.hpp"
|
||||
#include <string>
|
||||
|
||||
class FragTrap : virtual public ClapTrap
|
||||
{
|
||||
public:
|
||||
FragTrap();
|
||||
FragTrap(std::string name);
|
||||
FragTrap(FragTrap const &src);
|
||||
~FragTrap();
|
||||
|
||||
FragTrap &operator=(FragTrap const &rhs);
|
||||
|
||||
void highFivesGuys(void);
|
||||
void status(void) const;
|
||||
};
|
||||
34
ex03/inc/ScavTrap.hpp
Normal file
34
ex03/inc/ScavTrap.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* ScavTrap.hpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 11:28:29 by whaffman #+# #+# */
|
||||
/* Updated: 2025/04/07 17:06:59 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "ClapTrap.hpp"
|
||||
|
||||
class ScavTrap : virtual public ClapTrap
|
||||
{
|
||||
private:
|
||||
bool _guard_mode;
|
||||
|
||||
public:
|
||||
ScavTrap();
|
||||
ScavTrap(std::string name);
|
||||
ScavTrap(ScavTrap const &src);
|
||||
~ScavTrap();
|
||||
|
||||
ScavTrap &operator=(ScavTrap const &rhs);
|
||||
|
||||
void attack(std::string const &target);
|
||||
void guardGate();
|
||||
void status() const;
|
||||
};
|
||||
93
ex03/src/ClapTrap.cpp
Normal file
93
ex03/src/ClapTrap.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
#include "ClapTrap.hpp"
|
||||
#include <iostream>
|
||||
|
||||
ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0)
|
||||
{
|
||||
_name = "Noname";
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap::ClapTrap(std::string name) : _name(name), _hitpoints(10), _energy_points(10), _attack_damage(0)
|
||||
{
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << name << " is created!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap::ClapTrap(ClapTrap const &src)
|
||||
{
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is copied!" << std::endl;
|
||||
*this = src;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap::~ClapTrap()
|
||||
{
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ClapTrap &ClapTrap::operator=(ClapTrap const &rhs)
|
||||
{
|
||||
if (this == &rhs)
|
||||
return *this;
|
||||
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << rhs._name
|
||||
<< " is assigned to ClapTrap formely known as " << _name << "!"
|
||||
<< std::endl;
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
status();
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ClapTrap::attack(std::string const &target)
|
||||
{
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR9 << _name << " is too tired to attack!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
if (_hitpoints < 1)
|
||||
{
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR9 << _name << " should be repaired before it can attack!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
_energy_points -= 1;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " attacks " << target << ", causing "
|
||||
<< _attack_damage << " points of damage!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
void ClapTrap::takeDamage(unsigned int amount)
|
||||
{
|
||||
_hitpoints -= amount;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " takes " << amount
|
||||
<< " points of damage!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
void ClapTrap::beRepaired(unsigned int amount)
|
||||
{
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR9 << _name << " is too tired to repair!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
_hitpoints += amount;
|
||||
_energy_points -= 1;
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is repaired for " << amount
|
||||
<< " points!" << std::endl;
|
||||
status();
|
||||
}
|
||||
void ClapTrap::status() const
|
||||
{
|
||||
std::cout << COLOR12 << "Claptrap " << COLOR10 << _name << " has " << _hitpoints << " hitpoints, "
|
||||
<< _energy_points << " energy points and " << _attack_damage
|
||||
<< " attack damage!" << COLOR_RESET << std::endl;
|
||||
}
|
||||
67
ex03/src/DiamondTrap.cpp
Normal file
67
ex03/src/DiamondTrap.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
#include "DiamondTrap.hpp"
|
||||
#include "ClapTrap.hpp"
|
||||
#include "ScavTrap.hpp"
|
||||
#include "FragTrap.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
DiamondTrap::DiamondTrap() : ClapTrap("NoName"), _name("NoName")
|
||||
{
|
||||
_hitpoints = FragTrap::_hitpoints;
|
||||
_energy_points = ScavTrap::_energy_points;
|
||||
_attack_damage = FragTrap::_attack_damage;
|
||||
|
||||
std::cout << COLOR11 << "Diamondtrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
DiamondTrap::DiamondTrap(std::string name) : ClapTrap(name + "_clap_name"), _name(name)
|
||||
{
|
||||
_hitpoints = FragTrap::_hitpoints;
|
||||
_energy_points = ScavTrap::_energy_points;
|
||||
_attack_damage = FragTrap::_attack_damage;
|
||||
|
||||
std::cout << COLOR11 << "Diamondtrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
DiamondTrap::DiamondTrap(DiamondTrap const &src)
|
||||
{
|
||||
*this = src;
|
||||
std::cout << COLOR11 << "Diamondtrap " << COLOR_RESET << _name << " has been created by copy constructor" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
DiamondTrap::~DiamondTrap()
|
||||
{
|
||||
std::cout << COLOR11 << "Diamondtrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
DiamondTrap &DiamondTrap::operator=(DiamondTrap const &rhs)
|
||||
{
|
||||
if (this == &rhs)
|
||||
return (*this);
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
ClapTrap::_name = rhs.ClapTrap::_name;
|
||||
std::cout << COLOR11 << "Diamondtrap " << COLOR_RESET << _name << " has been created by assignment operator" << std::endl;
|
||||
status();
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void DiamondTrap::whoAmI(void)
|
||||
{
|
||||
std::cout << COLOR11 << "Diamondtrap " << COLOR_RESET
|
||||
<< "I am " << _name << ", but my ClapTRap friends call me: "
|
||||
<< ClapTrap::_name << std::endl;
|
||||
status();
|
||||
}
|
||||
void DiamondTrap::status() const
|
||||
{
|
||||
std::cout << COLOR11 << "Diamondtrap " << COLOR10 << _name << " has " << _hitpoints
|
||||
<< " hitpoints, " << _energy_points << " energy points and "
|
||||
<< _attack_damage << " attack damage." << std::endl;
|
||||
}
|
||||
61
ex03/src/FragTrap.cpp
Normal file
61
ex03/src/FragTrap.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include "FragTrap.hpp"
|
||||
#include "ClapTrap.hpp"
|
||||
#include <iostream>
|
||||
|
||||
FragTrap::FragTrap() : ClapTrap()
|
||||
{
|
||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
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;
|
||||
status();
|
||||
}
|
||||
FragTrap::FragTrap(FragTrap const &src)
|
||||
{
|
||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created by copy constructor" << std::endl;
|
||||
*this = src;
|
||||
status();
|
||||
}
|
||||
|
||||
FragTrap::~FragTrap()
|
||||
{
|
||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
FragTrap &FragTrap::operator=(FragTrap const &rhs)
|
||||
{
|
||||
if (this == &rhs)
|
||||
return (*this);
|
||||
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
|
||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created by assignation operator" << std::endl;
|
||||
status();
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void FragTrap::highFivesGuys(void)
|
||||
{
|
||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " common guys lets do high fives!!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
|
||||
void FragTrap::status(void) const
|
||||
{
|
||||
std::cout << COLOR14 << "FragTrap " << COLOR10 << _name << " has " << _hitpoints
|
||||
<< " hitpoints, " << _energy_points << " energy points and "
|
||||
<< _attack_damage << " attack damage." << COLOR_RESET << std::endl;
|
||||
}
|
||||
97
ex03/src/ScavTrap.cpp
Normal file
97
ex03/src/ScavTrap.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* ScavTrap.cpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 11:32:48 by whaffman #+# #+# */
|
||||
/* Updated: 2025/04/07 17:34:50 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <iostream>
|
||||
#include "ClapTrap.hpp"
|
||||
#include "ScavTrap.hpp"
|
||||
|
||||
ScavTrap::ScavTrap() : ClapTrap(), _guard_mode(false)
|
||||
{
|
||||
_hitpoints = 100;
|
||||
_energy_points = 50;
|
||||
_attack_damage = 20;
|
||||
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ScavTrap::ScavTrap(std::string name) : ClapTrap(name), _guard_mode(false)
|
||||
{
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ScavTrap::ScavTrap(ScavTrap const &src) : ClapTrap(src)
|
||||
{
|
||||
*this = src;
|
||||
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created by copy constructor" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ScavTrap::~ScavTrap()
|
||||
{
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
ScavTrap &ScavTrap::operator=(ScavTrap const &rhs)
|
||||
{
|
||||
if (this == &rhs)
|
||||
return (*this);
|
||||
|
||||
_name = rhs._name;
|
||||
_hitpoints = rhs._hitpoints;
|
||||
_energy_points = rhs._energy_points;
|
||||
_attack_damage = rhs._attack_damage;
|
||||
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created by assignment operator" << std::endl;
|
||||
status();
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void ScavTrap::attack(std::string const &target)
|
||||
{
|
||||
if (_energy_points < 1)
|
||||
{
|
||||
std::cout << COLOR13 << "ScavTrap " << COLOR9 << _name << " is too tired to attack!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
if (_hitpoints < 1)
|
||||
{
|
||||
std::cout << COLOR13 << "ScavTrap " << COLOR9 << _name << " should be repaired before it can attack!"
|
||||
<< COLOR_RESET << std::endl;
|
||||
return;
|
||||
}
|
||||
_energy_points -= 1;
|
||||
std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " attacks " << target << " without weapon, causing "
|
||||
<< _attack_damage << " points of damage!" << std::endl;
|
||||
status();
|
||||
}
|
||||
|
||||
void ScavTrap::guardGate()
|
||||
{
|
||||
_guard_mode = true;
|
||||
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " is in Gate keeper mode" << std::endl;
|
||||
}
|
||||
|
||||
void ScavTrap::status() const
|
||||
{
|
||||
std::cout << COLOR13 << "Scavtrap " << COLOR10 << _name << " has " << _hitpoints << " hitpoints, "
|
||||
<< _energy_points << " energy points, " << _attack_damage << " attack damage ";
|
||||
if (_guard_mode)
|
||||
std::cout << "and is in Gate keeper mode" << COLOR_RESET << std::endl;
|
||||
else
|
||||
std::cout << "and is not in Gate keeper mode" << COLOR_RESET << std::endl;
|
||||
}
|
||||
78
ex03/src/main.cpp
Normal file
78
ex03/src/main.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* main.cpp :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/03/28 11:35:59 by whaffman #+# #+# */
|
||||
/* Updated: 2025/04/07 17:25:03 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <iostream>
|
||||
#include "ClapTrap.hpp"
|
||||
#include "ScavTrap.hpp"
|
||||
#include "FragTrap.hpp"
|
||||
#include "DiamondTrap.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
||||
std::cout << COLOR10 << "claptrap with parameter constructor" << COLOR_RESET << std::endl;
|
||||
DiamondTrap claptrap("Rudolph");
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "claptrap2 with copy constructor" << COLOR_RESET << std::endl;
|
||||
DiamondTrap claptrap2(claptrap);
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "Claptrap3 with default constructor" << COLOR_RESET << std::endl;
|
||||
DiamondTrap claptrap3;
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "claptrap3 = claptrap" << COLOR_RESET << std::endl;
|
||||
claptrap3 = claptrap;
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "claptrap4 with parameter constructor" << COLOR_RESET << std::endl;
|
||||
DiamondTrap claptrap4("Eduard");
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap" << COLOR_RESET << std::endl;
|
||||
claptrap.attack("enemy");
|
||||
claptrap.takeDamage(5);
|
||||
claptrap.beRepaired(3);
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap2" << COLOR_RESET << std::endl;
|
||||
claptrap2.attack("enemy");
|
||||
claptrap2.takeDamage(15);
|
||||
claptrap2.attack("the sun");
|
||||
for(int i = 0; i < 10; i++)
|
||||
claptrap2.takeDamage(15);
|
||||
claptrap2.attack("the moon");
|
||||
claptrap2.highFivesGuys();
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap3" << COLOR_RESET << std::endl;
|
||||
claptrap3.attack("enemy");
|
||||
claptrap3.takeDamage(5);
|
||||
claptrap3.highFivesGuys();
|
||||
claptrap3.guardGate();
|
||||
claptrap3.whoAmI();
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: claptrap4" << COLOR_RESET << std::endl;
|
||||
claptrap4.attack("itself");
|
||||
claptrap4.takeDamage(5);
|
||||
claptrap4.beRepaired(4);
|
||||
claptrap4.highFivesGuys();
|
||||
claptrap4.attack("enemy");
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
||||
|
||||
return (0);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user