Add guardGate, fix typo in var
authorLukas Jiriste <ljiriste@student.42prague.com>
Fri, 18 Oct 2024 10:28:09 +0000 (12:28 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Fri, 18 Oct 2024 10:28:09 +0000 (12:28 +0200)
ex01/ScavTrap.cpp
ex01/ScavTrap.h
ex01/main.cpp

index 63fcf581dfd3f60c9e8ff5186659f8c3c89515cc..f867bbeb4328f0da475486c876f2a0d8a077785e 100644 (file)
@@ -9,7 +9,7 @@ ScavTrap::ScavTrap(std::string name): ClapTrap(name)
        m_hp = 100;
        m_energy = 50;
        m_attack = 20;
-       m_is_guading = 0;
+       m_is_guarding = 0;
 }
 
 ScavTrap::ScavTrap(const ScavTrap &other)
@@ -27,7 +27,7 @@ ScavTrap      &ScavTrap::operator=(const ScavTrap &other)
        if (this == &other)
                return (*this);
        ClapTrap::operator=(other);
-       m_is_guading = other.m_is_guading;
+       m_is_guarding = other.m_is_guarding;
        return (*this);
 }
 
@@ -46,3 +46,16 @@ void ScavTrap::attack(const std::string &target)
                --m_energy;
        }
 }
+
+void   ScavTrap::guardGate()
+{
+       if (m_hp == 0)
+               std::cout << m_name << " is dead and cannot guard the gate.\n";
+       else if (m_is_guarding == 0)
+       {
+               std::cout << m_name << " is now guarding the gate.\n";
+               m_is_guarding = 1;
+       }
+       else
+               std::cout << m_name << " is already guarding the gate.\n";
+}
index 5bdd16c09ca2d4b22a481184c6a04925b29e4e90..4a538e5ffce6cb74157a29fb7068214f9e5891f3 100644 (file)
@@ -7,7 +7,7 @@
 class ScavTrap : public ClapTrap
 {
        private:
-               bool    m_is_guading;
+               bool    m_is_guarding;
 
        public:
                ScavTrap(std::string name = "DEFAULT");
index b4026d464e7e9fcf8d8f31157a437f29a5c90503..2f16fe487544f97540bc9850d66cf0081a4bb32d 100644 (file)
@@ -16,13 +16,16 @@ int main()
        def.takeDamage(1);
        def.attack("foo");
        def.beRepaired(10);
-       for (int i(0); i < 10; ++i)
+       for (int i(0); i < 50; ++i)
                a.attack("bar");
        a.takeDamage(9);
+       a.guardGate();
+       a.guardGate();
        a.attack("bar");
        a.beRepaired(1);
        a.takeDamage(100);
        a.takeDamage(1);
+       a.guardGate();
        a.attack("bar");
        a.beRepaired(1);
        return (0);