diff --git a/ex00/ClapTrap/ClapTrap.cpp b/ex00/ClapTrap/ClapTrap.cpp index 035653d..f7fe84a 100644 --- a/ex00/ClapTrap/ClapTrap.cpp +++ b/ex00/ClapTrap/ClapTrap.cpp @@ -65,14 +65,14 @@ void ClapTrap::attack(const std::string &target) this->energy -= 1; } else { std::cout << "ClapTrap " << this->name - << " cant attack anymore..." << std::endl; + << " can't attack anymore..." << std::endl; } } void ClapTrap::takeDamage(unsigned int amount) { std::cout << "ClapTrap " << this->name - << " recieves " << amount + << " receives " << amount << " points of damage!" << std::endl; if (amount >= this->health) this->health = 0; @@ -82,16 +82,20 @@ void ClapTrap::takeDamage(unsigned int amount) void ClapTrap::beRepaired(unsigned int amount) { - if (this->energy > 0) + if (this->health == 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; + std::cout << "ClapTrap " << this->name << " can't repair itself because it's destroyed" << std::endl; + return ; } + if (this->energy == 0) + { + std::cout << "ClapTrap " << this->name << " has no energy left to repair!" << std::endl; + return ; + } + std::cout << "ClapTrap " << this->name + << " repairs itself, recovering " << amount + << " hit points!" << std::endl; + + this->health += amount; + this->energy -= 1; } diff --git a/ex00/ClapTrap/ClapTrap.hpp b/ex00/ClapTrap/ClapTrap.hpp index 7101c93..daac8dd 100644 --- a/ex00/ClapTrap/ClapTrap.hpp +++ b/ex00/ClapTrap/ClapTrap.hpp @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ClapTrap.cpp :+: :+: :+: */ +/* ClapTrap.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: aortigos energy -= 1; } else { std::cout << "ClapTrap " << this->name - << " cant attack anymore..." << std::endl; + << " can't attack anymore..." << std::endl; } } void ClapTrap::takeDamage(unsigned int amount) { std::cout << "ClapTrap " << this->name - << " recieves " << amount + << " receives " << amount << " points of damage!" << std::endl; if (amount >= this->health) this->health = 0; @@ -82,16 +82,20 @@ void ClapTrap::takeDamage(unsigned int amount) void ClapTrap::beRepaired(unsigned int amount) { - if (this->energy > 0) + if (this->health == 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; + std::cout << "ClapTrap " << this->name << " can't repair itself because it's destroyed" << std::endl; + return ; } + if (this->energy == 0) + { + std::cout << "ClapTrap " << this->name << " has no energy left to repair!" << std::endl; + return ; + } + std::cout << "ClapTrap " << this->name + << " repairs itself, recovering " << amount + << " hit points!" << std::endl; + + this->health += amount; + this->energy -= 1; } diff --git a/ex01/Makefile b/ex01/Makefile index 6575a07..5799d39 100644 --- a/ex01/Makefile +++ b/ex01/Makefile @@ -1,10 +1,10 @@ NAME = scavtrap SRCS = main.cpp ClapTrap/ClapTrap.cpp ScavTrap/ScavTrap.cpp -OBJS=$(SRCS:.cpp=.o) +OBJS = $(SRCS:.cpp=.o) -CC=c++ -CFLAGS=-Wall -Wextra -Werror -std=c++98 +CC = c++ +CFLAGS = -Wall -Wextra -Werror -std=c++98 all: $(NAME) diff --git a/ex01/ScavTrap/ScavTrap.cpp b/ex01/ScavTrap/ScavTrap.cpp index b069329..d419784 100644 --- a/ex01/ScavTrap/ScavTrap.cpp +++ b/ex01/ScavTrap/ScavTrap.cpp @@ -12,7 +12,7 @@ #include "ScavTrap.hpp" -ScavTrap::ScavTrap() : ClapTrap("(NULL)") +ScavTrap::ScavTrap() : ClapTrap("(NULL)"), guarding_gate(false) { this->health = 100; this->energy = 50; @@ -21,7 +21,7 @@ ScavTrap::ScavTrap() : ClapTrap("(NULL)") << std::endl; } -ScavTrap::ScavTrap(std::string name) : ClapTrap(name) +ScavTrap::ScavTrap(std::string name) : ClapTrap(name), guarding_gate(false) { this->health = 100; this->energy = 50; @@ -62,22 +62,21 @@ void ScavTrap::attack(const std::string &target) this->energy -= 1; } else { std::cout << "ScavTrap " << this->name - << " cant attack anymore..." << std::endl; + << " can't attack anymore..." << std::endl; } } void ScavTrap::guardGate() { - if (this->guardGate) + if (!this->guarding_gate) { - this->guardGate = false; - std::cout << "ScavTrap " << this->name << " is not in Gate keeper mode" + this->guarding_gate = true; + std::cout << "ScavTrap " << this->name << " is in Gate keeper mode" << std::endl; } else { - this->guardGate = true; - std::cout << "ScavTrap " << this->name << " is in Gate keeper mode" + std::cout << "ScavTrap " << this->name << " is already in Gate keeper mode" << std::endl; } diff --git a/ex01/ScavTrap/ScavTrap.hpp b/ex01/ScavTrap/ScavTrap.hpp index 1798e36..3dcf304 100644 --- a/ex01/ScavTrap/ScavTrap.hpp +++ b/ex01/ScavTrap/ScavTrap.hpp @@ -20,7 +20,7 @@ class ScavTrap : public ClapTrap { private: - boold guarding_gate; + bool guarding_gate; public: ScavTrap(); ScavTrap(std::string name); diff --git a/ex02/ClapTrap/ClapTrap.cpp b/ex02/ClapTrap/ClapTrap.cpp index 035653d..f7fe84a 100644 --- a/ex02/ClapTrap/ClapTrap.cpp +++ b/ex02/ClapTrap/ClapTrap.cpp @@ -65,14 +65,14 @@ void ClapTrap::attack(const std::string &target) this->energy -= 1; } else { std::cout << "ClapTrap " << this->name - << " cant attack anymore..." << std::endl; + << " can't attack anymore..." << std::endl; } } void ClapTrap::takeDamage(unsigned int amount) { std::cout << "ClapTrap " << this->name - << " recieves " << amount + << " receives " << amount << " points of damage!" << std::endl; if (amount >= this->health) this->health = 0; @@ -82,16 +82,20 @@ void ClapTrap::takeDamage(unsigned int amount) void ClapTrap::beRepaired(unsigned int amount) { - if (this->energy > 0) + if (this->health == 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; + std::cout << "ClapTrap " << this->name << " can't repair itself because it's destroyed" << std::endl; + return ; } + if (this->energy == 0) + { + std::cout << "ClapTrap " << this->name << " has no energy left to repair!" << std::endl; + return ; + } + std::cout << "ClapTrap " << this->name + << " repairs itself, recovering " << amount + << " hit points!" << std::endl; + + this->health += amount; + this->energy -= 1; } diff --git a/ex02/FragTrap/FragTrap.hpp b/ex02/FragTrap/FragTrap.hpp index 3b7eca9..ec91ecc 100644 --- a/ex02/FragTrap/FragTrap.hpp +++ b/ex02/FragTrap/FragTrap.hpp @@ -15,7 +15,7 @@ # define FRAGTRAP_HPP # include -# include "../ClapTrap/ClapTrab.hpp" +# include "../ClapTrap/ClapTrap.hpp" class FragTrap : public ClapTrap { diff --git a/ex02/ScavTrap/ScavTrap.cpp b/ex02/ScavTrap/ScavTrap.cpp index b069329..48b7633 100644 --- a/ex02/ScavTrap/ScavTrap.cpp +++ b/ex02/ScavTrap/ScavTrap.cpp @@ -68,16 +68,15 @@ void ScavTrap::attack(const std::string &target) void ScavTrap::guardGate() { - if (this->guardGate) + if (!this->guarding_gate) { - this->guardGate = false; - std::cout << "ScavTrap " << this->name << " is not in Gate keeper mode" + this->guarding_gate = true; + std::cout << "ScavTrap " << this->name << " is in Gate keeper mode" << std::endl; } else { - this->guardGate = true; - std::cout << "ScavTrap " << this->name << " is in Gate keeper mode" + std::cout << "ScavTrap " << this->name << " is already in Gate keeper mode" << std::endl; } diff --git a/ex02/ScavTrap/ScavTrap.hpp b/ex02/ScavTrap/ScavTrap.hpp index 1798e36..3dcf304 100644 --- a/ex02/ScavTrap/ScavTrap.hpp +++ b/ex02/ScavTrap/ScavTrap.hpp @@ -20,7 +20,7 @@ class ScavTrap : public ClapTrap { private: - boold guarding_gate; + bool guarding_gate; public: ScavTrap(); ScavTrap(std::string name);