Knight.cpp
1 #include "Knight.h" 2 #include <iostream> 3 using namespace std; 4 5 // [��缭] �⺻�� Hp=100, Attack=10 6 Knight::Knight() : _hp(100), _maxHp(100), _attack(10) 7 { 8 9 } 10 11 Knight::Knight(int hp) : _hp(hp), _maxHp(hp), _attack(10) 12 { 13 14 } 15 16 Knight::~Knight() 17 { 18 19 } 20 21 void Knight::AddHp(int value) 22 { 23 _hp += value; 24 if (_hp < 0) 25 _hp = 0; 26 if (_hp > _maxHp) 27 _hp = _maxHp; 28 } 29 30 bool Knight::IsDead() 31 { 32 return (_hp <= 0); 33 } 34 35 int Knight::GetAttackDamage() 36 { 37 int damage = _attack; 38 39 if (_maxHp > 0) 40 { 41 int percentage = (100 * _hp) / _maxHp; 42 if (percentage <= 50) 43 damage *= 2; 44 } 45 46 return damage; 47 } 48 49 void Knight::PrintInfo() 50 { 51 cout << "HP: " << _hp << endl; 52 cout << "ATT: " << _attack << endl; 53 } 54 55 void Knight::OnDamaged(Knight* attacker) 56 { 57 if (attacker == nullptr) 58 return; 59 60 // �� ü�� ��´� 61 int damage = attacker->GetAttackDamage(); 62 AddHp(-damage); 63 64 if (IsDead()) 65 return; 66 67 // �ݰ�! 68 attacker->OnDamaged(this); 69 }