Join request is sent, but I need to plan the next section out in detail

This commit is contained in:
Kayne Ruse
2013-05-22 17:31:13 +10:00
parent 66f54dca0b
commit cce1a874bf
8 changed files with 68 additions and 50 deletions
+17 -22
View File
@@ -1,47 +1,42 @@
#include "player_manager.hpp"
PlayerManager::PlayerManager(int max) {
maxPlayers = max;
}
PlayerManager::~PlayerManager() {
DeleteAll();
}
#include <stdexcept>
void PlayerManager::UpdateAll(int delta) {
for (auto it : playerList) {
it->Update(delta);
for (auto it : playerMap) {
it.second->Update(delta);
}
}
Player* PlayerManager::New(int playerID, int channel, std::string handle, std::string avatar) {
Player* p = new Player(playerID, channel, handle, avatar);
playerList.push_back(p);
return p;
if (playerMap.find(playerID) != playerMap.end()) {
throw(std::runtime_error("Player ID already exists"));
}
return playerMap[playerID] = new Player(playerID, channel, handle, avatar);
}
Player* PlayerManager::Get(int playerID) {
for (auto it : playerList) {
if (it->GetPlayerID() == playerID) {
return it;
for (auto it : playerMap) {
if (it.second->GetPlayerID() == playerID) {
return it.second;
}
}
return nullptr;
}
void PlayerManager::Delete(int playerID) {
for (auto it : playerList) {
if (it->GetPlayerID() == playerID) {
delete it;
playerList.remove(it);
for (auto it : playerMap) {
if (it.second->GetPlayerID() == playerID) {
delete it.second;
playerMap.erase(playerID);
return;
}
}
}
void PlayerManager::DeleteAll() {
for (auto it : playerList) {
delete it;
for (auto it : playerMap) {
delete it.second;
}
playerList.clear();
playerMap.clear();
}