diff --git a/common.mk b/common.mk index bd24137..6b1f9b7 100644 --- a/common.mk +++ b/common.mk @@ -6,14 +6,14 @@ # 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 VPATH = src OBJ = $(SRC:.cpp=.o) -CC = clang++ +CC = c++ CFLAGS = -Wall -Wextra -Werror all: $(NAME) diff --git a/ex00/inc/ClapTrap.hpp b/ex00/inc/ClapTrap.hpp index 39931da..c4f2151 100644 --- a/ex00/inc/ClapTrap.hpp +++ b/ex00/inc/ClapTrap.hpp @@ -6,7 +6,7 @@ /* 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 +#define BOLD_UNDERLINE "\033[1;4m" + #define COLOR0 "\033[38;5;0m" #define COLOR1 "\033[38;5;1m" #define COLOR2 "\033[38;5;2m" @@ -32,8 +34,6 @@ #define COLOR15 "\033[38;5;15m" #define COLOR_RESET "\033[m" - - class ClapTrap { private: @@ -48,10 +48,12 @@ public: ClapTrap(ClapTrap const &src); ~ClapTrap(); - ClapTrap &operator=(ClapTrap const &rhs); + ClapTrap &operator=(ClapTrap const &other); void status() const; void attack(std::string const &target); void takeDamage(unsigned int amount); void beRepaired(unsigned int amount); }; + +void claptrap_test(); diff --git a/ex00/src/ClapTrap.cpp b/ex00/src/ClapTrap.cpp index beeae3e..b8ed31e 100644 --- a/ex00/src/ClapTrap.cpp +++ b/ex00/src/ClapTrap.cpp @@ -4,7 +4,7 @@ ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0) { _name = "Noname"; - std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created!" << std::endl; + std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created! Lets call it \"Noname\"" << std::endl; status(); } @@ -14,31 +14,35 @@ ClapTrap::ClapTrap(std::string name) : _name(name), _hitpoints(10), _energy_poin 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; status(); } ClapTrap::~ClapTrap() { - std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl; 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; - std::cout << COLOR12 << "Claptrap " << COLOR_RESET << rhs._name + std::cout << COLOR12 << "Claptrap " << COLOR_RESET << other._name << " is assigned to ClapTrap formely known as " << _name << "!" << std::endl; - _name = rhs._name; - _hitpoints = rhs._hitpoints; - _energy_points = rhs._energy_points; - _attack_damage = rhs._attack_damage; + _name = other._name; + _hitpoints = other._hitpoints; + _energy_points = other._energy_points; + _attack_damage = other._attack_damage; status(); return *this; } @@ -91,3 +95,43 @@ void ClapTrap::status() const << _energy_points << " energy points and " << _attack_damage << " 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; +} \ No newline at end of file diff --git a/ex00/src/main.cpp b/ex00/src/main.cpp index 94685ef..1842972 100644 --- a/ex00/src/main.cpp +++ b/ex00/src/main.cpp @@ -6,53 +6,18 @@ /* 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 -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() { - std::cout << "Starting tests..." << std::endl; + std::cout << BOLD_UNDERLINE << COLOR9 << "Starting tests..." << COLOR_RESET << std::endl << std::endl; claptrap_test(); - + return 0; } \ No newline at end of file diff --git a/ex01/Makefile b/ex01/Makefile index bf11a4b..0509f26 100644 --- a/ex01/Makefile +++ b/ex01/Makefile @@ -6,11 +6,11 @@ # 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 -SRC= main.cpp ScavTrap.cpp ClapTrap.cpp +NAME= ClapTrap +SRC= main.cpp ScavTrap.cpp ClapTrap.cpp -include ../common.mk diff --git a/ex01/inc/ClapTrap.hpp b/ex01/inc/ClapTrap.hpp index 25a2ce5..53e5576 100644 --- a/ex01/inc/ClapTrap.hpp +++ b/ex01/inc/ClapTrap.hpp @@ -6,7 +6,7 @@ /* 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 +#define BOLD_UNDERLINE "\033[1;4m" + #define COLOR0 "\033[38;5;0m" #define COLOR1 "\033[38;5;1m" #define COLOR2 "\033[38;5;2m" @@ -32,8 +34,6 @@ #define COLOR15 "\033[38;5;15m" #define COLOR_RESET "\033[m" - - class ClapTrap { protected: @@ -48,10 +48,12 @@ public: ClapTrap(ClapTrap const &src); ~ClapTrap(); - ClapTrap &operator=(ClapTrap const &rhs); + ClapTrap &operator=(ClapTrap const &other); void status() const; void attack(std::string const &target); void takeDamage(unsigned int amount); void beRepaired(unsigned int amount); }; + +void claptrap_test(); \ No newline at end of file diff --git a/ex01/inc/ScavTrap.hpp b/ex01/inc/ScavTrap.hpp index 231475b..a0289c7 100644 --- a/ex01/inc/ScavTrap.hpp +++ b/ex01/inc/ScavTrap.hpp @@ -6,7 +6,7 @@ /* 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 &operator=(ScavTrap const &rhs); + ScavTrap &operator=(ScavTrap const &other); void attack(std::string const &target); void guardGate(); void status() const; -}; \ No newline at end of file +}; + +void scavtrap_test(); \ No newline at end of file diff --git a/ex01/src/ClapTrap.cpp b/ex01/src/ClapTrap.cpp index 2386448..b8ed31e 100644 --- a/ex01/src/ClapTrap.cpp +++ b/ex01/src/ClapTrap.cpp @@ -4,7 +4,7 @@ ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0) { _name = "Noname"; - std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created!" << std::endl; + std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created! Lets call it \"Noname\"" << std::endl; status(); } @@ -14,31 +14,35 @@ ClapTrap::ClapTrap(std::string name) : _name(name), _hitpoints(10), _energy_poin 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; - *this = src; status(); } ClapTrap::~ClapTrap() { - std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl; 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; - std::cout << COLOR12 << "Claptrap " << COLOR_RESET << rhs._name + std::cout << COLOR12 << "Claptrap " << COLOR_RESET << other._name << " is assigned to ClapTrap formely known as " << _name << "!" << std::endl; - _name = rhs._name; - _hitpoints = rhs._hitpoints; - _energy_points = rhs._energy_points; - _attack_damage = rhs._attack_damage; + _name = other._name; + _hitpoints = other._hitpoints; + _energy_points = other._energy_points; + _attack_damage = other._attack_damage; status(); return *this; } @@ -91,3 +95,43 @@ void ClapTrap::status() const << _energy_points << " energy points and " << _attack_damage << " 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; +} \ No newline at end of file diff --git a/ex01/src/ScavTrap.cpp b/ex01/src/ScavTrap.cpp index fb2367b..0a21bc5 100644 --- a/ex01/src/ScavTrap.cpp +++ b/ex01/src/ScavTrap.cpp @@ -6,7 +6,7 @@ /* 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; _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) { - 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) { - *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() { - 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); - _name = rhs._name; - _hitpoints = rhs._hitpoints; - _energy_points = rhs._energy_points; - _attack_damage = rhs._attack_damage; + _name = other._name; + _hitpoints = other._hitpoints; + _energy_points = other._energy_points; + _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); } @@ -79,15 +80,58 @@ void ScavTrap::guardGate() { _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 { - 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 "; if (_guard_mode) std::cout << "and is in Gate keeper mode" << COLOR_RESET << std::endl; else std::cout << "and is not in Gate keeper mode" << COLOR_RESET << std::endl; +} + +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; } \ No newline at end of file diff --git a/ex01/src/main.cpp b/ex01/src/main.cpp index b7bd984..b511b62 100644 --- a/ex01/src/main.cpp +++ b/ex01/src/main.cpp @@ -6,7 +6,7 @@ /* 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 "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() { std::cout << "Starting tests..." << std::endl; claptrap_test(); + std::cout << std::endl << std::endl; scavtrap_test(); std::cout << COLOR9 << "All tests completed" << COLOR_RESET << std::endl; - + return (0); } \ No newline at end of file diff --git a/ex02/Makefile b/ex02/Makefile index cacdec4..00a1cf2 100644 --- a/ex02/Makefile +++ b/ex02/Makefile @@ -6,11 +6,11 @@ # 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 -include ../common.mk diff --git a/ex02/inc/ClapTrap.hpp b/ex02/inc/ClapTrap.hpp index 25a2ce5..53e5576 100644 --- a/ex02/inc/ClapTrap.hpp +++ b/ex02/inc/ClapTrap.hpp @@ -6,7 +6,7 @@ /* 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 +#define BOLD_UNDERLINE "\033[1;4m" + #define COLOR0 "\033[38;5;0m" #define COLOR1 "\033[38;5;1m" #define COLOR2 "\033[38;5;2m" @@ -32,8 +34,6 @@ #define COLOR15 "\033[38;5;15m" #define COLOR_RESET "\033[m" - - class ClapTrap { protected: @@ -48,10 +48,12 @@ public: ClapTrap(ClapTrap const &src); ~ClapTrap(); - ClapTrap &operator=(ClapTrap const &rhs); + ClapTrap &operator=(ClapTrap const &other); void status() const; void attack(std::string const &target); void takeDamage(unsigned int amount); void beRepaired(unsigned int amount); }; + +void claptrap_test(); \ No newline at end of file diff --git a/ex02/inc/FragTrap.hpp b/ex02/inc/FragTrap.hpp index d9237cf..a20ca1f 100644 --- a/ex02/inc/FragTrap.hpp +++ b/ex02/inc/FragTrap.hpp @@ -6,7 +6,7 @@ /* 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 &operator=(FragTrap const &rhs); + FragTrap &operator=(FragTrap const &other); void highFivesGuys(void); void status(void) const; -}; \ No newline at end of file +}; + +void fragtrap_test(); \ No newline at end of file diff --git a/ex02/inc/ScavTrap.hpp b/ex02/inc/ScavTrap.hpp index 231475b..a0289c7 100644 --- a/ex02/inc/ScavTrap.hpp +++ b/ex02/inc/ScavTrap.hpp @@ -6,7 +6,7 @@ /* 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 &operator=(ScavTrap const &rhs); + ScavTrap &operator=(ScavTrap const &other); void attack(std::string const &target); void guardGate(); void status() const; -}; \ No newline at end of file +}; + +void scavtrap_test(); \ No newline at end of file diff --git a/ex02/src/ClapTrap.cpp b/ex02/src/ClapTrap.cpp index 2386448..b8ed31e 100644 --- a/ex02/src/ClapTrap.cpp +++ b/ex02/src/ClapTrap.cpp @@ -4,7 +4,7 @@ ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0) { _name = "Noname"; - std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created!" << std::endl; + std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created! Lets call it \"Noname\"" << std::endl; status(); } @@ -14,31 +14,35 @@ ClapTrap::ClapTrap(std::string name) : _name(name), _hitpoints(10), _energy_poin 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; - *this = src; status(); } ClapTrap::~ClapTrap() { - std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl; 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; - std::cout << COLOR12 << "Claptrap " << COLOR_RESET << rhs._name + std::cout << COLOR12 << "Claptrap " << COLOR_RESET << other._name << " is assigned to ClapTrap formely known as " << _name << "!" << std::endl; - _name = rhs._name; - _hitpoints = rhs._hitpoints; - _energy_points = rhs._energy_points; - _attack_damage = rhs._attack_damage; + _name = other._name; + _hitpoints = other._hitpoints; + _energy_points = other._energy_points; + _attack_damage = other._attack_damage; status(); return *this; } @@ -91,3 +95,43 @@ void ClapTrap::status() const << _energy_points << " energy points and " << _attack_damage << " 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; +} \ No newline at end of file diff --git a/ex02/src/FragTrap.cpp b/ex02/src/FragTrap.cpp index 06c49df..8a9eabe 100644 --- a/ex02/src/FragTrap.cpp +++ b/ex02/src/FragTrap.cpp @@ -14,26 +14,26 @@ FragTrap::FragTrap(std::string name) : ClapTrap(name) 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; } FragTrap::~FragTrap() { + 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); - _name = rhs._name; - _hitpoints = rhs._hitpoints; - _energy_points = rhs._energy_points; - _attack_damage = rhs._attack_damage; + _name = other._name; + _hitpoints = other._hitpoints; + _energy_points = other._energy_points; + _attack_damage = other._attack_damage; std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created by assignation operator" << std::endl; @@ -49,5 +49,48 @@ void FragTrap::status(void) const { std::cout << COLOR14 << "FragTrap " << COLOR10 << _name << " has " << _hitpoints << " hitpoints, " << _energy_points << " energy points and " - << _attack_damage << " attack damage." << std::endl; + << _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; } \ No newline at end of file diff --git a/ex02/src/ScavTrap.cpp b/ex02/src/ScavTrap.cpp index fb2367b..0a21bc5 100644 --- a/ex02/src/ScavTrap.cpp +++ b/ex02/src/ScavTrap.cpp @@ -6,7 +6,7 @@ /* 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; _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) { - 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) { - *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() { - 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); - _name = rhs._name; - _hitpoints = rhs._hitpoints; - _energy_points = rhs._energy_points; - _attack_damage = rhs._attack_damage; + _name = other._name; + _hitpoints = other._hitpoints; + _energy_points = other._energy_points; + _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); } @@ -79,15 +80,58 @@ void ScavTrap::guardGate() { _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 { - 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 "; if (_guard_mode) std::cout << "and is in Gate keeper mode" << COLOR_RESET << std::endl; else std::cout << "and is not in Gate keeper mode" << COLOR_RESET << std::endl; +} + +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; } \ No newline at end of file diff --git a/ex02/src/main.cpp b/ex02/src/main.cpp index 1af4773..b4246a8 100644 --- a/ex02/src/main.cpp +++ b/ex02/src/main.cpp @@ -6,7 +6,7 @@ /* 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 "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() { std::cout << "Starting tests..." << std::endl; claptrap_test(); + std::cout << std::endl << std::endl; + scavtrap_test(); + std::cout << std::endl << std::endl; + fragtrap_test(); + std::cout << std::endl << std::endl; std::cout << COLOR9 << "All tests completed!" << COLOR_RESET << std::endl; - + return (0); } \ No newline at end of file diff --git a/ex03/Makefile b/ex03/Makefile index 2780935..4e52ed3 100644 --- a/ex03/Makefile +++ b/ex03/Makefile @@ -6,11 +6,11 @@ # 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 -include ../common.mk diff --git a/ex03/inc/ClapTrap.hpp b/ex03/inc/ClapTrap.hpp index 25a2ce5..53e5576 100644 --- a/ex03/inc/ClapTrap.hpp +++ b/ex03/inc/ClapTrap.hpp @@ -6,7 +6,7 @@ /* 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 +#define BOLD_UNDERLINE "\033[1;4m" + #define COLOR0 "\033[38;5;0m" #define COLOR1 "\033[38;5;1m" #define COLOR2 "\033[38;5;2m" @@ -32,8 +34,6 @@ #define COLOR15 "\033[38;5;15m" #define COLOR_RESET "\033[m" - - class ClapTrap { protected: @@ -48,10 +48,12 @@ public: ClapTrap(ClapTrap const &src); ~ClapTrap(); - ClapTrap &operator=(ClapTrap const &rhs); + ClapTrap &operator=(ClapTrap const &other); void status() const; void attack(std::string const &target); void takeDamage(unsigned int amount); void beRepaired(unsigned int amount); }; + +void claptrap_test(); \ No newline at end of file diff --git a/ex03/inc/DiamondTrap.hpp b/ex03/inc/DiamondTrap.hpp index d5c2c47..e8d6118 100644 --- a/ex03/inc/DiamondTrap.hpp +++ b/ex03/inc/DiamondTrap.hpp @@ -6,11 +6,12 @@ /* 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 +#include #include "FragTrap.hpp" #include "ScavTrap.hpp" #include @@ -27,8 +28,10 @@ public: DiamondTrap(DiamondTrap const &src); ~DiamondTrap(); - DiamondTrap &operator=(DiamondTrap const &rhs); + DiamondTrap &operator=(DiamondTrap const &other); void whoAmI(void); void status(void) const; -}; \ No newline at end of file +}; + +void diamondtrap_test(); \ No newline at end of file diff --git a/ex03/inc/FragTrap.hpp b/ex03/inc/FragTrap.hpp index f13e955..68d20ca 100644 --- a/ex03/inc/FragTrap.hpp +++ b/ex03/inc/FragTrap.hpp @@ -6,7 +6,7 @@ /* 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 &operator=(FragTrap const &rhs); + FragTrap &operator=(FragTrap const &other); void highFivesGuys(void); void status(void) const; -}; \ No newline at end of file +}; + +void fragtrap_test(); \ No newline at end of file diff --git a/ex03/inc/ScavTrap.hpp b/ex03/inc/ScavTrap.hpp index 74b89fc..671af68 100644 --- a/ex03/inc/ScavTrap.hpp +++ b/ex03/inc/ScavTrap.hpp @@ -6,7 +6,7 @@ /* 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 &operator=(ScavTrap const &rhs); + ScavTrap &operator=(ScavTrap const &other); void attack(std::string const &target); void guardGate(); void status() const; -}; \ No newline at end of file +}; + +void scavtrap_test(); \ No newline at end of file diff --git a/ex03/src/ClapTrap.cpp b/ex03/src/ClapTrap.cpp index 3eb4c2e..b8ed31e 100644 --- a/ex03/src/ClapTrap.cpp +++ b/ex03/src/ClapTrap.cpp @@ -4,7 +4,7 @@ ClapTrap::ClapTrap() : _hitpoints(10), _energy_points(10), _attack_damage(0) { _name = "Noname"; - std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created!" << std::endl; + std::cout << COLOR12 << "Claptrap " << COLOR_RESET << "A nameless ClapTrap is created! Lets call it \"Noname\"" << std::endl; status(); } @@ -14,36 +14,35 @@ ClapTrap::ClapTrap(std::string name) : _name(name), _hitpoints(10), _energy_poin status(); } -ClapTrap::ClapTrap(ClapTrap const &src) +ClapTrap::ClapTrap(ClapTrap const &other) { - _name = src._name; - _hitpoints = src._hitpoints; - _energy_points = src._energy_points; - _attack_damage = src._attack_damage; - + _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; - status(); } ClapTrap::~ClapTrap() { - std::cout << COLOR12 << "Claptrap " << COLOR_RESET << _name << " is destroyed!" << std::endl; 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; - std::cout << COLOR12 << "Claptrap " << COLOR_RESET << rhs._name + std::cout << COLOR12 << "Claptrap " << COLOR_RESET << other._name << " is assigned to ClapTrap formely known as " << _name << "!" << std::endl; - _name = rhs._name; - _hitpoints = rhs._hitpoints; - _energy_points = rhs._energy_points; - _attack_damage = rhs._attack_damage; + _name = other._name; + _hitpoints = other._hitpoints; + _energy_points = other._energy_points; + _attack_damage = other._attack_damage; status(); return *this; } @@ -96,3 +95,43 @@ void ClapTrap::status() const << _energy_points << " energy points and " << _attack_damage << " 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; +} \ No newline at end of file diff --git a/ex03/src/DiamondTrap.cpp b/ex03/src/DiamondTrap.cpp index 76b4f2b..cc2a65e 100644 --- a/ex03/src/DiamondTrap.cpp +++ b/ex03/src/DiamondTrap.cpp @@ -11,7 +11,7 @@ DiamondTrap::DiamondTrap() : ClapTrap("NoName"), _name("NoName") _energy_points = ScavTrap::_energy_points; _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(); } @@ -21,7 +21,7 @@ DiamondTrap::DiamondTrap(std::string name) : ClapTrap(name + "_clap_name"), _nam _energy_points = ScavTrap::_energy_points; _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(); } @@ -29,41 +29,87 @@ DiamondTrap::DiamondTrap(DiamondTrap const &src) : ClapTrap(src), FragTrap(src), { _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(); } - DiamondTrap::~DiamondTrap() { - std::cout << COLOR11 << "Diamondtrap " << COLOR_RESET << _name << " has been destroyed" << std::endl; 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); - _name = rhs._name; - _hitpoints = rhs._hitpoints; - _energy_points = rhs._energy_points; - _attack_damage = rhs._attack_damage; - ClapTrap::_name = rhs.ClapTrap::_name; - std::cout << COLOR11 << "Diamondtrap " << COLOR_RESET << _name << " has been created by assignment operator" << std::endl; + _name = other._name; + _hitpoints = other._hitpoints; + _energy_points = other._energy_points; + _attack_damage = other._attack_damage; + ClapTrap::_name = other.ClapTrap::_name; + std::cout << COLOR11 << "DiamondTrap " << COLOR_RESET << _name << " has been created by assignment operator" << std::endl; status(); return (*this); } void DiamondTrap::whoAmI(void) { - std::cout << COLOR11 << "Diamondtrap " << COLOR_RESET - << "I am " << _name << ", but my ClapTRap friends call me: " + std::cout << COLOR11 << "DiamondTrap " << COLOR_RESET + << "I am " << _name << ", but my ClapTrap friends call me: " << ClapTrap::_name << std::endl; - status(); + status(); } 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 " - << _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; } \ No newline at end of file diff --git a/ex03/src/FragTrap.cpp b/ex03/src/FragTrap.cpp index 004bf81..8a9eabe 100644 --- a/ex03/src/FragTrap.cpp +++ b/ex03/src/FragTrap.cpp @@ -4,8 +4,6 @@ FragTrap::FragTrap() : ClapTrap() { - std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created" << std::endl; - status(); } FragTrap::FragTrap(std::string name) : ClapTrap(name) @@ -15,32 +13,29 @@ FragTrap::FragTrap(std::string name) : ClapTrap(name) _attack_damage = 30; std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created" << std::endl; - status(); } FragTrap::FragTrap(FragTrap const &src) : ClapTrap(src) { std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created by copy constructor" << std::endl; - status(); } FragTrap::~FragTrap() { - std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been destroyed" << std::endl; 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); - _name = rhs._name; - _hitpoints = rhs._hitpoints; - _energy_points = rhs._energy_points; - _attack_damage = rhs._attack_damage; + _name = other._name; + _hitpoints = other._hitpoints; + _energy_points = other._energy_points; + _attack_damage = other._attack_damage; std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " has been created by assignation operator" << std::endl; - status(); return (*this); } @@ -48,13 +43,54 @@ FragTrap &FragTrap::operator=(FragTrap const &rhs) void FragTrap::highFivesGuys(void) { std::cout << COLOR14 << "FragTrap " << COLOR_RESET << _name << " common guys lets do high fives!!" << std::endl; - status(); } - void FragTrap::status(void) const { std::cout << COLOR14 << "FragTrap " << COLOR10 << _name << " has " << _hitpoints << " hitpoints, " << _energy_points << " energy points and " - << _attack_damage << " attack damage." << COLOR_RESET << std::endl; + << _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; } \ No newline at end of file diff --git a/ex03/src/ScavTrap.cpp b/ex03/src/ScavTrap.cpp index c5b863b..0a21bc5 100644 --- a/ex03/src/ScavTrap.cpp +++ b/ex03/src/ScavTrap.cpp @@ -6,7 +6,7 @@ /* 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; _attack_damage = 20; - std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created" << std::endl; - status(); + std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " has been created" << std::endl; } ScavTrap::ScavTrap(std::string name) : ClapTrap(name), _guard_mode(false) { - std::cout << COLOR13 << "Scavtrap " << COLOR_RESET << _name << " has been created" << std::endl; - status(); + std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " has been created" << std::endl; } -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; - status(); + _guard_mode = src._guard_mode; + + std::cout << COLOR13 << "ScavTrap " << COLOR_RESET << _name << " has been created by copy constructor" << std::endl; } 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); - _name = rhs._name; - _hitpoints = rhs._hitpoints; - _energy_points = rhs._energy_points; - _attack_damage = rhs._attack_damage; + _name = other._name; + _hitpoints = other._hitpoints; + _energy_points = other._energy_points; + _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); } @@ -81,15 +80,58 @@ void ScavTrap::guardGate() { _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 { - 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 "; if (_guard_mode) std::cout << "and is in Gate keeper mode" << COLOR_RESET << std::endl; else std::cout << "and is not in Gate keeper mode" << COLOR_RESET << std::endl; +} + +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; } \ No newline at end of file diff --git a/ex03/src/main.cpp b/ex03/src/main.cpp index 976e9fe..ed48274 100644 --- a/ex03/src/main.cpp +++ b/ex03/src/main.cpp @@ -6,7 +6,7 @@ /* 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 "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() { - std::cout << "Starting tests..." << std::endl; + std::cout << "Starting tests..." << std::endl << std::endl; claptrap_test(); + std::cout << std::endl << std::endl; scavtrap_test(); + std::cout << std::endl << std::endl; fragtrap_test(); + std::cout << std::endl << std::endl; diamondtrap_test(); + std::cout << std::endl << std::endl; std::cout << COLOR9 << "All tests completed successfully!" << COLOR_RESET << std::endl; return 0;