diff --git a/ex00/ClapTrap/ClapTrap.cpp b/ex00/ClapTrap/ClapTrap.cpp index 4fba4a6..035653d 100644 --- a/ex00/ClapTrap/ClapTrap.cpp +++ b/ex00/ClapTrap/ClapTrap.cpp @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ClapTrap.hpp :+: :+: :+: */ +/* ClapTrap.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: aortigos name = target.name; + this->health = target.health; + this->energy = target.energy; + this->attackDamage = target.attackDamage; +} + +ClapTrap& ClapTrap::operator=(const ClapTrap &target) +{ + if (this != &target) + { + this->name = target.name; + this->health = target.health; + this->energy = target.energy; + this->attackDamage = target.attackDamage; + } + return (*this); +} + +ClapTrap::~ClapTrap() +{ + std::cout << "Destructor called for " + << this->name << std::endl; +} + +void ClapTrap::attack(const std::string &target) +{ + if (this->health > 0 && this->energy > 0) + { + std::cout << "ClapTrap " << this->name + << " attacks " << target + << ", causing " << this->attackDamage + << " points of damage!" << std::endl; + + this->energy -= 1; + } else { + std::cout << "ClapTrap " << this->name + << " cant attack anymore..." << std::endl; + } +} + +void ClapTrap::takeDamage(unsigned int amount) +{ + std::cout << "ClapTrap " << this->name + << " recieves " << amount + << " points of damage!" << std::endl; + if (amount >= this->health) + this->health = 0; + else + this->health -= amount; +} + +void ClapTrap::beRepaired(unsigned int amount) +{ + if (this->energy > 0) + { + std::cout << "ClapTrap " << this->name + << " repairs itself, recovering " << amount + << " hit points!" << std::endl; + + this->health += amount; + this->energy -= 1; + } else { + std::cout << "ClapTrap " << this->name + << " cant be repaired..." << std::endl; + } +} diff --git a/ex02/ClapTrap/ClapTrap.hpp b/ex02/ClapTrap/ClapTrap.hpp new file mode 100644 index 0000000..b06be08 --- /dev/null +++ b/ex02/ClapTrap/ClapTrap.hpp @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ClapTrap.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos + +class ClapTrap +{ + protected: + std::string name; + unsigned int health; + unsigned int energy; + unsigned int attackDamage; + + public: + ClapTrap(); + ClapTrap(std::string name); + ClapTrap(const ClapTrap &target); + ClapTrap& operator=(const ClapTrap &target); + ~ClapTrap(); + + void attack(const std::string &target); + void takeDamage(unsigned int amount); + void beRepaired(unsigned int amount); + +}; + +#endif diff --git a/ex02/FragTrap/FragTrap.cpp b/ex02/FragTrap/FragTrap.cpp new file mode 100644 index 0000000..a9df237 --- /dev/null +++ b/ex02/FragTrap/FragTrap.cpp @@ -0,0 +1,57 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* FragTrap.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos health = 100; + this->energy = 100; + this->attackDamage = 30; + std::cout << "FragTrap default constructor called " << this->name + << std::endl; +} + +FragTrap::FragTrap(std::string name) : ClapTrap(name) +{ + this->health = 100; + this->energy = 100; + this->attackDamage = 30; + std::cout << "FragTrap constructor called " << this->name + << std::endl; +} + +FragTrap::FragTrap(const FragTrap &other) : ClapTrap(other) { } + +FragTrap& FragTrap::operator=(const FragTrap &other) +{ + if (this != &other) + { + this->name = other.name; + this->health = other.health; + this->energy = other.energy; + this->attackDamage = other.attackDamage; + } + return (*this); +} + +FragTrap::~FragTrap() +{ + std::cout << "FragTrap destructor called for " + << this->name << std::endl; +} + +void FragTrap::highFivesGuys(void) +{ + std::cout << "FragTrap " << this->name << " has requested a high-five!" + << std::endl; +} diff --git a/ex02/FragTrap/FragTrap.hpp b/ex02/FragTrap/FragTrap.hpp new file mode 100644 index 0000000..3b7eca9 --- /dev/null +++ b/ex02/FragTrap/FragTrap.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* FragTrap.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +# include "../ClapTrap/ClapTrab.hpp" + +class FragTrap : public ClapTrap +{ + public: + FragTrap(); + FragTrap(std::string name); + FragTrap(const FragTrap &other); + FragTrap &operator=(const FragTrap &other); + ~FragTrap(); + + void highFivesGuys(void); +}; + +#endif diff --git a/ex02/Makefile b/ex02/Makefile new file mode 100644 index 0000000..97cfe3b --- /dev/null +++ b/ex02/Makefile @@ -0,0 +1,25 @@ +NAME = fragtrap + +SRCS = main.cpp ClapTrap/ClapTrap.cpp ScavTrap/ScavTrap.cpp +OBJS=$(SRCS:.cpp=.o) + +CC=c++ +CFLAGS=-Wall -Wextra -Werror -std=c++98 + +all: $(NAME) + +$(NAME): $(OBJS) + $(CC) $(CFLAGS) $(OBJS) -o $(NAME) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/ex02/ScavTrap/ScavTrap.cpp b/ex02/ScavTrap/ScavTrap.cpp new file mode 100644 index 0000000..c38736c --- /dev/null +++ b/ex02/ScavTrap/ScavTrap.cpp @@ -0,0 +1,73 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ScavTrap.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos health = 100; + this->energy = 50; + this->attackDamage = 20; + std::cout << "ScavTrap default constructor called " << this->name + << std::endl; +} + +ScavTrap::ScavTrap(std::string name) : ClapTrap(name) +{ + this->health = 100; + this->energy = 50; + this->attackDamage = 20; + std::cout << "ScavTrap constructor for " << this->name + << std::endl; +} + +ScavTrap::ScavTrap(const ScavTrap &other) : ClapTrap(other) { } + +ScavTrap& ScavTrap::operator=(const ScavTrap &other) +{ + if (this != &other) + { + this->name = other.name; + this->health = other.health; + this->energy = other.energy; + this->attackDamage = other.attackDamage; + } + return (*this); +} + +ScavTrap::~ScavTrap() +{ + std::cout << "ScavTrap destructor called for " + << this->name << std::endl; +} + +void ScavTrap::attack(const std::string &target) +{ + if (this->health > 0 && this->energy > 0) + { + std::cout << "ScavTrap " << this->name + << " attacks " << target + << ", causing " << this->attackDamage + << " points of damage!" << std::endl; + + this->energy -= 1; + } else { + std::cout << "ScavTrap " << this->name + << " cant attack anymore..." << std::endl; + } +} + +void ScavTrap::guardGate() +{ + std::cout << "ScavTrap " << this->name << " is in Gate keeper mode" + << std::endl; +} diff --git a/ex02/ScavTrap/ScavTrap.hpp b/ex02/ScavTrap/ScavTrap.hpp new file mode 100644 index 0000000..6096965 --- /dev/null +++ b/ex02/ScavTrap/ScavTrap.hpp @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ScavTrap.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +# include "../ClapTrap/ClapTrap.hpp" + +class ScavTrap : public ClapTrap +{ + public: + ScavTrap(); + ScavTrap(std::string name); + ScavTrap(const ScavTrap &other); + ScavTrap& operator=(const ScavTrap &other); + ~ScavTrap(); + + void attack(const std::string &target); + + void guardGate(); +}; + +#endif diff --git a/ex02/main.cpp b/ex02/main.cpp new file mode 100644 index 0000000..87f74e4 --- /dev/null +++ b/ex02/main.cpp @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos