forked from klusark/PacMacro
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer.cpp
54 lines (43 loc) · 878 Bytes
/
Player.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
46
47
48
49
50
51
52
53
54
#include <iostream>
#include "Player.hpp"
#include "Game.hpp"
#include "Connection.hpp"
std::vector<Player *> players;
std::ostream &operator<<(std::ostream &os, PlayerType const&type) {
switch (type) {
case Pacman:
os << "Pacman";
break;
case Inky:
os << "Inky";
break;
case Blinky:
os << "Blinky";
break;
case Pinky:
os << "Pinky";
break;
case Clyde:
os << "Clyde";
break;
}
return os;
}
Player::Player() : _type(InvalidType), _pos(0) {
}
void Player::addConnection(Connection *connection) {
_connections.push_back(connection);
}
void Player::removeConnection(Connection *connection) {
for (auto it = _connections.begin(); it != _connections.end(); ++it) {
if (*it == connection) {
_connections.erase(it);
return;
}
}
}
void Player::send(const std::string &data) {
for (Connection *x : _connections) {
x->send(data);
}
}