Changeset a1a3bd5 in network-game for common/WorldMap.cpp
- Timestamp:
- Apr 23, 2013, 1:31:54 AM (12 years ago)
- Branches:
- master
- Children:
- 227baaa
- Parents:
- 054b50b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
common/WorldMap.cpp
r054b50b ra1a3bd5 15 15 16 16 vctMap = new vector<vector<TerrainType>*>(width); 17 vctObjects = new vector<vector<ObjectType>*>(width); 17 18 18 19 for (int x=0; x<width; x++) { 19 vector<TerrainType>* newVector = new vector<TerrainType>(height); 20 vector<TerrainType>* newMapVector = new vector<TerrainType>(height); 21 vector<ObjectType>* newObjectVector = new vector<ObjectType>(height); 20 22 21 for (int y=0; y<height; y++) 22 (*newVector)[y] = TERRAIN_NONE; 23 for (int y=0; y<height; y++) { 24 (*newMapVector)[y] = TERRAIN_NONE; 25 (*newObjectVector)[y] = OBJECT_NONE; 26 } 23 27 24 (*vctMap)[x] = newVector; 28 (*vctMap)[x] = newMapVector; 29 (*vctObjects)[x] = newObjectVector; 25 30 } 26 31 } … … 28 33 WorldMap::~WorldMap() 29 34 { 30 for (int x=0; x<width; x++) 35 for (int x=0; x<width; x++) { 31 36 delete (*vctMap)[x]; 37 delete (*vctObjects)[x]; 38 } 32 39 33 40 delete vctMap; 41 delete vctObjects; 34 42 } 35 43 … … 43 51 cout << "getting element" << endl; 44 52 (*(*vctMap)[x])[y] = t; 53 } 54 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; 45 64 } 46 65 … … 57 76 else 58 77 m->setElement(x, y, TERRAIN_GRASS); 78 79 m->setObject(x, y, OBJECT_NONE); 59 80 } 60 81 } … … 102 123 istringstream iss(line); 103 124 string token; 104 int type;105 TerrainType terrain;106 125 107 for(int x=0; x<width; x++) 108 { 126 if (row < height) { 127 // load terrain 128 129 int type; 130 TerrainType terrain; 131 132 for(int x=0; x<width; x++) 133 { 134 getline(iss, token, ','); 135 cout << "token: " << token << endl; 136 type = atoi(token.c_str()); 137 cout << "type: " << type << endl; 138 139 switch(type) { 140 case 1: 141 terrain = TERRAIN_GRASS; 142 break; 143 case 2: 144 terrain = TERRAIN_OCEAN; 145 break; 146 case 3: 147 terrain = TERRAIN_ROCK; 148 break; 149 } 150 151 cout << "About to set element" << endl; 152 cout << "x: " << x << endl; 153 cout << "row: " << row << endl; 154 m->setElement(x, row, terrain); 155 } 156 }else { 157 // load objects 158 159 int x, y, type; 160 ObjectType object; 161 109 162 getline(iss, token, ','); 110 cout << "token: " << token << endl; 163 cout << "token(x): " << token << endl; 164 x = atoi(token.c_str()); 165 166 getline(iss, token, ','); 167 cout << "token(y): " << token << endl; 168 y = atoi(token.c_str()); 169 170 getline(iss, token, ','); 171 cout << "token(type): " << token << endl; 111 172 type = atoi(token.c_str()); 112 cout << "type: " << type << endl;113 173 114 174 switch(type) { 175 case 0: 176 object = OBJECT_NONE; 177 break; 115 178 case 1: 116 terrain = TERRAIN_GRASS;179 object = OBJECT_RED_FLAG; 117 180 break; 118 181 case 2: 119 terrain = TERRAIN_OCEAN; 120 break; 121 case 3: 122 terrain = TERRAIN_ROCK; 182 object = OBJECT_BLUE_FLAG; 123 183 break; 124 184 } 125 185 126 cout << "About to set element" << endl; 127 cout << "x: " << x << endl; 128 cout << "row: " << row << endl; 129 m->setElement(x, row, terrain); 186 m->setObject(x, y, object); 130 187 } 131 188 }
Note:
See TracChangeset
for help on using the changeset viewer.