Changeset 45734ff in network-game for common/Game.cpp


Ignore:
Timestamp:
Dec 22, 2013, 10:14:43 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
58ca135
Parents:
1d96513
Message:

The Game class stores a list of projectiles present in that game

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/Game.cpp

    r1d96513 r45734ff  
    3737}
    3838
     39bool 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
     48bool Game::removePlayer(unsigned int id) {
     49   if (players.erase(id) == 1)
     50      return true;
     51   else
     52      return false;
     53}
     54
    3955map<unsigned int, Projectile>& Game::getProjectiles() {
    4056   return this->projectiles;
     57}
     58
     59bool 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
     68bool Game::removeProjectile(unsigned int id) {
     69   if (projectiles.erase(id) == 1)
     70      return true;
     71   else
     72      return false;
    4173}
    4274
     
    6395void Game::setBlueScore(int score) {
    6496   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    else
    73       return false;
    74 }
    75 
    76 bool Game::removePlayer(unsigned int id) {
    77    if (players.erase(id) == 1)
    78       return true;
    79    else
    80       return false;
    8197}
    8298
     
    159175}
    160176
    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;
     177void Game::assignProjectileId(Projectile* p) {
     178   p->id = unusedProjectileId;
     179   updateUnusedProjectileId();
    168180}
    169181
    170 bool Game::removeProjectile(unsigned int id) {
    171    if (projectiles.erase(id) == 1)
    172       return true;
    173    else
    174       return false;
     182void Game::updateUnusedProjectileId() {
     183   while (projectiles.find(unusedProjectileId) != projectiles.end())
     184      unusedProjectileId++;
    175185}
Note: See TracChangeset for help on using the changeset viewer.