#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); for (int x=0; x* newVector = new vector(height); for (int y=0; ysetElement(x, y, TERRAIN_OCEAN); else m->setElement(x, y, TERRAIN_GRASS); } } 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; int type; TerrainType terrain; for(int x=0; xsetElement(x, row, terrain); } } row++; } file.close(); } else cout << "Could not open the file" << endl; return m; }