#include "WorldMap.h" #include #include #include #include #include using namespace std; WorldMap::WorldMap(int width, int height) { this->width = width; this->height = height; vctMap = new vector*>(width); vctStructures = new vector*>(width); vctObjects = new vector(); for (int x=0; x* newMapVector = new vector(height); vector* newStructureVector = new vector(height); for (int y=0; y WorldMap::getObjects(int x, int y) { vector vctObjectsInRegion; return vctObjectsInRegion; } void WorldMap::addObject(int x, int y, WorldMap::ObjectType t) { WorldMap::Object o(t, x, y); vctObjects->push_back(o); } WorldMap* WorldMap::createDefaultMap() { WorldMap* m = new WorldMap(12l, 12); for(int x=0; x<12; x++) { for(int y=0; y<12; y++) { if (x ==0 || y == 0 || x == 11 || y == 11) m->setElement(x, y, TERRAIN_OCEAN); else m->setElement(x, y, TERRAIN_GRASS); m->setStructure(x, y, STRUCTURE_NONE); } } m->setElement(5, 5, TERRAIN_ROCK); return m; } WorldMap* WorldMap::loadMapFromFile(string filename) { WorldMap* m = new WorldMap(12l, 12); ifstream file(filename.c_str()); if (file.is_open()) { string line; int width, height; // read the map dimensions getline(file, line); if (line.size() > 0) { istringstream iss(line); string token; getline(iss, token, 'x'); width = atoi(token.c_str()); getline(iss, token, 'x'); height = atoi(token.c_str()); } cout << "width: " << width << endl; cout << "height: " << height << endl; // read the map contents int row = 0; while ( file.good() ) { getline(file, line); if (line.size() > 0) { cout << "line: " << line << endl; istringstream iss(line); string token; if (row < height) { // load terrain int type; TerrainType terrain; for(int x=0; xsetElement(x, row, terrain); } }else { // load objects int x, y, type; StructureType structure; getline(iss, token, ','); cout << "token(x): " << token << endl; x = atoi(token.c_str()); getline(iss, token, ','); cout << "token(y): " << token << endl; y = atoi(token.c_str()); getline(iss, token, ','); cout << "token(type): " << token << endl; type = atoi(token.c_str()); switch(type) { case 0: structure = STRUCTURE_NONE; break; case 1: structure = STRUCTURE_BLUE_FLAG; break; case 2: structure = STRUCTURE_RED_FLAG; break; } m->setStructure(x, y, structure); } } row++; } file.close(); } else cout << "Could not open the file" << endl; return m; } /*** Functions for Object ***/ WorldMap::Object::Object(ObjectType type, POSITION pos) { this->type = type; this->pos = pos; } WorldMap::Object::Object(ObjectType type, int x, int y) { this->type = type; this->pos.x = x; this->pos.y = y; } WorldMap::Object::~Object() { }