Changeset 7f884ea in network-game for common


Ignore:
Timestamp:
Jan 24, 2014, 12:27:15 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
f66d04f
Parents:
e70b66b
Message:

Map-related structs are now outside of the WorldMap class

Location:
common
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • common/Game.cpp

    re70b66b r7f884ea  
    102102}
    103103
    104 void Game::addObjectToMap(WorldMap::ObjectType objectType, int x, int y) {
     104void Game::addObjectToMap(ObjectType objectType, int x, int y) {
    105105   NETWORK_MSG serverMsg;
    106106
     
    120120   if (0 <= x && x < this->worldMap->width*25 &&
    121121       0 <= y && y < this->worldMap->height*25 &&
    122        this->worldMap->getElement(x/25, y/25) == WorldMap::TERRAIN_GRASS)
     122       this->worldMap->getElement(x/25, y/25) == TERRAIN_GRASS)
    123123   {
    124124      p->target.x = x;
     
    140140   switch(this->worldMap->getElement(p->pos.x/25, p->pos.y/25))
    141141   {
    142       case WorldMap::TERRAIN_NONE:
    143       case WorldMap::TERRAIN_OCEAN:
    144       case WorldMap::TERRAIN_ROCK:
     142      case TERRAIN_NONE:
     143      case TERRAIN_OCEAN:
     144      case TERRAIN_ROCK:
    145145      {
    146146         p->pos = oldPos;
     
    167167      if (posDistance(p->pos, it->pos.toFloat()) < 10) {
    168168         switch (it->type) {
    169             case WorldMap::OBJECT_BLUE_FLAG:
     169            case OBJECT_BLUE_FLAG:
    170170               if (p->team == 1) {
    171171                  p->hasBlueFlag = true;
     
    173173               }
    174174               break;
    175             case WorldMap::OBJECT_RED_FLAG:
     175            case OBJECT_RED_FLAG:
    176176               if (p->team == 0) {
    177177                  p->hasRedFlag = true;
     
    179179               }
    180180               break;
    181             case WorldMap::OBJECT_NONE:
     181            case OBJECT_NONE:
    182182               break;
    183183         }
     
    198198   if (p->isDead)
    199199   {
    200       WorldMap::ObjectType flagType = WorldMap::OBJECT_NONE;
     200      ObjectType flagType = OBJECT_NONE;
    201201      if (p->hasBlueFlag)
    202          flagType = WorldMap::OBJECT_BLUE_FLAG;
     202         flagType = OBJECT_BLUE_FLAG;
    203203      else if (p->hasRedFlag)
    204          flagType = WorldMap::OBJECT_RED_FLAG;
    205 
    206       if (flagType != WorldMap::OBJECT_NONE)
     204         flagType = OBJECT_RED_FLAG;
     205
     206      if (flagType != OBJECT_NONE)
    207207         this->addObjectToMap(flagType, p->pos.x, p->pos.y);
    208208   }
     
    252252      cout << "player move processed" << endl;
    253253
    254       WorldMap::ObjectType flagType;
     254      ObjectType flagType;
    255255      POSITION pos;
    256256      bool flagTurnedIn = false;
     
    260260      switch(this->worldMap->getStructure(p->pos.x/25, p->pos.y/25))
    261261      {
    262          case WorldMap::STRUCTURE_BLUE_FLAG:
     262         case STRUCTURE_BLUE_FLAG:
    263263         {
    264264            if (p->team == 0 && p->hasRedFlag)
    265265            {
    266266               // check that your flag is at your base
    267                pos = this->worldMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);
     267               pos = this->worldMap->getStructureLocation(STRUCTURE_BLUE_FLAG);
    268268                           
    269269               vector<WorldMap::Object>* vctObjects = this->worldMap->getObjects();
     
    272272               for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++)
    273273               {
    274                   if (itObjects->type == WorldMap::OBJECT_BLUE_FLAG)
     274                  if (itObjects->type == OBJECT_BLUE_FLAG)
    275275                  {
    276276                     if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12)
     
    285285               {
    286286                  p->hasRedFlag = false;
    287                   flagType = WorldMap::OBJECT_RED_FLAG;
    288                   pos = this->worldMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);
     287                  flagType = OBJECT_RED_FLAG;
     288                  pos = this->worldMap->getStructureLocation(STRUCTURE_RED_FLAG);
    289289                  flagTurnedIn = true;
    290290                  this->blueScore++;
     
    294294            break;
    295295         }
    296          case WorldMap::STRUCTURE_RED_FLAG:
     296         case STRUCTURE_RED_FLAG:
    297297         {
    298298            if (p->team == 1 && p->hasBlueFlag)
    299299            {
    300300               // check that your flag is at your base
    301                pos = this->worldMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);
     301               pos = this->worldMap->getStructureLocation(STRUCTURE_RED_FLAG);
    302302                       
    303303               vector<WorldMap::Object>* vctObjects = this->worldMap->getObjects();
     
    306306               for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++)
    307307               {
    308                   if (itObjects->type == WorldMap::OBJECT_RED_FLAG)
     308                  if (itObjects->type == OBJECT_RED_FLAG)
    309309                  {
    310310                     if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12)
     
    319319               {
    320320                  p->hasBlueFlag = false;
    321                   flagType = WorldMap::OBJECT_BLUE_FLAG;
    322                   pos = this->worldMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);
     321                  flagType = OBJECT_BLUE_FLAG;
     322                  pos = this->worldMap->getStructureLocation(STRUCTURE_BLUE_FLAG);
    323323                  flagTurnedIn = true;
    324324                  this->redScore++;
     
    385385         {
    386386            if (p->team == 0 &&
    387                 itObjects->type == WorldMap::OBJECT_BLUE_FLAG)
     387                itObjects->type == OBJECT_BLUE_FLAG)
    388388            {
    389                structPos = this->worldMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);
     389               structPos = this->worldMap->getStructureLocation(STRUCTURE_BLUE_FLAG);
    390390               flagReturned = true;
    391391               break;
    392392            }
    393393            else if (p->team == 1 &&
    394                      itObjects->type == WorldMap::OBJECT_RED_FLAG)
     394                     itObjects->type == OBJECT_RED_FLAG)
    395395            {
    396                structPos = this->worldMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);
     396               structPos = this->worldMap->getStructureLocation(STRUCTURE_RED_FLAG);
    397397               flagReturned = true;
    398398               break;
  • common/Game.h

    re70b66b r7f884ea  
    4646   void setRedScore(unsigned int score);
    4747
    48    void addObjectToMap(WorldMap::ObjectType objectType, int x, int y);
     48   void addObjectToMap(ObjectType objectType, int x, int y);
    4949
    5050   map<unsigned int, Player*>& getPlayers();
  • common/WorldMap.cpp

    re70b66b r7f884ea  
    4949      for (int x=0; x<this->width; x++) {
    5050         switch (this->getStructure(x, y)) {
    51             case WorldMap::STRUCTURE_BLUE_FLAG:
    52                this->addObject(WorldMap::OBJECT_BLUE_FLAG, x*25+12, y*25+12);
     51            case STRUCTURE_BLUE_FLAG:
     52               this->addObject(OBJECT_BLUE_FLAG, x*25+12, y*25+12);
    5353               break;
    54             case WorldMap::STRUCTURE_RED_FLAG:
    55                this->addObject(WorldMap::OBJECT_RED_FLAG, x*25+12, y*25+12);
     54            case STRUCTURE_RED_FLAG:
     55               this->addObject(OBJECT_RED_FLAG, x*25+12, y*25+12);
    5656               break;
    57             case WorldMap::STRUCTURE_NONE:
     57            case STRUCTURE_NONE:
    5858               break;
    5959         }
     
    6262}
    6363
    64 WorldMap::TerrainType WorldMap::getElement(int x, int y)
     64TerrainType WorldMap::getElement(int x, int y)
    6565{
    6666   return (*(*vctMap)[x])[y];
     
    7272}
    7373
    74 WorldMap::StructureType WorldMap::getStructure(int x, int y)
     74StructureType WorldMap::getStructure(int x, int y)
    7575{
    7676   return (*(*vctStructures)[x])[y];
     
    118118
    119119// used by the server to create new objects
    120 void WorldMap::addObject(WorldMap::ObjectType t, int x, int y) {
     120void WorldMap::addObject(ObjectType t, int x, int y) {
    121121   unsigned int id;
    122122   vector<WorldMap::Object>::iterator it;
     
    137137
    138138// used by the client to update object positions or create objects it has not seen before
    139 void WorldMap::updateObject(unsigned int id, WorldMap::ObjectType t, int x, int y) {
     139void WorldMap::updateObject(unsigned int id, ObjectType t, int x, int y) {
    140140   vector<WorldMap::Object>::iterator it;
    141141   bool foundObject = false;
     
    143143   cout << "Searching for object to update" << endl;
    144144   switch (t) {
    145    case WorldMap::OBJECT_BLUE_FLAG:
     145   case OBJECT_BLUE_FLAG:
    146146      cout << "BLUE_FLAG" << endl;
    147147      break;
    148    case WorldMap::OBJECT_RED_FLAG:
     148   case OBJECT_RED_FLAG:
    149149      cout << "RED_FLAG" << endl;
    150150      break;
    151    case WorldMap::OBJECT_NONE:
     151   case OBJECT_NONE:
    152152      cout << "OBJECY_NONE" << endl;
    153153      break;
     
    159159         cout << "Found object with id " << id << endl;
    160160         switch (it->type) {
    161          case WorldMap::OBJECT_BLUE_FLAG:
     161         case OBJECT_BLUE_FLAG:
    162162            cout << "BLUE_FLAG" << endl;
    163163            break;
    164          case WorldMap::OBJECT_RED_FLAG:
     164         case OBJECT_RED_FLAG:
    165165            cout << "RED_FLAG" << endl;
    166166            break;
    167          case WorldMap::OBJECT_NONE:
     167         case OBJECT_NONE:
    168168            cout << "OBJECY_NONE" << endl;
    169169            break;
  • common/WorldMap.h

    re70b66b r7f884ea  
    99using namespace std;
    1010
     11enum TerrainType {
     12   TERRAIN_NONE,
     13   TERRAIN_GRASS,
     14   TERRAIN_OCEAN,
     15   TERRAIN_ROCK
     16};
     17
     18enum StructureType {
     19   STRUCTURE_NONE,
     20   STRUCTURE_BLUE_FLAG,
     21   STRUCTURE_RED_FLAG
     22};
     23
     24enum ObjectType {
     25   OBJECT_NONE,
     26   OBJECT_BLUE_FLAG,
     27   OBJECT_RED_FLAG
     28};
     29
    1130class WorldMap {
    1231public:
    13    enum TerrainType {
    14       TERRAIN_NONE,
    15       TERRAIN_GRASS,
    16       TERRAIN_OCEAN,
    17       TERRAIN_ROCK
    18    };
    19 
    20    enum StructureType {
    21       STRUCTURE_NONE,
    22       STRUCTURE_BLUE_FLAG,
    23       STRUCTURE_RED_FLAG
    24    };
    25 
    26    enum ObjectType {
    27       OBJECT_NONE,
    28       OBJECT_BLUE_FLAG,
    29       OBJECT_RED_FLAG
    30    };
    31 
    3232   class Object {
    3333   public:
     
    6767
    6868   void addObject(ObjectType type, int x, int y);
    69    void updateObject(unsigned int id, WorldMap::ObjectType t, int x, int y);
     69   void updateObject(unsigned int id, ObjectType t, int x, int y);
    7070   bool removeObject(unsigned int id);
    7171
Note: See TracChangeset for help on using the changeset viewer.