-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacter.cpp
More file actions
46 lines (39 loc) · 1.15 KB
/
Character.cpp
File metadata and controls
46 lines (39 loc) · 1.15 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "Character.h"
Character::Character(const std::string &name, int max_health_points) : name(name), max_health_points(max_health_points)
{
}
void Character::Attack(Character &character)
{
if (character.max_health_points > 0){
character.max_health_points -= 2;
}
}
void Character::Rest(int hours)
{
if (this->current_health_points + hours <= this->max_health_points){
this->current_health_points += hours;
} else{
this->current_health_points = 0;
}
}
void Character::TakeDamage(int damage)
{
if (this->current_health_points - damage >= 0){
this->current_health_points -= damage;
} else{
this->current_health_points = 0;
}
}
void Character::GetHealed(int heal)
{
this->Rest(heal);
}
void Character::Serialize(std::ostream &os) const
{
os << this->name << "(HP: " << this->current_health_points << "/" << this->max_health_points << ")";
}
std::ostream &operator<<(std::ostream &os, const Character &character)
{
os << character.name << "(HP: " << character.current_health_points << "/" << character.max_health_points << ")";
return os;
}