From b8e39b947890e74d82530e25ad9d02668aae1f0c Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Thu, 12 Nov 2020 15:46:07 +0100 Subject: Reformating cpp04 classes --- cpp04/ex01/Enemy.cpp | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) (limited to 'cpp04/ex01/Enemy.cpp') 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 +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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() {} -- cgit