- Timestamp:
- Jan 24, 2014, 12:27:15 AM (11 years ago)
- Branches:
- master
- Children:
- f66d04f
- Parents:
- e70b66b
- Location:
- common
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Game.cpp
re70b66b r7f884ea 102 102 } 103 103 104 void Game::addObjectToMap( WorldMap::ObjectType objectType, int x, int y) {104 void Game::addObjectToMap(ObjectType objectType, int x, int y) { 105 105 NETWORK_MSG serverMsg; 106 106 … … 120 120 if (0 <= x && x < this->worldMap->width*25 && 121 121 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) 123 123 { 124 124 p->target.x = x; … … 140 140 switch(this->worldMap->getElement(p->pos.x/25, p->pos.y/25)) 141 141 { 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: 145 145 { 146 146 p->pos = oldPos; … … 167 167 if (posDistance(p->pos, it->pos.toFloat()) < 10) { 168 168 switch (it->type) { 169 case WorldMap::OBJECT_BLUE_FLAG:169 case OBJECT_BLUE_FLAG: 170 170 if (p->team == 1) { 171 171 p->hasBlueFlag = true; … … 173 173 } 174 174 break; 175 case WorldMap::OBJECT_RED_FLAG:175 case OBJECT_RED_FLAG: 176 176 if (p->team == 0) { 177 177 p->hasRedFlag = true; … … 179 179 } 180 180 break; 181 case WorldMap::OBJECT_NONE:181 case OBJECT_NONE: 182 182 break; 183 183 } … … 198 198 if (p->isDead) 199 199 { 200 WorldMap::ObjectType flagType = WorldMap::OBJECT_NONE;200 ObjectType flagType = OBJECT_NONE; 201 201 if (p->hasBlueFlag) 202 flagType = WorldMap::OBJECT_BLUE_FLAG;202 flagType = OBJECT_BLUE_FLAG; 203 203 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) 207 207 this->addObjectToMap(flagType, p->pos.x, p->pos.y); 208 208 } … … 252 252 cout << "player move processed" << endl; 253 253 254 WorldMap::ObjectType flagType;254 ObjectType flagType; 255 255 POSITION pos; 256 256 bool flagTurnedIn = false; … … 260 260 switch(this->worldMap->getStructure(p->pos.x/25, p->pos.y/25)) 261 261 { 262 case WorldMap::STRUCTURE_BLUE_FLAG:262 case STRUCTURE_BLUE_FLAG: 263 263 { 264 264 if (p->team == 0 && p->hasRedFlag) 265 265 { 266 266 // 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); 268 268 269 269 vector<WorldMap::Object>* vctObjects = this->worldMap->getObjects(); … … 272 272 for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) 273 273 { 274 if (itObjects->type == WorldMap::OBJECT_BLUE_FLAG)274 if (itObjects->type == OBJECT_BLUE_FLAG) 275 275 { 276 276 if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12) … … 285 285 { 286 286 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); 289 289 flagTurnedIn = true; 290 290 this->blueScore++; … … 294 294 break; 295 295 } 296 case WorldMap::STRUCTURE_RED_FLAG:296 case STRUCTURE_RED_FLAG: 297 297 { 298 298 if (p->team == 1 && p->hasBlueFlag) 299 299 { 300 300 // 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); 302 302 303 303 vector<WorldMap::Object>* vctObjects = this->worldMap->getObjects(); … … 306 306 for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) 307 307 { 308 if (itObjects->type == WorldMap::OBJECT_RED_FLAG)308 if (itObjects->type == OBJECT_RED_FLAG) 309 309 { 310 310 if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12) … … 319 319 { 320 320 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); 323 323 flagTurnedIn = true; 324 324 this->redScore++; … … 385 385 { 386 386 if (p->team == 0 && 387 itObjects->type == WorldMap::OBJECT_BLUE_FLAG)387 itObjects->type == OBJECT_BLUE_FLAG) 388 388 { 389 structPos = this->worldMap->getStructureLocation( WorldMap::STRUCTURE_BLUE_FLAG);389 structPos = this->worldMap->getStructureLocation(STRUCTURE_BLUE_FLAG); 390 390 flagReturned = true; 391 391 break; 392 392 } 393 393 else if (p->team == 1 && 394 itObjects->type == WorldMap::OBJECT_RED_FLAG)394 itObjects->type == OBJECT_RED_FLAG) 395 395 { 396 structPos = this->worldMap->getStructureLocation( WorldMap::STRUCTURE_RED_FLAG);396 structPos = this->worldMap->getStructureLocation(STRUCTURE_RED_FLAG); 397 397 flagReturned = true; 398 398 break; -
common/Game.h
re70b66b r7f884ea 46 46 void setRedScore(unsigned int score); 47 47 48 void addObjectToMap( WorldMap::ObjectType objectType, int x, int y);48 void addObjectToMap(ObjectType objectType, int x, int y); 49 49 50 50 map<unsigned int, Player*>& getPlayers(); -
common/WorldMap.cpp
re70b66b r7f884ea 49 49 for (int x=0; x<this->width; x++) { 50 50 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); 53 53 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); 56 56 break; 57 case WorldMap::STRUCTURE_NONE:57 case STRUCTURE_NONE: 58 58 break; 59 59 } … … 62 62 } 63 63 64 WorldMap::TerrainType WorldMap::getElement(int x, int y)64 TerrainType WorldMap::getElement(int x, int y) 65 65 { 66 66 return (*(*vctMap)[x])[y]; … … 72 72 } 73 73 74 WorldMap::StructureType WorldMap::getStructure(int x, int y)74 StructureType WorldMap::getStructure(int x, int y) 75 75 { 76 76 return (*(*vctStructures)[x])[y]; … … 118 118 119 119 // used by the server to create new objects 120 void WorldMap::addObject( WorldMap::ObjectType t, int x, int y) {120 void WorldMap::addObject(ObjectType t, int x, int y) { 121 121 unsigned int id; 122 122 vector<WorldMap::Object>::iterator it; … … 137 137 138 138 // 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) {139 void WorldMap::updateObject(unsigned int id, ObjectType t, int x, int y) { 140 140 vector<WorldMap::Object>::iterator it; 141 141 bool foundObject = false; … … 143 143 cout << "Searching for object to update" << endl; 144 144 switch (t) { 145 case WorldMap::OBJECT_BLUE_FLAG:145 case OBJECT_BLUE_FLAG: 146 146 cout << "BLUE_FLAG" << endl; 147 147 break; 148 case WorldMap::OBJECT_RED_FLAG:148 case OBJECT_RED_FLAG: 149 149 cout << "RED_FLAG" << endl; 150 150 break; 151 case WorldMap::OBJECT_NONE:151 case OBJECT_NONE: 152 152 cout << "OBJECY_NONE" << endl; 153 153 break; … … 159 159 cout << "Found object with id " << id << endl; 160 160 switch (it->type) { 161 case WorldMap::OBJECT_BLUE_FLAG:161 case OBJECT_BLUE_FLAG: 162 162 cout << "BLUE_FLAG" << endl; 163 163 break; 164 case WorldMap::OBJECT_RED_FLAG:164 case OBJECT_RED_FLAG: 165 165 cout << "RED_FLAG" << endl; 166 166 break; 167 case WorldMap::OBJECT_NONE:167 case OBJECT_NONE: 168 168 cout << "OBJECY_NONE" << endl; 169 169 break; -
common/WorldMap.h
re70b66b r7f884ea 9 9 using namespace std; 10 10 11 enum TerrainType { 12 TERRAIN_NONE, 13 TERRAIN_GRASS, 14 TERRAIN_OCEAN, 15 TERRAIN_ROCK 16 }; 17 18 enum StructureType { 19 STRUCTURE_NONE, 20 STRUCTURE_BLUE_FLAG, 21 STRUCTURE_RED_FLAG 22 }; 23 24 enum ObjectType { 25 OBJECT_NONE, 26 OBJECT_BLUE_FLAG, 27 OBJECT_RED_FLAG 28 }; 29 11 30 class WorldMap { 12 31 public: 13 enum TerrainType {14 TERRAIN_NONE,15 TERRAIN_GRASS,16 TERRAIN_OCEAN,17 TERRAIN_ROCK18 };19 20 enum StructureType {21 STRUCTURE_NONE,22 STRUCTURE_BLUE_FLAG,23 STRUCTURE_RED_FLAG24 };25 26 enum ObjectType {27 OBJECT_NONE,28 OBJECT_BLUE_FLAG,29 OBJECT_RED_FLAG30 };31 32 32 class Object { 33 33 public: … … 67 67 68 68 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); 70 70 bool removeObject(unsigned int id); 71 71
Note:
See TracChangeset
for help on using the changeset viewer.