Changes in / [60017fc:093c141] in network-game
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/Client.vcxproj.filters
r60017fc r093c141 56 56 </ClCompile> 57 57 <ClCompile Include="..\..\common\WorldMap.cpp"> 58 <Filter>Source Files\ gui</Filter>58 <Filter>Source Files\common</Filter> 59 59 </ClCompile> 60 60 </ItemGroup> -
client/Client/main.cpp
r60017fc r093c141 29 29 #include "../../common/Message.h" 30 30 #include "../../common/Common.h" 31 #include "../../common/WorldMap.h" 31 32 #include "../../common/Player.h" 32 #include "../../common/WorldMap.h"33 33 34 34 #include "Window.h" … … 160 160 } 161 161 162 WorldMap* gameMap = WorldMap::createDefaultMap(); 162 WorldMap* gameMap = WorldMap::loadMapFromFile("../../data/map.txt"); 163 //delete gameMap; 164 //gameMap = WorldMap::createDefaultMap(); 163 165 164 166 wndLogin = new Window(0, 0, SCREEN_W, SCREEN_H); -
common/WorldMap.cpp
r60017fc r093c141 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 } -
common/WorldMap.h
r60017fc r093c141 26 26 27 27 static WorldMap* createDefaultMap(); 28 static WorldMap* loadMapFromFile(string filename); 28 29 }; 29 30
Note:
See TracChangeset
for help on using the changeset viewer.