final ?
This commit is contained in:
parent
1a16c14f2b
commit
bc7195ca99
@ -6,14 +6,14 @@
|
|||||||
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
||||||
# +#+ #
|
# +#+ #
|
||||||
# Created: 2025/03/21 15:00:16 by whaffman #+# #+# #
|
# Created: 2025/03/21 15:00:16 by whaffman #+# #+# #
|
||||||
# Updated: 2025/04/07 22:48:32 by whaffman ######## odam.nl #
|
# Updated: 2025/04/08 10:22:55 by whaffman ######## odam.nl #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
INC = -I./inc
|
INC = -I./inc
|
||||||
VPATH = src
|
VPATH = src
|
||||||
OBJ = $(SRC:.cpp=.o)
|
OBJ = $(SRC:.cpp=.o)
|
||||||
CC = clang++
|
CC = c++
|
||||||
CFLAGS = -Wall -Wextra -Werror
|
CFLAGS = -Wall -Wextra -Werror
|
||||||
|
|
||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/27 16:26:32 by whaffman #+# #+# */
|
/* Created: 2025/03/27 16:26:32 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 15:35:26 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 10:19:00 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#define BOLD_UNDERLINE "\033[1;4m"
|
||||||
|
|
||||||
#define COLOR0 "\033[38;5;0m"
|
#define COLOR0 "\033[38;5;0m"
|
||||||
#define COLOR1 "\033[38;5;1m"
|
#define COLOR1 "\033[38;5;1m"
|
||||||
#define COLOR2 "\033[38;5;2m"
|
#define COLOR2 "\033[38;5;2m"
|
||||||
@ -32,8 +34,6 @@
|
|||||||
#define COLOR15 "\033[38;5;15m"
|
#define COLOR15 "\033[38;5;15m"
|
||||||
#define COLOR_RESET "\033[m"
|
#define COLOR_RESET "\033[m"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ClapTrap
|
class ClapTrap
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -48,10 +48,12 @@ public:
|
|||||||
ClapTrap(ClapTrap const &src);
|
ClapTrap(ClapTrap const &src);
|
||||||
~ClapTrap();
|
~ClapTrap();
|
||||||
|
|
||||||
ClapTrap &operator=(ClapTrap const &rhs);
|
ClapTrap &operator=(ClapTrap const &other);
|
||||||
|
|
||||||
void status() const;
|
void status() const;
|
||||||
void attack(std::string const &target);
|
void attack(std::string const &target);
|
||||||
void takeDamage(unsigned int amount);
|
void takeDamage(unsigned int amount);
|
||||||
void beRepaired(unsigned int amount);
|
void beRepaired(unsigned int amount);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void claptrap_test();
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0)
|
ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0)
|
||||||
{
|
{
|
||||||
_name = "Noname";
|
_name = "Noname";
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created!" << std::endl;
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created! Lets call it \"Noname\"" << std::endl;
|
||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,31 +14,35 @@ ClapTrap::ClapTrap(std::string name) : _name(name), _hitpoints(10), _energy_poin
|
|||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClapTrap::ClapTrap(ClapTrap const &src)
|
ClapTrap::ClapTrap(ClapTrap const &other)
|
||||||
{
|
{
|
||||||
*this = src;
|
_name = other._name;
|
||||||
|
_hitpoints = other._hitpoints;
|
||||||
|
_energy_points = other._energy_points;
|
||||||
|
_attack_damage = other._attack_damage;
|
||||||
|
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is copied!" << std::endl;
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is copied!" << std::endl;
|
||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClapTrap::~ClapTrap()
|
ClapTrap::~ClapTrap()
|
||||||
{
|
{
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl;
|
|
||||||
status();
|
status();
|
||||||
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClapTrap &ClapTrap::operator=(ClapTrap const &rhs)
|
ClapTrap &ClapTrap::operator=(ClapTrap const &other)
|
||||||
{
|
{
|
||||||
if (this == &rhs)
|
if (this == &other)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << rhs._name
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << other._name
|
||||||
<< " is assigned to ClapTrap formely known as " << _name << "!"
|
<< " is assigned to ClapTrap formely known as " << _name << "!"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
_name = rhs._name;
|
_name = other._name;
|
||||||
_hitpoints = rhs._hitpoints;
|
_hitpoints = other._hitpoints;
|
||||||
_energy_points = rhs._energy_points;
|
_energy_points = other._energy_points;
|
||||||
_attack_damage = rhs._attack_damage;
|
_attack_damage = other._attack_damage;
|
||||||
status();
|
status();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -91,3 +95,43 @@ void ClapTrap::status() const
|
|||||||
<< _energy_points << " energy points and " << _attack_damage
|
<< _energy_points << " energy points and " << _attack_damage
|
||||||
<< " attack damage!" << COLOR_RESET << std::endl;
|
<< " attack damage!" << COLOR_RESET << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void claptrap_test()
|
||||||
|
{
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR1 << "ClapTrap tests:" << COLOR_RESET << std::endl << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "ClapTrap Alice with parameter constructor" << COLOR_RESET << std::endl;
|
||||||
|
ClapTrap alice("Alice");
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "ClapTrap alice_copy with copy constructor of Alice" << COLOR_RESET << std::endl;
|
||||||
|
ClapTrap alice_copy(alice);
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_claptrap with default constructor" << COLOR_RESET << std::endl;
|
||||||
|
ClapTrap default_claptrap;
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_claptrap = alice" << COLOR_RESET << std::endl;
|
||||||
|
default_claptrap = alice;
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: alice" << COLOR_RESET << std::endl;
|
||||||
|
alice.attack("enemy");
|
||||||
|
alice.takeDamage(5);
|
||||||
|
alice.beRepaired(3);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: alice_copy" << COLOR_RESET << std::endl;
|
||||||
|
alice_copy.attack("enemy");
|
||||||
|
alice_copy.takeDamage(15);
|
||||||
|
alice_copy.attack("the sun");
|
||||||
|
for(int i = 0; i < 10; i++)
|
||||||
|
alice_copy.beRepaired(1);
|
||||||
|
alice_copy.attack("the moon");
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: default_claptrap" << COLOR_RESET << std::endl;
|
||||||
|
default_claptrap.attack("enemy");
|
||||||
|
default_claptrap.takeDamage(5);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
||||||
|
}
|
||||||
@ -6,53 +6,18 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/27 16:56:23 by whaffman #+# #+# */
|
/* Created: 2025/03/27 16:56:23 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 22:38:04 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 09:25:45 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ClapTrap.hpp"
|
#include "ClapTrap.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
void claptrap_test()
|
|
||||||
{
|
|
||||||
std::cout << COLOR9 << "ClapTrap tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "ClapTrap Alice with parameter constructor" << COLOR_RESET << std::endl;
|
|
||||||
ClapTrap alice("Alice");
|
|
||||||
std::cout << COLOR10 << "Claptrap alice_copy with copy constructor of Alice" << COLOR_RESET << std::endl;
|
|
||||||
ClapTrap alice_copy(alice);
|
|
||||||
std::cout << COLOR10 << "default_claptrap with default constructor" << COLOR_RESET << std::endl;
|
|
||||||
ClapTrap default_claptrap;
|
|
||||||
std::cout << COLOR10 << "default_claptrap = alice" << COLOR_RESET << std::endl;
|
|
||||||
default_claptrap = alice;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: alice" << COLOR_RESET << std::endl;
|
|
||||||
alice.attack("enemy");
|
|
||||||
alice.takeDamage(5);
|
|
||||||
alice.beRepaired(3);
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: alice_copy" << COLOR_RESET << std::endl;
|
|
||||||
alice_copy.attack("enemy");
|
|
||||||
alice_copy.takeDamage(15);
|
|
||||||
alice_copy.attack("the sun");
|
|
||||||
for(int i = 0; i < 10; i++)
|
|
||||||
alice_copy.beRepaired(1);
|
|
||||||
alice_copy.attack("the moon");
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: default_claptrap" << COLOR_RESET << std::endl;
|
|
||||||
default_claptrap.attack("enemy");
|
|
||||||
default_claptrap.takeDamage(5);
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::cout << "Starting tests..." << std::endl;
|
std::cout << BOLD_UNDERLINE << COLOR9 << "Starting tests..." << COLOR_RESET << std::endl << std::endl;
|
||||||
claptrap_test();
|
claptrap_test();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -6,11 +6,11 @@
|
|||||||
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
||||||
# +#+ #
|
# +#+ #
|
||||||
# Created: 2025/03/24 15:14:58 by whaffman #+# #+# #
|
# Created: 2025/03/24 15:14:58 by whaffman #+# #+# #
|
||||||
# Updated: 2025/03/28 11:35:32 by whaffman ######## odam.nl #
|
# Updated: 2025/04/08 09:11:36 by whaffman ######## odam.nl #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
NAME= ScavTrap
|
NAME= ClapTrap
|
||||||
SRC= main.cpp ScavTrap.cpp ClapTrap.cpp
|
SRC= main.cpp ScavTrap.cpp ClapTrap.cpp
|
||||||
|
|
||||||
-include ../common.mk
|
-include ../common.mk
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/27 16:26:32 by whaffman #+# #+# */
|
/* Created: 2025/03/27 16:26:32 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 15:49:00 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 10:19:00 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#define BOLD_UNDERLINE "\033[1;4m"
|
||||||
|
|
||||||
#define COLOR0 "\033[38;5;0m"
|
#define COLOR0 "\033[38;5;0m"
|
||||||
#define COLOR1 "\033[38;5;1m"
|
#define COLOR1 "\033[38;5;1m"
|
||||||
#define COLOR2 "\033[38;5;2m"
|
#define COLOR2 "\033[38;5;2m"
|
||||||
@ -32,8 +34,6 @@
|
|||||||
#define COLOR15 "\033[38;5;15m"
|
#define COLOR15 "\033[38;5;15m"
|
||||||
#define COLOR_RESET "\033[m"
|
#define COLOR_RESET "\033[m"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ClapTrap
|
class ClapTrap
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
@ -48,10 +48,12 @@ public:
|
|||||||
ClapTrap(ClapTrap const &src);
|
ClapTrap(ClapTrap const &src);
|
||||||
~ClapTrap();
|
~ClapTrap();
|
||||||
|
|
||||||
ClapTrap &operator=(ClapTrap const &rhs);
|
ClapTrap &operator=(ClapTrap const &other);
|
||||||
|
|
||||||
void status() const;
|
void status() const;
|
||||||
void attack(std::string const &target);
|
void attack(std::string const &target);
|
||||||
void takeDamage(unsigned int amount);
|
void takeDamage(unsigned int amount);
|
||||||
void beRepaired(unsigned int amount);
|
void beRepaired(unsigned int amount);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void claptrap_test();
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/28 11:28:29 by whaffman #+# #+# */
|
/* Created: 2025/03/28 11:28:29 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 16:19:46 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 10:19:00 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,9 +26,11 @@ public:
|
|||||||
ScavTrap(ScavTrap const &src);
|
ScavTrap(ScavTrap const &src);
|
||||||
~ScavTrap();
|
~ScavTrap();
|
||||||
|
|
||||||
ScavTrap &operator=(ScavTrap const &rhs);
|
ScavTrap &operator=(ScavTrap const &other);
|
||||||
|
|
||||||
void attack(std::string const &target);
|
void attack(std::string const &target);
|
||||||
void guardGate();
|
void guardGate();
|
||||||
void status() const;
|
void status() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void scavtrap_test();
|
||||||
@ -4,7 +4,7 @@
|
|||||||
ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0)
|
ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0)
|
||||||
{
|
{
|
||||||
_name = "Noname";
|
_name = "Noname";
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created!" << std::endl;
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created! Lets call it \"Noname\"" << std::endl;
|
||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,31 +14,35 @@ ClapTrap::ClapTrap(std::string name) : _name(name), _hitpoints(10), _energy_poin
|
|||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClapTrap::ClapTrap(ClapTrap const &src)
|
ClapTrap::ClapTrap(ClapTrap const &other)
|
||||||
{
|
{
|
||||||
|
_name = other._name;
|
||||||
|
_hitpoints = other._hitpoints;
|
||||||
|
_energy_points = other._energy_points;
|
||||||
|
_attack_damage = other._attack_damage;
|
||||||
|
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is copied!" << std::endl;
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is copied!" << std::endl;
|
||||||
*this = src;
|
|
||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClapTrap::~ClapTrap()
|
ClapTrap::~ClapTrap()
|
||||||
{
|
{
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl;
|
|
||||||
status();
|
status();
|
||||||
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClapTrap &ClapTrap::operator=(ClapTrap const &rhs)
|
ClapTrap &ClapTrap::operator=(ClapTrap const &other)
|
||||||
{
|
{
|
||||||
if (this == &rhs)
|
if (this == &other)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << rhs._name
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << other._name
|
||||||
<< " is assigned to ClapTrap formely known as " << _name << "!"
|
<< " is assigned to ClapTrap formely known as " << _name << "!"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
_name = rhs._name;
|
_name = other._name;
|
||||||
_hitpoints = rhs._hitpoints;
|
_hitpoints = other._hitpoints;
|
||||||
_energy_points = rhs._energy_points;
|
_energy_points = other._energy_points;
|
||||||
_attack_damage = rhs._attack_damage;
|
_attack_damage = other._attack_damage;
|
||||||
status();
|
status();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -91,3 +95,43 @@ void ClapTrap::status() const
|
|||||||
<< _energy_points << " energy points and " << _attack_damage
|
<< _energy_points << " energy points and " << _attack_damage
|
||||||
<< " attack damage!" << COLOR_RESET << std::endl;
|
<< " attack damage!" << COLOR_RESET << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void claptrap_test()
|
||||||
|
{
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR1 << "ClapTrap tests:" << COLOR_RESET << std::endl << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "ClapTrap Alice with parameter constructor" << COLOR_RESET << std::endl;
|
||||||
|
ClapTrap alice("Alice");
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "ClapTrap alice_copy with copy constructor of Alice" << COLOR_RESET << std::endl;
|
||||||
|
ClapTrap alice_copy(alice);
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_claptrap with default constructor" << COLOR_RESET << std::endl;
|
||||||
|
ClapTrap default_claptrap;
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_claptrap = alice" << COLOR_RESET << std::endl;
|
||||||
|
default_claptrap = alice;
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: alice" << COLOR_RESET << std::endl;
|
||||||
|
alice.attack("enemy");
|
||||||
|
alice.takeDamage(5);
|
||||||
|
alice.beRepaired(3);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: alice_copy" << COLOR_RESET << std::endl;
|
||||||
|
alice_copy.attack("enemy");
|
||||||
|
alice_copy.takeDamage(15);
|
||||||
|
alice_copy.attack("the sun");
|
||||||
|
for(int i = 0; i < 10; i++)
|
||||||
|
alice_copy.beRepaired(1);
|
||||||
|
alice_copy.attack("the moon");
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: default_claptrap" << COLOR_RESET << std::endl;
|
||||||
|
default_claptrap.attack("enemy");
|
||||||
|
default_claptrap.takeDamage(5);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
||||||
|
}
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/28 11:32:48 by whaffman #+# #+# */
|
/* Created: 2025/03/28 11:32:48 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 16:21:49 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 10:19:00 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,37 +20,38 @@ ScavTrap::ScavTrap() : ClapTrap(), _guard_mode(false)
|
|||||||
_energy_points = 50;
|
_energy_points = 50;
|
||||||
_attack_damage = 20;
|
_attack_damage = 20;
|
||||||
|
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _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)
|
ScavTrap::ScavTrap(std::string name) : ClapTrap(name), _guard_mode(false)
|
||||||
{
|
{
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _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)
|
ScavTrap::ScavTrap(ScavTrap const &src) : ClapTrap(src)
|
||||||
{
|
{
|
||||||
*this = src;
|
_guard_mode = src._guard_mode;
|
||||||
|
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _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()
|
ScavTrap::~ScavTrap()
|
||||||
{
|
{
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
status();
|
||||||
|
std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScavTrap &ScavTrap::operator=(ScavTrap const &rhs)
|
ScavTrap &ScavTrap::operator=(ScavTrap const &other)
|
||||||
{
|
{
|
||||||
if (this == &rhs)
|
if (this == &other)
|
||||||
return (*this);
|
return (*this);
|
||||||
|
|
||||||
_name = rhs._name;
|
_name = other._name;
|
||||||
_hitpoints = rhs._hitpoints;
|
_hitpoints = other._hitpoints;
|
||||||
_energy_points = rhs._energy_points;
|
_energy_points = other._energy_points;
|
||||||
_attack_damage = rhs._attack_damage;
|
_attack_damage = other._attack_damage;
|
||||||
|
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created by assignment operator" << std::endl;
|
std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " has been created by assignment operator" << std::endl;
|
||||||
|
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
@ -79,15 +80,58 @@ void ScavTrap::guardGate()
|
|||||||
{
|
{
|
||||||
_guard_mode = true;
|
_guard_mode = true;
|
||||||
|
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " is in Gate keeper mode" << std::endl;
|
std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " is in Gate keeper mode" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScavTrap::status() const
|
void ScavTrap::status() const
|
||||||
{
|
{
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR10 << _name << " has " << _hitpoints << " hitpoints, "
|
std::cout << COLOR13 << "ScavTrap " << COLOR10 << _name << " has " << _hitpoints << " hitpoints, "
|
||||||
<< _energy_points << " energy points, " << _attack_damage << " attack damage ";
|
<< _energy_points << " energy points, " << _attack_damage << " attack damage ";
|
||||||
if (_guard_mode)
|
if (_guard_mode)
|
||||||
std::cout << "and is in Gate keeper mode" << COLOR_RESET << std::endl;
|
std::cout << "and is in Gate keeper mode" << COLOR_RESET << std::endl;
|
||||||
else
|
else
|
||||||
std::cout << "and is not in Gate keeper mode" << COLOR_RESET << std::endl;
|
std::cout << "and is not in Gate keeper mode" << COLOR_RESET << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void scavtrap_test()
|
||||||
|
{
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR9 << "ScavTrap 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 << "ScavTrap Bob with parameter constructor" << COLOR_RESET << std::endl;
|
||||||
|
ScavTrap bob("Bob");
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Scavtrap bob_copy with copy constructor of Bob" << COLOR_RESET << std::endl;
|
||||||
|
ScavTrap bob_copy(bob);
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_scavtrap with default constructor" << COLOR_RESET << std::endl;
|
||||||
|
ScavTrap default_scavtrap;
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_scavtrap = bob" << COLOR_RESET << std::endl;
|
||||||
|
default_scavtrap = bob;
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: bob" << COLOR_RESET << std::endl;
|
||||||
|
bob.attack("enemy");
|
||||||
|
bob.takeDamage(5);
|
||||||
|
bob.beRepaired(3);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: bob_copy" << COLOR_RESET << std::endl;
|
||||||
|
bob_copy.attack("enemy");
|
||||||
|
bob_copy.takeDamage(15);
|
||||||
|
bob_copy.attack("the sun");
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
bob_copy.beRepaired(1);
|
||||||
|
bob_copy.attack("the moon");
|
||||||
|
bob_copy.guardGate();
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: default_scavtrap" << COLOR_RESET << std::endl;
|
||||||
|
default_scavtrap.attack("enemy");
|
||||||
|
default_scavtrap.takeDamage(5);
|
||||||
|
default_scavtrap.guardGate();
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
||||||
}
|
}
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/28 11:35:59 by whaffman #+# #+# */
|
/* Created: 2025/03/28 11:35:59 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 22:39:55 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 09:26:25 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,86 +14,17 @@
|
|||||||
#include "ClapTrap.hpp"
|
#include "ClapTrap.hpp"
|
||||||
#include "ScavTrap.hpp"
|
#include "ScavTrap.hpp"
|
||||||
|
|
||||||
void claptrap_test()
|
|
||||||
{
|
|
||||||
std::cout << COLOR9 << "ClapTrap tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "ClapTrap Alice with parameter constructor" << COLOR_RESET << std::endl;
|
|
||||||
ClapTrap alice("Alice");
|
|
||||||
std::cout << COLOR10 << "Claptrap alice_copy with copy constructor of Alice" << COLOR_RESET << std::endl;
|
|
||||||
ClapTrap alice_copy(alice);
|
|
||||||
std::cout << COLOR10 << "default_claptrap with default constructor" << COLOR_RESET << std::endl;
|
|
||||||
ClapTrap default_claptrap;
|
|
||||||
std::cout << COLOR10 << "default_claptrap = alice" << COLOR_RESET << std::endl;
|
|
||||||
default_claptrap = alice;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: alice" << COLOR_RESET << std::endl;
|
|
||||||
alice.attack("enemy");
|
|
||||||
alice.takeDamage(5);
|
|
||||||
alice.beRepaired(3);
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: alice_copy" << COLOR_RESET << std::endl;
|
|
||||||
alice_copy.attack("enemy");
|
|
||||||
alice_copy.takeDamage(15);
|
|
||||||
alice_copy.attack("the sun");
|
|
||||||
for(int i = 0; i < 10; i++)
|
|
||||||
alice_copy.beRepaired(1);
|
|
||||||
alice_copy.attack("the moon");
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: default_claptrap" << COLOR_RESET << std::endl;
|
|
||||||
default_claptrap.attack("enemy");
|
|
||||||
default_claptrap.takeDamage(5);
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void scavtrap_test()
|
|
||||||
{
|
|
||||||
std::cout << COLOR9 << "ScavTrap tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "ScavTrap Bob with parameter constructor" << COLOR_RESET << std::endl;
|
|
||||||
ScavTrap bob("Bob");
|
|
||||||
std::cout << COLOR10 << "Scavtrap bob_copy with copy constructor of Bob" << COLOR_RESET << std::endl;
|
|
||||||
ScavTrap bob_copy(bob);
|
|
||||||
std::cout << COLOR10 << "default_scavtrap with default constructor" << COLOR_RESET << std::endl;
|
|
||||||
ScavTrap default_scavtrap;
|
|
||||||
std::cout << COLOR10 << "default_scavtrap = bob" << COLOR_RESET << std::endl;
|
|
||||||
default_scavtrap = bob;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: bob" << COLOR_RESET << std::endl;
|
|
||||||
bob.attack("enemy");
|
|
||||||
bob.takeDamage(5);
|
|
||||||
bob.beRepaired(3);
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: bob_copy" << COLOR_RESET << std::endl;
|
|
||||||
bob_copy.attack("enemy");
|
|
||||||
bob_copy.takeDamage(15);
|
|
||||||
bob_copy.attack("the sun");
|
|
||||||
for(int i = 0; i < 10; i++)
|
|
||||||
bob_copy.beRepaired(1);
|
|
||||||
bob_copy.attack("the moon");
|
|
||||||
bob_copy.guardGate();
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: default_scavtrap" << COLOR_RESET << std::endl;
|
|
||||||
default_scavtrap.attack("enemy");
|
|
||||||
default_scavtrap.takeDamage(5);
|
|
||||||
default_scavtrap.guardGate();
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::cout << "Starting tests..." << std::endl;
|
std::cout << "Starting tests..." << std::endl;
|
||||||
claptrap_test();
|
claptrap_test();
|
||||||
|
std::cout << std::endl << std::endl;
|
||||||
scavtrap_test();
|
scavtrap_test();
|
||||||
std::cout << COLOR9 << "All tests completed" << COLOR_RESET << std::endl;
|
std::cout << COLOR9 << "All tests completed" << COLOR_RESET << std::endl;
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -6,11 +6,11 @@
|
|||||||
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
||||||
# +#+ #
|
# +#+ #
|
||||||
# Created: 2025/03/24 15:14:58 by whaffman #+# #+# #
|
# Created: 2025/03/24 15:14:58 by whaffman #+# #+# #
|
||||||
# Updated: 2025/03/28 15:52:22 by whaffman ######## odam.nl #
|
# Updated: 2025/04/08 09:28:54 by whaffman ######## odam.nl #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
NAME= FragTrap
|
NAME= ClapTrap
|
||||||
SRC= FragTrap.cpp main.cpp ScavTrap.cpp ClapTrap.cpp
|
SRC= FragTrap.cpp main.cpp ScavTrap.cpp ClapTrap.cpp
|
||||||
|
|
||||||
-include ../common.mk
|
-include ../common.mk
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/27 16:26:32 by whaffman #+# #+# */
|
/* Created: 2025/03/27 16:26:32 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 15:49:00 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 10:19:00 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#define BOLD_UNDERLINE "\033[1;4m"
|
||||||
|
|
||||||
#define COLOR0 "\033[38;5;0m"
|
#define COLOR0 "\033[38;5;0m"
|
||||||
#define COLOR1 "\033[38;5;1m"
|
#define COLOR1 "\033[38;5;1m"
|
||||||
#define COLOR2 "\033[38;5;2m"
|
#define COLOR2 "\033[38;5;2m"
|
||||||
@ -32,8 +34,6 @@
|
|||||||
#define COLOR15 "\033[38;5;15m"
|
#define COLOR15 "\033[38;5;15m"
|
||||||
#define COLOR_RESET "\033[m"
|
#define COLOR_RESET "\033[m"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ClapTrap
|
class ClapTrap
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
@ -48,10 +48,12 @@ public:
|
|||||||
ClapTrap(ClapTrap const &src);
|
ClapTrap(ClapTrap const &src);
|
||||||
~ClapTrap();
|
~ClapTrap();
|
||||||
|
|
||||||
ClapTrap &operator=(ClapTrap const &rhs);
|
ClapTrap &operator=(ClapTrap const &other);
|
||||||
|
|
||||||
void status() const;
|
void status() const;
|
||||||
void attack(std::string const &target);
|
void attack(std::string const &target);
|
||||||
void takeDamage(unsigned int amount);
|
void takeDamage(unsigned int amount);
|
||||||
void beRepaired(unsigned int amount);
|
void beRepaired(unsigned int amount);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void claptrap_test();
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/28 15:44:08 by whaffman #+# #+# */
|
/* Created: 2025/03/28 15:44:08 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 17:26:42 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 10:19:00 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -23,8 +23,10 @@ public:
|
|||||||
FragTrap(FragTrap const &src);
|
FragTrap(FragTrap const &src);
|
||||||
~FragTrap();
|
~FragTrap();
|
||||||
|
|
||||||
FragTrap &operator=(FragTrap const &rhs);
|
FragTrap &operator=(FragTrap const &other);
|
||||||
|
|
||||||
void highFivesGuys(void);
|
void highFivesGuys(void);
|
||||||
void status(void) const;
|
void status(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void fragtrap_test();
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/28 11:28:29 by whaffman #+# #+# */
|
/* Created: 2025/03/28 11:28:29 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 16:19:46 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 10:19:00 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,9 +26,11 @@ public:
|
|||||||
ScavTrap(ScavTrap const &src);
|
ScavTrap(ScavTrap const &src);
|
||||||
~ScavTrap();
|
~ScavTrap();
|
||||||
|
|
||||||
ScavTrap &operator=(ScavTrap const &rhs);
|
ScavTrap &operator=(ScavTrap const &other);
|
||||||
|
|
||||||
void attack(std::string const &target);
|
void attack(std::string const &target);
|
||||||
void guardGate();
|
void guardGate();
|
||||||
void status() const;
|
void status() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void scavtrap_test();
|
||||||
@ -4,7 +4,7 @@
|
|||||||
ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0)
|
ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0)
|
||||||
{
|
{
|
||||||
_name = "Noname";
|
_name = "Noname";
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created!" << std::endl;
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created! Lets call it \"Noname\"" << std::endl;
|
||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,31 +14,35 @@ ClapTrap::ClapTrap(std::string name) : _name(name), _hitpoints(10), _energy_poin
|
|||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClapTrap::ClapTrap(ClapTrap const &src)
|
ClapTrap::ClapTrap(ClapTrap const &other)
|
||||||
{
|
{
|
||||||
|
_name = other._name;
|
||||||
|
_hitpoints = other._hitpoints;
|
||||||
|
_energy_points = other._energy_points;
|
||||||
|
_attack_damage = other._attack_damage;
|
||||||
|
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is copied!" << std::endl;
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is copied!" << std::endl;
|
||||||
*this = src;
|
|
||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClapTrap::~ClapTrap()
|
ClapTrap::~ClapTrap()
|
||||||
{
|
{
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl;
|
|
||||||
status();
|
status();
|
||||||
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClapTrap &ClapTrap::operator=(ClapTrap const &rhs)
|
ClapTrap &ClapTrap::operator=(ClapTrap const &other)
|
||||||
{
|
{
|
||||||
if (this == &rhs)
|
if (this == &other)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << rhs._name
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << other._name
|
||||||
<< " is assigned to ClapTrap formely known as " << _name << "!"
|
<< " is assigned to ClapTrap formely known as " << _name << "!"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
_name = rhs._name;
|
_name = other._name;
|
||||||
_hitpoints = rhs._hitpoints;
|
_hitpoints = other._hitpoints;
|
||||||
_energy_points = rhs._energy_points;
|
_energy_points = other._energy_points;
|
||||||
_attack_damage = rhs._attack_damage;
|
_attack_damage = other._attack_damage;
|
||||||
status();
|
status();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -91,3 +95,43 @@ void ClapTrap::status() const
|
|||||||
<< _energy_points << " energy points and " << _attack_damage
|
<< _energy_points << " energy points and " << _attack_damage
|
||||||
<< " attack damage!" << COLOR_RESET << std::endl;
|
<< " attack damage!" << COLOR_RESET << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void claptrap_test()
|
||||||
|
{
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR1 << "ClapTrap tests:" << COLOR_RESET << std::endl << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "ClapTrap Alice with parameter constructor" << COLOR_RESET << std::endl;
|
||||||
|
ClapTrap alice("Alice");
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "ClapTrap alice_copy with copy constructor of Alice" << COLOR_RESET << std::endl;
|
||||||
|
ClapTrap alice_copy(alice);
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_claptrap with default constructor" << COLOR_RESET << std::endl;
|
||||||
|
ClapTrap default_claptrap;
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_claptrap = alice" << COLOR_RESET << std::endl;
|
||||||
|
default_claptrap = alice;
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: alice" << COLOR_RESET << std::endl;
|
||||||
|
alice.attack("enemy");
|
||||||
|
alice.takeDamage(5);
|
||||||
|
alice.beRepaired(3);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: alice_copy" << COLOR_RESET << std::endl;
|
||||||
|
alice_copy.attack("enemy");
|
||||||
|
alice_copy.takeDamage(15);
|
||||||
|
alice_copy.attack("the sun");
|
||||||
|
for(int i = 0; i < 10; i++)
|
||||||
|
alice_copy.beRepaired(1);
|
||||||
|
alice_copy.attack("the moon");
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: default_claptrap" << COLOR_RESET << std::endl;
|
||||||
|
default_claptrap.attack("enemy");
|
||||||
|
default_claptrap.takeDamage(5);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
||||||
|
}
|
||||||
@ -14,26 +14,26 @@ FragTrap::FragTrap(std::string name) : ClapTrap(name)
|
|||||||
|
|
||||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||||
}
|
}
|
||||||
FragTrap::FragTrap(FragTrap const &src)
|
FragTrap::FragTrap(FragTrap const &src) : ClapTrap(src)
|
||||||
{
|
{
|
||||||
*this = src;
|
|
||||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _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()
|
FragTrap::~FragTrap()
|
||||||
{
|
{
|
||||||
|
status();
|
||||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
FragTrap &FragTrap::operator=(FragTrap const &rhs)
|
FragTrap &FragTrap::operator=(FragTrap const &other)
|
||||||
{
|
{
|
||||||
if (this == &rhs)
|
if (this == &other)
|
||||||
return (*this);
|
return (*this);
|
||||||
|
|
||||||
_name = rhs._name;
|
_name = other._name;
|
||||||
_hitpoints = rhs._hitpoints;
|
_hitpoints = other._hitpoints;
|
||||||
_energy_points = rhs._energy_points;
|
_energy_points = other._energy_points;
|
||||||
_attack_damage = rhs._attack_damage;
|
_attack_damage = other._attack_damage;
|
||||||
|
|
||||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created by assignation operator" << std::endl;
|
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created by assignation operator" << std::endl;
|
||||||
|
|
||||||
@ -49,5 +49,48 @@ void FragTrap::status(void) const
|
|||||||
{
|
{
|
||||||
std::cout << COLOR14 << "FragTrap " << COLOR10 << _name << " has " << _hitpoints
|
std::cout << COLOR14 << "FragTrap " << COLOR10 << _name << " has " << _hitpoints
|
||||||
<< " hitpoints, " << _energy_points << " energy points and "
|
<< " hitpoints, " << _energy_points << " energy points and "
|
||||||
<< _attack_damage << " attack damage." << std::endl;
|
<< _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;
|
||||||
}
|
}
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/28 11:32:48 by whaffman #+# #+# */
|
/* Created: 2025/03/28 11:32:48 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 16:21:49 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 10:19:00 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,37 +20,38 @@ ScavTrap::ScavTrap() : ClapTrap(), _guard_mode(false)
|
|||||||
_energy_points = 50;
|
_energy_points = 50;
|
||||||
_attack_damage = 20;
|
_attack_damage = 20;
|
||||||
|
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _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)
|
ScavTrap::ScavTrap(std::string name) : ClapTrap(name), _guard_mode(false)
|
||||||
{
|
{
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _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)
|
ScavTrap::ScavTrap(ScavTrap const &src) : ClapTrap(src)
|
||||||
{
|
{
|
||||||
*this = src;
|
_guard_mode = src._guard_mode;
|
||||||
|
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _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()
|
ScavTrap::~ScavTrap()
|
||||||
{
|
{
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
status();
|
||||||
|
std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScavTrap &ScavTrap::operator=(ScavTrap const &rhs)
|
ScavTrap &ScavTrap::operator=(ScavTrap const &other)
|
||||||
{
|
{
|
||||||
if (this == &rhs)
|
if (this == &other)
|
||||||
return (*this);
|
return (*this);
|
||||||
|
|
||||||
_name = rhs._name;
|
_name = other._name;
|
||||||
_hitpoints = rhs._hitpoints;
|
_hitpoints = other._hitpoints;
|
||||||
_energy_points = rhs._energy_points;
|
_energy_points = other._energy_points;
|
||||||
_attack_damage = rhs._attack_damage;
|
_attack_damage = other._attack_damage;
|
||||||
|
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created by assignment operator" << std::endl;
|
std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " has been created by assignment operator" << std::endl;
|
||||||
|
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
@ -79,15 +80,58 @@ void ScavTrap::guardGate()
|
|||||||
{
|
{
|
||||||
_guard_mode = true;
|
_guard_mode = true;
|
||||||
|
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " is in Gate keeper mode" << std::endl;
|
std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " is in Gate keeper mode" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScavTrap::status() const
|
void ScavTrap::status() const
|
||||||
{
|
{
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR10 << _name << " has " << _hitpoints << " hitpoints, "
|
std::cout << COLOR13 << "ScavTrap " << COLOR10 << _name << " has " << _hitpoints << " hitpoints, "
|
||||||
<< _energy_points << " energy points, " << _attack_damage << " attack damage ";
|
<< _energy_points << " energy points, " << _attack_damage << " attack damage ";
|
||||||
if (_guard_mode)
|
if (_guard_mode)
|
||||||
std::cout << "and is in Gate keeper mode" << COLOR_RESET << std::endl;
|
std::cout << "and is in Gate keeper mode" << COLOR_RESET << std::endl;
|
||||||
else
|
else
|
||||||
std::cout << "and is not in Gate keeper mode" << COLOR_RESET << std::endl;
|
std::cout << "and is not in Gate keeper mode" << COLOR_RESET << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void scavtrap_test()
|
||||||
|
{
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR9 << "ScavTrap 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 << "ScavTrap Bob with parameter constructor" << COLOR_RESET << std::endl;
|
||||||
|
ScavTrap bob("Bob");
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Scavtrap bob_copy with copy constructor of Bob" << COLOR_RESET << std::endl;
|
||||||
|
ScavTrap bob_copy(bob);
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_scavtrap with default constructor" << COLOR_RESET << std::endl;
|
||||||
|
ScavTrap default_scavtrap;
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_scavtrap = bob" << COLOR_RESET << std::endl;
|
||||||
|
default_scavtrap = bob;
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: bob" << COLOR_RESET << std::endl;
|
||||||
|
bob.attack("enemy");
|
||||||
|
bob.takeDamage(5);
|
||||||
|
bob.beRepaired(3);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: bob_copy" << COLOR_RESET << std::endl;
|
||||||
|
bob_copy.attack("enemy");
|
||||||
|
bob_copy.takeDamage(15);
|
||||||
|
bob_copy.attack("the sun");
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
bob_copy.beRepaired(1);
|
||||||
|
bob_copy.attack("the moon");
|
||||||
|
bob_copy.guardGate();
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: default_scavtrap" << COLOR_RESET << std::endl;
|
||||||
|
default_scavtrap.attack("enemy");
|
||||||
|
default_scavtrap.takeDamage(5);
|
||||||
|
default_scavtrap.guardGate();
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
||||||
}
|
}
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/28 11:35:59 by whaffman #+# #+# */
|
/* Created: 2025/03/28 11:35:59 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 22:41:10 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 09:39:38 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -15,125 +15,20 @@
|
|||||||
#include "ScavTrap.hpp"
|
#include "ScavTrap.hpp"
|
||||||
#include "FragTrap.hpp"
|
#include "FragTrap.hpp"
|
||||||
|
|
||||||
void claptrap_test()
|
|
||||||
{
|
|
||||||
std::cout << COLOR9 << "ClapTrap tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "ClapTrap Alice with parameter constructor" << COLOR_RESET << std::endl;
|
|
||||||
ClapTrap alice("Alice");
|
|
||||||
std::cout << COLOR10 << "Claptrap alice_copy with copy constructor of Alice" << COLOR_RESET << std::endl;
|
|
||||||
ClapTrap alice_copy(alice);
|
|
||||||
std::cout << COLOR10 << "default_claptrap with default constructor" << COLOR_RESET << std::endl;
|
|
||||||
ClapTrap default_claptrap;
|
|
||||||
std::cout << COLOR10 << "default_claptrap = alice" << COLOR_RESET << std::endl;
|
|
||||||
default_claptrap = alice;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: alice" << COLOR_RESET << std::endl;
|
|
||||||
alice.attack("enemy");
|
|
||||||
alice.takeDamage(5);
|
|
||||||
alice.beRepaired(3);
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: alice_copy" << COLOR_RESET << std::endl;
|
|
||||||
alice_copy.attack("enemy");
|
|
||||||
alice_copy.takeDamage(15);
|
|
||||||
alice_copy.attack("the sun");
|
|
||||||
for(int i = 0; i < 10; i++)
|
|
||||||
alice_copy.beRepaired(1);
|
|
||||||
alice_copy.attack("the moon");
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: default_claptrap" << COLOR_RESET << std::endl;
|
|
||||||
default_claptrap.attack("enemy");
|
|
||||||
default_claptrap.takeDamage(5);
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void scavtrap_test()
|
|
||||||
{
|
|
||||||
std::cout << COLOR9 << "ScavTrap tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "ScavTrap Bob with parameter constructor" << COLOR_RESET << std::endl;
|
|
||||||
ScavTrap bob("Bob");
|
|
||||||
std::cout << COLOR10 << "Scavtrap bob_copy with copy constructor of Bob" << COLOR_RESET << std::endl;
|
|
||||||
ScavTrap bob_copy(bob);
|
|
||||||
std::cout << COLOR10 << "default_scavtrap with default constructor" << COLOR_RESET << std::endl;
|
|
||||||
ScavTrap default_scavtrap;
|
|
||||||
std::cout << COLOR10 << "default_scavtrap = bob" << COLOR_RESET << std::endl;
|
|
||||||
default_scavtrap = bob;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: bob" << COLOR_RESET << std::endl;
|
|
||||||
bob.attack("enemy");
|
|
||||||
bob.takeDamage(5);
|
|
||||||
bob.beRepaired(3);
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: bob_copy" << COLOR_RESET << std::endl;
|
|
||||||
bob_copy.attack("enemy");
|
|
||||||
bob_copy.takeDamage(15);
|
|
||||||
bob_copy.attack("the sun");
|
|
||||||
for(int i = 0; i < 10; i++)
|
|
||||||
bob_copy.beRepaired(1);
|
|
||||||
bob_copy.attack("the moon");
|
|
||||||
bob_copy.guardGate();
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: default_scavtrap" << COLOR_RESET << std::endl;
|
|
||||||
default_scavtrap.attack("enemy");
|
|
||||||
default_scavtrap.takeDamage(5);
|
|
||||||
default_scavtrap.guardGate();
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fragtrap_test()
|
|
||||||
{
|
|
||||||
std::cout << COLOR9 << "FragTrap tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "FragTrap Charlie with parameter constructor" << COLOR_RESET << std::endl;
|
|
||||||
FragTrap charlie("Charlie");
|
|
||||||
std::cout << COLOR10 << "Fragtrap charlie_copy with copy constructor of Charlie" << COLOR_RESET << std::endl;
|
|
||||||
FragTrap charlie_copy(charlie);
|
|
||||||
std::cout << COLOR10 << "default_fragtrap with default constructor" << COLOR_RESET << std::endl;
|
|
||||||
FragTrap default_fragtrap;
|
|
||||||
std::cout << COLOR10 << "default_fragtrap = charlie" << COLOR_RESET << std::endl;
|
|
||||||
default_fragtrap = charlie;
|
|
||||||
|
|
||||||
std::cout << 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 << 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 << 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 << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::cout << "Starting tests..." << std::endl;
|
std::cout << "Starting tests..." << std::endl;
|
||||||
claptrap_test();
|
claptrap_test();
|
||||||
|
std::cout << std::endl << std::endl;
|
||||||
|
|
||||||
scavtrap_test();
|
scavtrap_test();
|
||||||
|
std::cout << std::endl << std::endl;
|
||||||
|
|
||||||
fragtrap_test();
|
fragtrap_test();
|
||||||
|
std::cout << std::endl << std::endl;
|
||||||
std::cout << COLOR9 << "All tests completed!" << COLOR_RESET << std::endl;
|
std::cout << COLOR9 << "All tests completed!" << COLOR_RESET << std::endl;
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -6,11 +6,11 @@
|
|||||||
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
# By: whaffman <whaffman@student.codam.nl> +#+ #
|
||||||
# +#+ #
|
# +#+ #
|
||||||
# Created: 2025/03/24 15:14:58 by whaffman #+# #+# #
|
# Created: 2025/03/24 15:14:58 by whaffman #+# #+# #
|
||||||
# Updated: 2025/04/07 17:21:50 by whaffman ######## odam.nl #
|
# Updated: 2025/04/08 09:36:20 by whaffman ######## odam.nl #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
NAME= DiamondTrap
|
NAME= ClapTrap
|
||||||
SRC= main.cpp ClapTrap.cpp ScavTrap.cpp FragTrap.cpp DiamondTrap.cpp
|
SRC= main.cpp ClapTrap.cpp ScavTrap.cpp FragTrap.cpp DiamondTrap.cpp
|
||||||
|
|
||||||
-include ../common.mk
|
-include ../common.mk
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/27 16:26:32 by whaffman #+# #+# */
|
/* Created: 2025/03/27 16:26:32 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 15:49:00 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 10:19:00 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#define BOLD_UNDERLINE "\033[1;4m"
|
||||||
|
|
||||||
#define COLOR0 "\033[38;5;0m"
|
#define COLOR0 "\033[38;5;0m"
|
||||||
#define COLOR1 "\033[38;5;1m"
|
#define COLOR1 "\033[38;5;1m"
|
||||||
#define COLOR2 "\033[38;5;2m"
|
#define COLOR2 "\033[38;5;2m"
|
||||||
@ -32,8 +34,6 @@
|
|||||||
#define COLOR15 "\033[38;5;15m"
|
#define COLOR15 "\033[38;5;15m"
|
||||||
#define COLOR_RESET "\033[m"
|
#define COLOR_RESET "\033[m"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ClapTrap
|
class ClapTrap
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
@ -48,10 +48,12 @@ public:
|
|||||||
ClapTrap(ClapTrap const &src);
|
ClapTrap(ClapTrap const &src);
|
||||||
~ClapTrap();
|
~ClapTrap();
|
||||||
|
|
||||||
ClapTrap &operator=(ClapTrap const &rhs);
|
ClapTrap &operator=(ClapTrap const &other);
|
||||||
|
|
||||||
void status() const;
|
void status() const;
|
||||||
void attack(std::string const &target);
|
void attack(std::string const &target);
|
||||||
void takeDamage(unsigned int amount);
|
void takeDamage(unsigned int amount);
|
||||||
void beRepaired(unsigned int amount);
|
void beRepaired(unsigned int amount);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void claptrap_test();
|
||||||
@ -6,11 +6,12 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/04/07 17:02:52 by whaffman #+# #+# */
|
/* Created: 2025/04/07 17:02:52 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 17:37:06 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 10:19:00 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <string>
|
||||||
#include "FragTrap.hpp"
|
#include "FragTrap.hpp"
|
||||||
#include "ScavTrap.hpp"
|
#include "ScavTrap.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -27,8 +28,10 @@ public:
|
|||||||
DiamondTrap(DiamondTrap const &src);
|
DiamondTrap(DiamondTrap const &src);
|
||||||
~DiamondTrap();
|
~DiamondTrap();
|
||||||
|
|
||||||
DiamondTrap &operator=(DiamondTrap const &rhs);
|
DiamondTrap &operator=(DiamondTrap const &other);
|
||||||
|
|
||||||
void whoAmI(void);
|
void whoAmI(void);
|
||||||
void status(void) const;
|
void status(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void diamondtrap_test();
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/28 15:44:08 by whaffman #+# #+# */
|
/* Created: 2025/03/28 15:44:08 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 17:28:32 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 10:19:00 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -23,8 +23,10 @@ public:
|
|||||||
FragTrap(FragTrap const &src);
|
FragTrap(FragTrap const &src);
|
||||||
~FragTrap();
|
~FragTrap();
|
||||||
|
|
||||||
FragTrap &operator=(FragTrap const &rhs);
|
FragTrap &operator=(FragTrap const &other);
|
||||||
|
|
||||||
void highFivesGuys(void);
|
void highFivesGuys(void);
|
||||||
void status(void) const;
|
void status(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void fragtrap_test();
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/28 11:28:29 by whaffman #+# #+# */
|
/* Created: 2025/03/28 11:28:29 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 17:06:59 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 10:19:00 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,9 +26,11 @@ public:
|
|||||||
ScavTrap(ScavTrap const &src);
|
ScavTrap(ScavTrap const &src);
|
||||||
~ScavTrap();
|
~ScavTrap();
|
||||||
|
|
||||||
ScavTrap &operator=(ScavTrap const &rhs);
|
ScavTrap &operator=(ScavTrap const &other);
|
||||||
|
|
||||||
void attack(std::string const &target);
|
void attack(std::string const &target);
|
||||||
void guardGate();
|
void guardGate();
|
||||||
void status() const;
|
void status() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void scavtrap_test();
|
||||||
@ -4,7 +4,7 @@
|
|||||||
ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0)
|
ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0)
|
||||||
{
|
{
|
||||||
_name = "Noname";
|
_name = "Noname";
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created!" << std::endl;
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created! Lets call it \"Noname\"" << std::endl;
|
||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,36 +14,35 @@ ClapTrap::ClapTrap(std::string name) : _name(name), _hitpoints(10), _energy_poin
|
|||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClapTrap::ClapTrap(ClapTrap const &src)
|
ClapTrap::ClapTrap(ClapTrap const &other)
|
||||||
{
|
{
|
||||||
_name = src._name;
|
_name = other._name;
|
||||||
_hitpoints = src._hitpoints;
|
_hitpoints = other._hitpoints;
|
||||||
_energy_points = src._energy_points;
|
_energy_points = other._energy_points;
|
||||||
_attack_damage = src._attack_damage;
|
_attack_damage = other._attack_damage;
|
||||||
|
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is copied!" << std::endl;
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is copied!" << std::endl;
|
||||||
|
|
||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClapTrap::~ClapTrap()
|
ClapTrap::~ClapTrap()
|
||||||
{
|
{
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl;
|
|
||||||
status();
|
status();
|
||||||
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClapTrap &ClapTrap::operator=(ClapTrap const &rhs)
|
ClapTrap &ClapTrap::operator=(ClapTrap const &other)
|
||||||
{
|
{
|
||||||
if (this == &rhs)
|
if (this == &other)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << rhs._name
|
std::cout << COLOR12 << "Claptrap " << COLOR_RESET << other._name
|
||||||
<< " is assigned to ClapTrap formely known as " << _name << "!"
|
<< " is assigned to ClapTrap formely known as " << _name << "!"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
_name = rhs._name;
|
_name = other._name;
|
||||||
_hitpoints = rhs._hitpoints;
|
_hitpoints = other._hitpoints;
|
||||||
_energy_points = rhs._energy_points;
|
_energy_points = other._energy_points;
|
||||||
_attack_damage = rhs._attack_damage;
|
_attack_damage = other._attack_damage;
|
||||||
status();
|
status();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -96,3 +95,43 @@ void ClapTrap::status() const
|
|||||||
<< _energy_points << " energy points and " << _attack_damage
|
<< _energy_points << " energy points and " << _attack_damage
|
||||||
<< " attack damage!" << COLOR_RESET << std::endl;
|
<< " attack damage!" << COLOR_RESET << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void claptrap_test()
|
||||||
|
{
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR1 << "ClapTrap tests:" << COLOR_RESET << std::endl << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "ClapTrap Alice with parameter constructor" << COLOR_RESET << std::endl;
|
||||||
|
ClapTrap alice("Alice");
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "ClapTrap alice_copy with copy constructor of Alice" << COLOR_RESET << std::endl;
|
||||||
|
ClapTrap alice_copy(alice);
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_claptrap with default constructor" << COLOR_RESET << std::endl;
|
||||||
|
ClapTrap default_claptrap;
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_claptrap = alice" << COLOR_RESET << std::endl;
|
||||||
|
default_claptrap = alice;
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: alice" << COLOR_RESET << std::endl;
|
||||||
|
alice.attack("enemy");
|
||||||
|
alice.takeDamage(5);
|
||||||
|
alice.beRepaired(3);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: alice_copy" << COLOR_RESET << std::endl;
|
||||||
|
alice_copy.attack("enemy");
|
||||||
|
alice_copy.takeDamage(15);
|
||||||
|
alice_copy.attack("the sun");
|
||||||
|
for(int i = 0; i < 10; i++)
|
||||||
|
alice_copy.beRepaired(1);
|
||||||
|
alice_copy.attack("the moon");
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: default_claptrap" << COLOR_RESET << std::endl;
|
||||||
|
default_claptrap.attack("enemy");
|
||||||
|
default_claptrap.takeDamage(5);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
||||||
|
}
|
||||||
@ -11,7 +11,7 @@ DiamondTrap::DiamondTrap() : ClapTrap("NoName"), _name("NoName")
|
|||||||
_energy_points = ScavTrap::_energy_points;
|
_energy_points = ScavTrap::_energy_points;
|
||||||
_attack_damage = FragTrap::_attack_damage;
|
_attack_damage = FragTrap::_attack_damage;
|
||||||
|
|
||||||
std::cout << COLOR11 << "Diamondtrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
std::cout << COLOR11 << "DiamondTrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ DiamondTrap::DiamondTrap(std::string name) : ClapTrap(name + "_clap_name"), _nam
|
|||||||
_energy_points = ScavTrap::_energy_points;
|
_energy_points = ScavTrap::_energy_points;
|
||||||
_attack_damage = FragTrap::_attack_damage;
|
_attack_damage = FragTrap::_attack_damage;
|
||||||
|
|
||||||
std::cout << COLOR11 << "Diamondtrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
std::cout << COLOR11 << "DiamondTrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,41 +29,87 @@ DiamondTrap::DiamondTrap(DiamondTrap const &src) : ClapTrap(src), FragTrap(src),
|
|||||||
{
|
{
|
||||||
_name = src._name;
|
_name = src._name;
|
||||||
|
|
||||||
std::cout << COLOR11 << "Diamondtrap " << COLOR_RESET << _name << " has been created by copy constructor" << std::endl;
|
std::cout << COLOR11 << "DiamondTrap " << COLOR_RESET << _name << " has been created by copy constructor" << std::endl;
|
||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DiamondTrap::~DiamondTrap()
|
DiamondTrap::~DiamondTrap()
|
||||||
{
|
{
|
||||||
std::cout << COLOR11 << "Diamondtrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
|
||||||
status();
|
status();
|
||||||
|
std::cout << COLOR11 << "DiamondTrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiamondTrap &DiamondTrap::operator=(DiamondTrap const &rhs)
|
DiamondTrap &DiamondTrap::operator=(DiamondTrap const &other)
|
||||||
{
|
{
|
||||||
if (this == &rhs)
|
if (this == &other)
|
||||||
return (*this);
|
return (*this);
|
||||||
_name = rhs._name;
|
_name = other._name;
|
||||||
_hitpoints = rhs._hitpoints;
|
_hitpoints = other._hitpoints;
|
||||||
_energy_points = rhs._energy_points;
|
_energy_points = other._energy_points;
|
||||||
_attack_damage = rhs._attack_damage;
|
_attack_damage = other._attack_damage;
|
||||||
ClapTrap::_name = rhs.ClapTrap::_name;
|
ClapTrap::_name = other.ClapTrap::_name;
|
||||||
std::cout << COLOR11 << "Diamondtrap " << COLOR_RESET << _name << " has been created by assignment operator" << std::endl;
|
std::cout << COLOR11 << "DiamondTrap " << COLOR_RESET << _name << " has been created by assignment operator" << std::endl;
|
||||||
status();
|
status();
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiamondTrap::whoAmI(void)
|
void DiamondTrap::whoAmI(void)
|
||||||
{
|
{
|
||||||
std::cout << COLOR11 << "Diamondtrap " << COLOR_RESET
|
std::cout << COLOR11 << "DiamondTrap " << COLOR_RESET
|
||||||
<< "I am " << _name << ", but my ClapTRap friends call me: "
|
<< "I am " << _name << ", but my ClapTrap friends call me: "
|
||||||
<< ClapTrap::_name << std::endl;
|
<< ClapTrap::_name << std::endl;
|
||||||
status();
|
status();
|
||||||
}
|
}
|
||||||
void DiamondTrap::status() const
|
void DiamondTrap::status() const
|
||||||
{
|
{
|
||||||
std::cout << COLOR11 << "Diamondtrap " << COLOR10 << _name << " has " << _hitpoints
|
std::cout << COLOR11 << "DiamondTrap " << COLOR10 << _name << " has " << _hitpoints
|
||||||
<< " hitpoints, " << _energy_points << " energy points and "
|
<< " hitpoints, " << _energy_points << " energy points and "
|
||||||
<< _attack_damage << " attack damage." << std::endl;
|
<< _attack_damage << " attack damage." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void diamondtrap_test()
|
||||||
|
{
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR9 << "DiamondTrap 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 << "DiamondTrap Diamond with parameter constructor" << COLOR_RESET << std::endl;
|
||||||
|
DiamondTrap diamond("Diamond");
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "DiamondTrap diamond_copy with copy constructor of Diamond" << COLOR_RESET << std::endl;
|
||||||
|
DiamondTrap diamond_copy(diamond);
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_diamondtrap with default constructor" << COLOR_RESET << std::endl;
|
||||||
|
DiamondTrap default_diamondtrap;
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_diamondtrap = diamond" << COLOR_RESET << std::endl;
|
||||||
|
default_diamondtrap = diamond;
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: diamond" << COLOR_RESET << std::endl;
|
||||||
|
diamond.attack("enemy");
|
||||||
|
diamond.takeDamage(5);
|
||||||
|
diamond.beRepaired(3);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: diamond_copy" << COLOR_RESET << std::endl;
|
||||||
|
diamond_copy.attack("enemy");
|
||||||
|
diamond_copy.takeDamage(15);
|
||||||
|
diamond_copy.attack("the sun");
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
diamond_copy.beRepaired(1);
|
||||||
|
diamond_copy.attack("the moon");
|
||||||
|
diamond_copy.highFivesGuys();
|
||||||
|
diamond_copy.guardGate();
|
||||||
|
diamond_copy.whoAmI();
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: default_diamondtrap" << COLOR_RESET << std::endl;
|
||||||
|
default_diamondtrap.attack("enemy");
|
||||||
|
default_diamondtrap.takeDamage(5);
|
||||||
|
default_diamondtrap.highFivesGuys();
|
||||||
|
default_diamondtrap.guardGate();
|
||||||
|
default_diamondtrap.whoAmI();
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
||||||
}
|
}
|
||||||
@ -4,8 +4,6 @@
|
|||||||
|
|
||||||
FragTrap::FragTrap() : ClapTrap()
|
FragTrap::FragTrap() : ClapTrap()
|
||||||
{
|
{
|
||||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
|
||||||
status();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FragTrap::FragTrap(std::string name) : ClapTrap(name)
|
FragTrap::FragTrap(std::string name) : ClapTrap(name)
|
||||||
@ -15,32 +13,29 @@ FragTrap::FragTrap(std::string name) : ClapTrap(name)
|
|||||||
_attack_damage = 30;
|
_attack_damage = 30;
|
||||||
|
|
||||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||||
status();
|
|
||||||
}
|
}
|
||||||
FragTrap::FragTrap(FragTrap const &src) : ClapTrap(src)
|
FragTrap::FragTrap(FragTrap const &src) : ClapTrap(src)
|
||||||
{
|
{
|
||||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created by copy constructor" << std::endl;
|
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created by copy constructor" << std::endl;
|
||||||
status();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FragTrap::~FragTrap()
|
FragTrap::~FragTrap()
|
||||||
{
|
{
|
||||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
|
||||||
status();
|
status();
|
||||||
|
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
FragTrap &FragTrap::operator=(FragTrap const &rhs)
|
FragTrap &FragTrap::operator=(FragTrap const &other)
|
||||||
{
|
{
|
||||||
if (this == &rhs)
|
if (this == &other)
|
||||||
return (*this);
|
return (*this);
|
||||||
|
|
||||||
_name = rhs._name;
|
_name = other._name;
|
||||||
_hitpoints = rhs._hitpoints;
|
_hitpoints = other._hitpoints;
|
||||||
_energy_points = rhs._energy_points;
|
_energy_points = other._energy_points;
|
||||||
_attack_damage = rhs._attack_damage;
|
_attack_damage = other._attack_damage;
|
||||||
|
|
||||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created by assignation operator" << std::endl;
|
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created by assignation operator" << std::endl;
|
||||||
status();
|
|
||||||
|
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
@ -48,13 +43,54 @@ FragTrap &FragTrap::operator=(FragTrap const &rhs)
|
|||||||
void FragTrap::highFivesGuys(void)
|
void FragTrap::highFivesGuys(void)
|
||||||
{
|
{
|
||||||
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " common guys lets do high fives!!" << std::endl;
|
std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " common guys lets do high fives!!" << std::endl;
|
||||||
status();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FragTrap::status(void) const
|
void FragTrap::status(void) const
|
||||||
{
|
{
|
||||||
std::cout << COLOR14 << "FragTrap " << COLOR10 << _name << " has " << _hitpoints
|
std::cout << COLOR14 << "FragTrap " << COLOR10 << _name << " has " << _hitpoints
|
||||||
<< " hitpoints, " << _energy_points << " energy points and "
|
<< " hitpoints, " << _energy_points << " energy points and "
|
||||||
<< _attack_damage << " attack damage." << COLOR_RESET << std::endl;
|
<< _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;
|
||||||
}
|
}
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/28 11:32:48 by whaffman #+# #+# */
|
/* Created: 2025/03/28 11:32:48 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 23:01:15 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 10:19:00 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,40 +20,39 @@ ScavTrap::ScavTrap() : ClapTrap(), _guard_mode(false)
|
|||||||
_energy_points = 50;
|
_energy_points = 50;
|
||||||
_attack_damage = 20;
|
_attack_damage = 20;
|
||||||
|
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||||
status();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScavTrap::ScavTrap(std::string name) : ClapTrap(name), _guard_mode(false)
|
ScavTrap::ScavTrap(std::string name) : ClapTrap(name), _guard_mode(false)
|
||||||
{
|
{
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " has been created" << std::endl;
|
||||||
status();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScavTrap::ScavTrap(ScavTrap const &src) : ClapTrap(src), _guard_mode(src._guard_mode)
|
ScavTrap::ScavTrap(ScavTrap const &src) : ClapTrap(src)
|
||||||
{
|
{
|
||||||
_name = src._name; std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created by copy constructor" << std::endl;
|
_guard_mode = src._guard_mode;
|
||||||
status();
|
|
||||||
|
std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " has been created by copy constructor" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScavTrap::~ScavTrap()
|
ScavTrap::~ScavTrap()
|
||||||
{
|
{
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
|
||||||
status();
|
status();
|
||||||
|
std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " has been destroyed" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScavTrap &ScavTrap::operator=(ScavTrap const &rhs)
|
ScavTrap &ScavTrap::operator=(ScavTrap const &other)
|
||||||
{
|
{
|
||||||
if (this == &rhs)
|
if (this == &other)
|
||||||
return (*this);
|
return (*this);
|
||||||
|
|
||||||
_name = rhs._name;
|
_name = other._name;
|
||||||
_hitpoints = rhs._hitpoints;
|
_hitpoints = other._hitpoints;
|
||||||
_energy_points = rhs._energy_points;
|
_energy_points = other._energy_points;
|
||||||
_attack_damage = rhs._attack_damage;
|
_attack_damage = other._attack_damage;
|
||||||
|
|
||||||
|
std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " has been created by assignment operator" << std::endl;
|
||||||
|
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created by assignment operator" << std::endl;
|
|
||||||
status();
|
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,15 +80,58 @@ void ScavTrap::guardGate()
|
|||||||
{
|
{
|
||||||
_guard_mode = true;
|
_guard_mode = true;
|
||||||
|
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " is in Gate keeper mode" << std::endl;
|
std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " is in Gate keeper mode" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScavTrap::status() const
|
void ScavTrap::status() const
|
||||||
{
|
{
|
||||||
std::cout << COLOR13 << "Scavtrap " << COLOR10 << _name << " has " << _hitpoints << " hitpoints, "
|
std::cout << COLOR13 << "ScavTrap " << COLOR10 << _name << " has " << _hitpoints << " hitpoints, "
|
||||||
<< _energy_points << " energy points, " << _attack_damage << " attack damage ";
|
<< _energy_points << " energy points, " << _attack_damage << " attack damage ";
|
||||||
if (_guard_mode)
|
if (_guard_mode)
|
||||||
std::cout << "and is in Gate keeper mode" << COLOR_RESET << std::endl;
|
std::cout << "and is in Gate keeper mode" << COLOR_RESET << std::endl;
|
||||||
else
|
else
|
||||||
std::cout << "and is not in Gate keeper mode" << COLOR_RESET << std::endl;
|
std::cout << "and is not in Gate keeper mode" << COLOR_RESET << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void scavtrap_test()
|
||||||
|
{
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR9 << "ScavTrap 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 << "ScavTrap Bob with parameter constructor" << COLOR_RESET << std::endl;
|
||||||
|
ScavTrap bob("Bob");
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Scavtrap bob_copy with copy constructor of Bob" << COLOR_RESET << std::endl;
|
||||||
|
ScavTrap bob_copy(bob);
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_scavtrap with default constructor" << COLOR_RESET << std::endl;
|
||||||
|
ScavTrap default_scavtrap;
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "default_scavtrap = bob" << COLOR_RESET << std::endl;
|
||||||
|
default_scavtrap = bob;
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: bob" << COLOR_RESET << std::endl;
|
||||||
|
bob.attack("enemy");
|
||||||
|
bob.takeDamage(5);
|
||||||
|
bob.beRepaired(3);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: bob_copy" << COLOR_RESET << std::endl;
|
||||||
|
bob_copy.attack("enemy");
|
||||||
|
bob_copy.takeDamage(15);
|
||||||
|
bob_copy.attack("the sun");
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
bob_copy.beRepaired(1);
|
||||||
|
bob_copy.attack("the moon");
|
||||||
|
bob_copy.guardGate();
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Attack, takeDamage and beRepaired tests: default_scavtrap" << COLOR_RESET << std::endl;
|
||||||
|
default_scavtrap.attack("enemy");
|
||||||
|
default_scavtrap.takeDamage(5);
|
||||||
|
default_scavtrap.guardGate();
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << BOLD_UNDERLINE << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
||||||
}
|
}
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/03/28 11:35:59 by whaffman #+# #+# */
|
/* Created: 2025/03/28 11:35:59 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/04/07 22:42:18 by whaffman ######## odam.nl */
|
/* Updated: 2025/04/08 09:43:39 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -16,167 +16,18 @@
|
|||||||
#include "FragTrap.hpp"
|
#include "FragTrap.hpp"
|
||||||
#include "DiamondTrap.hpp"
|
#include "DiamondTrap.hpp"
|
||||||
|
|
||||||
void claptrap_test()
|
|
||||||
{
|
|
||||||
std::cout << COLOR9 << "ClapTrap tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "ClapTrap Alice with parameter constructor" << COLOR_RESET << std::endl;
|
|
||||||
ClapTrap alice("Alice");
|
|
||||||
std::cout << COLOR10 << "Claptrap alice_copy with copy constructor of Alice" << COLOR_RESET << std::endl;
|
|
||||||
ClapTrap alice_copy(alice);
|
|
||||||
std::cout << COLOR10 << "default_claptrap with default constructor" << COLOR_RESET << std::endl;
|
|
||||||
ClapTrap default_claptrap;
|
|
||||||
std::cout << COLOR10 << "default_claptrap = alice" << COLOR_RESET << std::endl;
|
|
||||||
default_claptrap = alice;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: alice" << COLOR_RESET << std::endl;
|
|
||||||
alice.attack("enemy");
|
|
||||||
alice.takeDamage(5);
|
|
||||||
alice.beRepaired(3);
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: alice_copy" << COLOR_RESET << std::endl;
|
|
||||||
alice_copy.attack("enemy");
|
|
||||||
alice_copy.takeDamage(15);
|
|
||||||
alice_copy.attack("the sun");
|
|
||||||
for(int i = 0; i < 10; i++)
|
|
||||||
alice_copy.beRepaired(1);
|
|
||||||
alice_copy.attack("the moon");
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: default_claptrap" << COLOR_RESET << std::endl;
|
|
||||||
default_claptrap.attack("enemy");
|
|
||||||
default_claptrap.takeDamage(5);
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void scavtrap_test()
|
|
||||||
{
|
|
||||||
std::cout << COLOR9 << "ScavTrap tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "ScavTrap Bob with parameter constructor" << COLOR_RESET << std::endl;
|
|
||||||
ScavTrap bob("Bob");
|
|
||||||
std::cout << COLOR10 << "Scavtrap bob_copy with copy constructor of Bob" << COLOR_RESET << std::endl;
|
|
||||||
ScavTrap bob_copy(bob);
|
|
||||||
std::cout << COLOR10 << "default_scavtrap with default constructor" << COLOR_RESET << std::endl;
|
|
||||||
ScavTrap default_scavtrap;
|
|
||||||
std::cout << COLOR10 << "default_scavtrap = bob" << COLOR_RESET << std::endl;
|
|
||||||
default_scavtrap = bob;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: bob" << COLOR_RESET << std::endl;
|
|
||||||
bob.attack("enemy");
|
|
||||||
bob.takeDamage(5);
|
|
||||||
bob.beRepaired(3);
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: bob_copy" << COLOR_RESET << std::endl;
|
|
||||||
bob_copy.attack("enemy");
|
|
||||||
bob_copy.takeDamage(15);
|
|
||||||
bob_copy.attack("the sun");
|
|
||||||
for(int i = 0; i < 10; i++)
|
|
||||||
bob_copy.beRepaired(1);
|
|
||||||
bob_copy.attack("the moon");
|
|
||||||
bob_copy.guardGate();
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: default_scavtrap" << COLOR_RESET << std::endl;
|
|
||||||
default_scavtrap.attack("enemy");
|
|
||||||
default_scavtrap.takeDamage(5);
|
|
||||||
default_scavtrap.guardGate();
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fragtrap_test()
|
|
||||||
{
|
|
||||||
std::cout << COLOR9 << "FragTrap tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "FragTrap Charlie with parameter constructor" << COLOR_RESET << std::endl;
|
|
||||||
FragTrap charlie("Charlie");
|
|
||||||
std::cout << COLOR10 << "Fragtrap charlie_copy with copy constructor of Charlie" << COLOR_RESET << std::endl;
|
|
||||||
FragTrap charlie_copy(charlie);
|
|
||||||
std::cout << COLOR10 << "default_fragtrap with default constructor" << COLOR_RESET << std::endl;
|
|
||||||
FragTrap default_fragtrap;
|
|
||||||
std::cout << COLOR10 << "default_fragtrap = charlie" << COLOR_RESET << std::endl;
|
|
||||||
default_fragtrap = charlie;
|
|
||||||
|
|
||||||
std::cout << 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 << 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 << 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 << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void diamondtrap_test()
|
|
||||||
{
|
|
||||||
std::cout << COLOR9 << "DiamondTrap tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "Constructor & assignment tests" << COLOR_RESET << std::endl;
|
|
||||||
std::cout << COLOR10 << "DiamondTrap Diamond with parameter constructor" << COLOR_RESET << std::endl;
|
|
||||||
DiamondTrap diamond("Diamond");
|
|
||||||
std::cout << COLOR10 << "Diamondtrap diamond_copy with copy constructor of Diamond" << COLOR_RESET << std::endl;
|
|
||||||
DiamondTrap diamond_copy(diamond);
|
|
||||||
std::cout << COLOR10 << "default_diamondtrap with default constructor" << COLOR_RESET << std::endl;
|
|
||||||
DiamondTrap default_diamondtrap;
|
|
||||||
std::cout << COLOR10 << "default_diamondtrap = diamond" << COLOR_RESET << std::endl;
|
|
||||||
default_diamondtrap = diamond;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: diamond" << COLOR_RESET << std::endl;
|
|
||||||
diamond.attack("enemy");
|
|
||||||
diamond.takeDamage(5);
|
|
||||||
diamond.beRepaired(3);
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: diamond_copy" << COLOR_RESET << std::endl;
|
|
||||||
diamond_copy.attack("enemy");
|
|
||||||
diamond_copy.takeDamage(15);
|
|
||||||
diamond_copy.attack("the sun");
|
|
||||||
for(int i = 0; i < 10; i++)
|
|
||||||
diamond_copy.beRepaired(1);
|
|
||||||
diamond_copy.attack("the moon");
|
|
||||||
diamond_copy.highFivesGuys();
|
|
||||||
diamond_copy.guardGate();
|
|
||||||
diamond_copy.whoAmI();
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Attack, takeDamage and beRepaired tests: default_diamondtrap" << COLOR_RESET << std::endl;
|
|
||||||
default_diamondtrap.attack("enemy");
|
|
||||||
default_diamondtrap.takeDamage(5);
|
|
||||||
default_diamondtrap.highFivesGuys();
|
|
||||||
default_diamondtrap.guardGate();
|
|
||||||
default_diamondtrap.whoAmI();
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << COLOR10 << "Destructor tests" << COLOR_RESET << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::cout << "Starting tests..." << std::endl;
|
std::cout << "Starting tests..." << std::endl << std::endl;
|
||||||
claptrap_test();
|
claptrap_test();
|
||||||
|
std::cout << std::endl << std::endl;
|
||||||
scavtrap_test();
|
scavtrap_test();
|
||||||
|
std::cout << std::endl << std::endl;
|
||||||
fragtrap_test();
|
fragtrap_test();
|
||||||
|
std::cout << std::endl << std::endl;
|
||||||
diamondtrap_test();
|
diamondtrap_test();
|
||||||
|
std::cout << std::endl << std::endl;
|
||||||
|
|
||||||
std::cout << COLOR9 << "All tests completed successfully!" << COLOR_RESET << std::endl;
|
std::cout << COLOR9 << "All tests completed successfully!" << COLOR_RESET << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user