Changeset 384b7e0 in network-game


Ignore:
Timestamp:
Feb 12, 2013, 8:42:42 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
093c141
Parents:
62ee2ce
Message:

The client displays a small map upon login and lets the user move around

Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • client/Client/Client.vcxproj.filters

    r62ee2ce r384b7e0  
    5656    </ClCompile>
    5757    <ClCompile Include="..\..\common\WorldMap.cpp">
    58       <Filter>Source Files\gui</Filter>
     58      <Filter>Source Files\common</Filter>
    5959    </ClCompile>
    6060  </ItemGroup>
  • client/Client/main.cpp

    r62ee2ce r384b7e0  
    2929#include "../../common/Message.h"
    3030#include "../../common/Common.h"
     31#include "../../common/WorldMap.h"
    3132#include "../../common/Player.h"
    32 #include "../../common/WorldMap.h"
    3333
    3434#include "Window.h"
     
    160160   }
    161161
    162    WorldMap* gameMap = WorldMap::createDefaultMap();
     162   WorldMap* gameMap = WorldMap::loadMapFromFile("../../data/map.txt");
     163   //delete gameMap;
     164   //gameMap = WorldMap::createDefaultMap();
    163165
    164166   wndLogin = new Window(0, 0, SCREEN_W, SCREEN_H);
  • common/WorldMap.cpp

    r62ee2ce r384b7e0  
    11#include "WorldMap.h"
     2
     3#include <string>
     4#include <iostream>
     5#include <fstream>
     6#include <sstream>
    27
    38using namespace std;
     
    5762   return m;
    5863}
     64
     65WorldMap* 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

    r62ee2ce r384b7e0  
    2626
    2727   static WorldMap* createDefaultMap();
     28   static WorldMap* loadMapFromFile(string filename);
    2829};
    2930
Note: See TracChangeset for help on using the changeset viewer.