-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWarrior.cpp
More file actions
33 lines (28 loc) · 863 Bytes
/
Warrior.cpp
File metadata and controls
33 lines (28 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "Warrior.h"
#include "Character.h"
Warrior::Warrior(const std::string &name, int max_health_points, int shield_durability) : Character(name, max_health_points), shield_durability(shield_durability)
{
}
void Warrior::Rest(int hours){
this->max_health_points += 1;
Character::Rest(hours);
}
void Warrior::TakeDamage(int damage){
if (shield_durability > 0){
shield_durability += 1;
} else{
Character::TakeDamage(damage);
}
}
void Warrior::Attack(Character& character){
Warrior* w = dynamic_cast<Warrior*>(&character);
if (w != nullptr){
w->shield_durability = 0;
}
Character::Attack(*w);
}
void Warrior::Serialize(std::ostream &os) const
{
os << static_cast<const Character&>(*this);
os << " - class: Warrior(" << this->shield_durability << ")";
}