aboutsummaryrefslogtreecommitdiff
path: root/cpp04/ex01/Enemy.cpp
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-11-12 15:46:07 +0100
committerCharles Cabergs <me@cacharle.xyz>2020-11-12 15:46:07 +0100
commitb8e39b947890e74d82530e25ad9d02668aae1f0c (patch)
treef59acfdecb0711137c200a4c5acb854e351f9cf9 /cpp04/ex01/Enemy.cpp
parent96dcf214a8c40529b251ea31ef037868583dd1da (diff)
downloadpiscine_cpp-b8e39b947890e74d82530e25ad9d02668aae1f0c.tar.gz
piscine_cpp-b8e39b947890e74d82530e25ad9d02668aae1f0c.tar.bz2
piscine_cpp-b8e39b947890e74d82530e25ad9d02668aae1f0c.zip
Reformating cpp04 classes
Diffstat (limited to 'cpp04/ex01/Enemy.cpp')
-rw-r--r--cpp04/ex01/Enemy.cpp39
1 files changed, 13 insertions, 26 deletions
diff --git a/cpp04/ex01/Enemy.cpp b/cpp04/ex01/Enemy.cpp
index 321ca68..c04f01b 100644
--- a/cpp04/ex01/Enemy.cpp
+++ b/cpp04/ex01/Enemy.cpp
@@ -6,49 +6,36 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 13:23:47 by charles #+# #+# */
-/* Updated: 2020/04/14 14:11:19 by charles ### ########.fr */
+/* Updated: 2020/11/12 13:50:10 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "Enemy.hpp"
-Enemy::Enemy(Enemy const& other)
-{
- *this = other;
-}
+Enemy::Enemy(int hp, std::string const& type) : m_hp(hp), m_type(type) {}
-void Enemy::operator=(Enemy const& other)
-{
- m_hp = other.m_hp;
- m_type = other.m_type;
-}
+Enemy::Enemy(Enemy const& other) { *this = other; }
-Enemy::~Enemy()
+Enemy& Enemy::operator=(Enemy const& other)
{
+ m_hp = other.m_hp;
+ m_type = other.m_type;
+ return *this;
}
-Enemy::Enemy(int hp, std::string const& type)
- : m_hp(hp), m_type(type)
-{
-}
+Enemy::~Enemy() {}
-std::string const& Enemy::getType() const
-{
- return m_type;
-}
-int Enemy::getHP() const
-{
- return m_hp;
-}
+std::string const& Enemy::getType() const { return m_type; }
+int Enemy::getHP() const { return m_hp; }
void Enemy::takeDamage(int amount)
{
if (amount < 0)
return;
m_hp -= amount;
+ if (m_hp < 0)
+ m_hp = 0;
}
-Enemy::Enemy()
-{
-}
+Enemy::Enemy() {}