- Timestamp:
- May 19, 2013, 7:12:07 PM (12 years ago)
- Branches:
- master
- Children:
- cc1c6c1
- Parents:
- 035d852
- Location:
- common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Player.cpp
r035d852 r05051c7 124 124 // using moveCanceled in a hacky way just to indicate that the server 125 125 // has updated some player info. Should change the variable name 126 switch(map->get Object(newPos.x/25, newPos.y/25)) {127 case WorldMap:: OBJECT_BLUE_FLAG:126 switch(map->getStructure(newPos.x/25, newPos.y/25)) { 127 case WorldMap::STRUCTURE_BLUE_FLAG: 128 128 hasBlueFlag = true; 129 129 moveCanceled = true; 130 130 break; 131 case WorldMap:: OBJECT_RED_FLAG:131 case WorldMap::STRUCTURE_RED_FLAG: 132 132 hasRedFlag = true; 133 133 moveCanceled = true; -
common/WorldMap.cpp
r035d852 r05051c7 15 15 16 16 vctMap = new vector<vector<TerrainType>*>(width); 17 vctObjects = new vector<vector<ObjectType>*>(width); 17 vctStructures = new vector<vector<StructureType>*>(width); 18 vctObjects = new vector<Object>(); 18 19 19 20 for (int x=0; x<width; x++) { 20 21 vector<TerrainType>* newMapVector = new vector<TerrainType>(height); 21 vector< ObjectType>* newObjectVector = new vector<ObjectType>(height);22 vector<StructureType>* newStructureVector = new vector<StructureType>(height); 22 23 23 24 for (int y=0; y<height; y++) { 24 25 (*newMapVector)[y] = TERRAIN_NONE; 25 (*new ObjectVector)[y] = OBJECT_NONE;26 (*newStructureVector)[y] = STRUCTURE_NONE; 26 27 } 27 28 28 29 (*vctMap)[x] = newMapVector; 29 (*vct Objects)[x] = newObjectVector;30 (*vctStructures)[x] = newStructureVector; 30 31 } 31 32 } … … 35 36 for (int x=0; x<width; x++) { 36 37 delete (*vctMap)[x]; 37 delete (*vct Objects)[x];38 delete (*vctStructures)[x]; 38 39 } 39 40 40 41 delete vctMap; 42 delete vctStructures; 41 43 delete vctObjects; 42 44 } … … 49 51 void WorldMap::setElement(int x, int y, TerrainType t) 50 52 { 51 cout << "getting element" << endl;52 53 (*(*vctMap)[x])[y] = t; 53 54 } 54 55 55 WorldMap::ObjectType WorldMap::getObject(int x, int y) 56 { 57 return (*(*vctObjects)[x])[y]; 58 } 59 60 void WorldMap::setObject(int x, int y, ObjectType t) 61 { 62 cout << "getting object" << endl; 63 (*(*vctObjects)[x])[y] = t; 56 WorldMap::StructureType WorldMap::getStructure(int x, int y) 57 { 58 return (*(*vctStructures)[x])[y]; 59 } 60 61 void WorldMap::setStructure(int x, int y, StructureType t) 62 { 63 (*(*vctStructures)[x])[y] = t; 64 } 65 66 vector<WorldMap::Object> WorldMap::getObjects(int x, int y) { 67 vector<WorldMap::Object> vctObjectsInRegion; 68 69 return vctObjectsInRegion; 70 } 71 72 void WorldMap::addObject(int x, int y, WorldMap::ObjectType t) { 73 WorldMap::Object o(t, x, y); 74 75 vctObjects->push_back(o); 64 76 } 65 77 … … 77 89 m->setElement(x, y, TERRAIN_GRASS); 78 90 79 m->set Object(x, y, OBJECT_NONE);91 m->setStructure(x, y, STRUCTURE_NONE); 80 92 } 81 93 } … … 158 170 159 171 int x, y, type; 160 ObjectType object;172 StructureType structure; 161 173 162 174 getline(iss, token, ','); … … 174 186 switch(type) { 175 187 case 0: 176 object = OBJECT_NONE;188 structure = STRUCTURE_NONE; 177 189 break; 178 190 case 1: 179 object = OBJECT_BLUE_FLAG;191 structure = STRUCTURE_BLUE_FLAG; 180 192 break; 181 193 case 2: 182 object = OBJECT_RED_FLAG;194 structure = STRUCTURE_RED_FLAG; 183 195 break; 184 196 } 185 197 186 m->set Object(x, y, object);198 m->setStructure(x, y, structure); 187 199 } 188 200 } … … 197 209 return m; 198 210 } 211 212 213 /*** Functions for Object ***/ 214 215 WorldMap::Object::Object(ObjectType type, POSITION pos) { 216 this->type = type; 217 this->pos = pos; 218 } 219 220 WorldMap::Object::Object(ObjectType type, int x, int y) { 221 this->type = type; 222 this->pos.x = x; 223 this->pos.y = y; 224 } 225 226 WorldMap::Object::~Object() { 227 } -
common/WorldMap.h
r035d852 r05051c7 5 5 6 6 #include <vector> 7 8 #include "Common.h" 7 9 8 10 using namespace std; … … 17 19 }; 18 20 21 enum StructureType { 22 STRUCTURE_NONE, 23 STRUCTURE_BLUE_FLAG, 24 STRUCTURE_RED_FLAG 25 }; 26 19 27 enum ObjectType { 20 28 OBJECT_NONE, … … 23 31 }; 24 32 33 class Object { 34 public: 35 ObjectType type; 36 POSITION pos; 37 38 Object(ObjectType type, int x, int y); 39 Object(ObjectType type, POSITION pos); 40 41 ~Object(); 42 }; 43 25 44 int width, height; 26 45 vector<vector<TerrainType>*>* vctMap; 27 vector<vector<ObjectType>*>* vctObjects; 46 vector<vector<StructureType>*>* vctStructures; 47 vector<Object>* vctObjects; 28 48 29 49 WorldMap(int width, int height); … … 34 54 void setElement(int x, int y, TerrainType type); 35 55 36 ObjectType getObject(int x, int y); 37 void setObject(int x, int y, ObjectType type); 56 StructureType getStructure(int x, int y); 57 void setStructure(int x, int y, StructureType type); 58 59 vector<Object> getObjects(int x, int y); 60 void addObject(int x, int y, ObjectType type); 38 61 39 62 static WorldMap* createDefaultMap();
Note:
See TracChangeset
for help on using the changeset viewer.