-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParty.cpp
More file actions
74 lines (55 loc) · 1.48 KB
/
Copy pathParty.cpp
File metadata and controls
74 lines (55 loc) · 1.48 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
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
#include "Party.hpp"
#include "Character.hpp"
Party::Party(string name, int id, int maxSize)
: partyName(move(name)), partyId(id), maxMembers(maxSize) {}
Party::~Party() = default;
const string& Party::getPartyName() const {
return partyName;
}
int Party::getPartyId() const {
return partyId;
}
int Party::getMaxMembers() const {
return maxMembers;
}
const vector<CharPtr>& Party::getMembers() const {
return members;
}
vector<CharPtr> Party::getAliveMembers() const {
vector<CharPtr> alive;
for (const auto& m : members) {
if (m->isAlive())
alive.push_back(m);
}
return alive;
}
int Party::getAliveCount() const {
return static_cast<int>(getAliveMembers().size());
}
bool Party::isDefeated() const {
return getAliveCount() == 0;
}
bool Party::isFull() const {
return static_cast<int>(members.size()) >= maxMembers;
}
void Party::setPartyName(const string& name) {
partyName = name;
}
void Party::setMaxMembers(int max) {
maxMembers = std::max(1, max);
}
bool Party::addMember(const CharPtr& character) {
if (isFull()) {
cout << "Party is full!\n";
return false;
}
members.push_back(character);
character->setOwnerParty(this);
return true;
}
void Party::removeMember(const CharPtr& character) {
members.erase(
std::remove(members.begin(), members.end(), character),
members.end()
);
}