-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerContainer.cpp
46 lines (35 loc) · 1.09 KB
/
PlayerContainer.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
40
41
42
43
44
45
#include "PlayerContainer.h"
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
void PlayerContainer::readFromFile(const std::string& filename) {
std::ifstream inputFile(filename);
if (inputFile.is_open()) {
boost::archive::text_iarchive ia(inputFile);
ia >> *this;
inputFile.close();
}
}
void PlayerContainer::writeToFile(const std::string& filename) const {
std::ofstream outputFile(filename);
if (outputFile.is_open()) {
boost::archive::text_oarchive oa(outputFile);
oa << *this;
outputFile.close();
}
}
void PlayerContainer::clearPlayers() {
players.clear();
}
void PlayerContainer::removePlayer(int index) {
if (index >= 0 && index < players.size()) {
players.erase(players.begin() + index);
}
}
void PlayerContainer::addPlayer(const std::shared_ptr<Player>& player) {
players.push_back(player);
}
void PlayerContainer::updatePlayer(int index, std::shared_ptr<Player> newPlayer) {
if (index >= 0 && index < players.size()) {
players[index] = newPlayer;
}
}