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 // hp 50% ���� => maxHp / hp�� 2 �̻� 38 int damage = _attack; 39 40 if (_maxHp == 0) 41 return damage; 42 int percentage = (_hp * 100) / _maxHp; 43 if (percentage <= 50) 44 damage *= 2; 45 46 return damage; 47 } 48 49 void Knight::PrintInfo() 50 { 51 cout << "HP: " << _hp << endl; 52 cout << "ATT: " << _attack << endl; 53 }