commit 244932f90547fed2d4835d4eea421dc24e43455c Author: aortigos Date: Tue Sep 16 23:57:31 2025 +0200 ex00 done diff --git a/ex00/ClapTrap/ClapTrap.cpp b/ex00/ClapTrap/ClapTrap.cpp new file mode 100644 index 0000000..cdaeb16 --- /dev/null +++ b/ex00/ClapTrap/ClapTrap.cpp @@ -0,0 +1,86 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ClapTrap.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* 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" << 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; + this->health -= amount; +} + +void ClapTrap::beRepaired(unsigned int amount) +{ + if (this->energy > 0) + { + this->health += amount; + this->energy -= 1; + } else { + std::cout << "ClapTrap " << this->name + << " cant be repaired..." << std::endl; + } +} diff --git a/ex00/ClapTrap/ClapTrap.hpp b/ex00/ClapTrap/ClapTrap.hpp new file mode 100644 index 0000000..daac8dd --- /dev/null +++ b/ex00/ClapTrap/ClapTrap.hpp @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ClapTrap.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos + +class ClapTrap +{ + private: + 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/ex00/Makefile b/ex00/Makefile new file mode 100644 index 0000000..f680680 --- /dev/null +++ b/ex00/Makefile @@ -0,0 +1,25 @@ +NAME = claptrap + +SRCS = main.cpp ClapTrap/ClapTrap.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/ex00/main.cpp b/ex00/main.cpp new file mode 100644 index 0000000..95a7aa8 --- /dev/null +++ b/ex00/main.cpp @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos