Changes in common/WorldMap.cpp [62ee2ce:384b7e0] in network-game
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
common/WorldMap.cpp
r62ee2ce r384b7e0 1 1 #include "WorldMap.h" 2 3 #include <string> 4 #include <iostream> 5 #include <fstream> 6 #include <sstream> 2 7 3 8 using namespace std; … … 57 62 return m; 58 63 } 64 65 WorldMap* WorldMap::loadMapFromFile(string filename) 66 { 67 WorldMap* m = new WorldMap(12l, 12); 68 69 ifstream file(filename); 70 71 if (file.is_open()) 72 { 73 string line; 74 int width, height; 75 76 // read the map dimensions 77 getline(file, line); 78 if (line.size() > 0) 79 { 80 istringstream iss(line); 81 string token; 82 getline(iss, token, 'x'); 83 width = atoi(token.c_str()); 84 getline(iss, token, 'x'); 85 height = atoi(token.c_str()); 86 } 87 88 cout << "width: " << width << endl; 89 cout << "height: " << height << endl; 90 91 // read the map contents 92 int row = 0; 93 while ( file.good() ) 94 { 95 getline(file, line); 96 if (line.size() > 0) 97 { 98 cout << "line: " << line << endl; 99 100 istringstream iss(line); 101 string token; 102 int type; 103 TerrainType terrain; 104 105 for(int x=0; x<width; x++) 106 { 107 getline(iss, token, ','); 108 cout << "token: " << token << endl; 109 type = atoi(token.c_str()); 110 cout << "type: " << type << endl; 111 112 switch(type) { 113 case 1: 114 terrain = TERRAIN_GRASS; 115 break; 116 case 2: 117 terrain = TERRAIN_OCEAN; 118 break; 119 case 3: 120 terrain = TERRAIN_ROCK; 121 break; 122 } 123 124 cout << "About to set element" << endl; 125 cout << "x: " << x << endl; 126 cout << "row: " << row << endl; 127 m->setElement(x, row, terrain); 128 } 129 } 130 131 row++; 132 } 133 file.close(); 134 } 135 else 136 cout << "Could not open the file" << endl; 137 138 return m; 139 }
Note:
See TracChangeset
for help on using the changeset viewer.