-
Notifications
You must be signed in to change notification settings - Fork 0
/
human.cpp
40 lines (30 loc) · 847 Bytes
/
human.cpp
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
#include <iostream>
#include <sstream>
#include "human.h"
namespace da_game {
Human::Human(bool has_heart, int max_health) : has_heart(has_heart), max_health(max_health) {
hp = 100;
}
void Human::run() {
if (!has_heart) {
// Undead, fast regen
hp *= 2;
}
std::cout << "Ruuunning!" << std::endl;
}
std::string Human::get_type() const {
return "Human";
}
void Human::eat(Food & food) {
std::cout << "Yum! Food is great! Give me more " << std::endl;
hp += food.health_increase();
if (hp > max_health)
hp = max_health;
}
std::string Human::serialize() const {
std::ostringstream o;
o << "has_heart=" << has_heart;
o << ",max_health=" << max_health;
return o.str();
}
}