Changeset 45734ff in network-game for common/Game.cpp
- Timestamp:
- Dec 22, 2013, 10:14:43 PM (11 years ago)
- Branches:
- master
- Children:
- 58ca135
- Parents:
- 1d96513
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Game.cpp
r1d96513 r45734ff 37 37 } 38 38 39 bool Game::addPlayer(Player* p) { 40 if (players.find(p->id) == players.end()) { 41 players[p->id] = p; 42 return true; 43 } 44 else 45 return false; 46 } 47 48 bool Game::removePlayer(unsigned int id) { 49 if (players.erase(id) == 1) 50 return true; 51 else 52 return false; 53 } 54 39 55 map<unsigned int, Projectile>& Game::getProjectiles() { 40 56 return this->projectiles; 57 } 58 59 bool Game::addProjectile(Projectile p) { 60 if (projectiles.find(p.id) == projectiles.end()) { 61 projectiles[p.id] = p; 62 return true; 63 } 64 else 65 return false; 66 } 67 68 bool Game::removeProjectile(unsigned int id) { 69 if (projectiles.erase(id) == 1) 70 return true; 71 else 72 return false; 41 73 } 42 74 … … 63 95 void Game::setBlueScore(int score) { 64 96 this->blueScore = score; 65 }66 67 bool Game::addPlayer(Player* p) {68 if (players.find(p->id) == players.end()) {69 players[p->id] = p;70 return true;71 }72 else73 return false;74 }75 76 bool Game::removePlayer(unsigned int id) {77 if (players.erase(id) == 1)78 return true;79 else80 return false;81 97 } 82 98 … … 159 175 } 160 176 161 bool Game::addProjectile(Projectile p) { 162 if (projectiles.find(p.id) == projectiles.end()) { 163 projectiles[p.id] = p; 164 return true; 165 } 166 else 167 return false; 177 void Game::assignProjectileId(Projectile* p) { 178 p->id = unusedProjectileId; 179 updateUnusedProjectileId(); 168 180 } 169 181 170 bool Game::removeProjectile(unsigned int id) { 171 if (projectiles.erase(id) == 1) 172 return true; 173 else 174 return false; 182 void Game::updateUnusedProjectileId() { 183 while (projectiles.find(unusedProjectileId) != projectiles.end()) 184 unusedProjectileId++; 175 185 }
Note:
See TracChangeset
for help on using the changeset viewer.