-
Notifications
You must be signed in to change notification settings - Fork 0
/
monster.cc
104 lines (76 loc) · 2.95 KB
/
monster.cc
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "monster.h"
Monster::Monster(HealthPoints health, HealthPoints attack_power, std::string name) :
_health(health), _name(name), Attacker(attack_power) { }
HealthPoints Monster::getHealth() const {
return _health;
}
void Monster::takeDamage(HealthPoints damage) {
_health -= std::min(_health, damage);
}
Mummy::Mummy(HealthPoints health, HealthPoints attack_power)
: Monster(health, attack_power, "Mummy") { }
const std::string& Mummy::getName() const {
return _name;
}
Vampire::Vampire(HealthPoints health, HealthPoints attack_power)
: Monster(health, attack_power, "Vampire") { }
const std::string& Vampire::getName() const {
return _name;
}
Zombie::Zombie(HealthPoints health, HealthPoints attack_power)
: Monster(health, attack_power, "Zombie") { }
const std::string& Zombie::getName() const {
return _name;
}
GroupOfMonsters::GroupOfMonsters(std::initializer_list<std::shared_ptr<Monster>> monsters)
: _monsters(monsters), _name("GroupOfMonsters") { }
GroupOfMonsters::GroupOfMonsters(const std::vector<std::shared_ptr<Monster>>& monsters)
: _monsters(monsters), _name("GroupOfMonsters") { }
GroupOfMonsters::GroupOfMonsters(std::vector<std::shared_ptr<Monster>>&& monsters)
: _monsters(monsters), _name("GroupOfMonsters") { }
HealthPoints GroupOfMonsters::getHealth() const {
HealthPoints health_of_group = 0;
for (std::shared_ptr<Monster> monster : _monsters) {
health_of_group += monster->getHealth();
}
return health_of_group;
}
AttackPower GroupOfMonsters::getAttackPower() const {
AttackPower attack_power_of_group = 0;
for (std::shared_ptr<Monster> monster : _monsters) {
attack_power_of_group += monster->getAttackPower();
}
return attack_power_of_group;
}
void GroupOfMonsters::takeDamage(AttackPower damage) {
for (std::shared_ptr<Monster> monster : _monsters) {
monster->takeDamage(damage);
}
}
const std::string& GroupOfMonsters::getName() const {
return _name;
}
std::shared_ptr<Mummy>
createMummy(HealthPoints health, AttackPower attack_power) {
return std::make_shared<Mummy>(health, attack_power);
}
std::shared_ptr<Vampire>
createVampire(HealthPoints health, AttackPower attack_power) {
return std::make_shared<Vampire>(health, attack_power);
}
std::shared_ptr<Zombie>
createZombie(HealthPoints health, AttackPower attack_power) {
return std::make_shared<Zombie>(health, attack_power);
}
std::shared_ptr<GroupOfMonsters>
createGroupOfMonsters(std::initializer_list<std::shared_ptr<Monster>> monsters) {
return std::make_shared<GroupOfMonsters>(monsters);
}
std::shared_ptr<GroupOfMonsters>
createGroupOfMonsters(const std::vector<std::shared_ptr<Monster>>& monsters) {
return std::make_shared<GroupOfMonsters>(monsters);
}
std::shared_ptr<GroupOfMonsters>
createGroupOfMonsters(std::vector<std::shared_ptr<Monster>>&& monsters) {
return std::make_shared<GroupOfMonsters>(std::move(monsters));
}