Changeset 62ee2ce in network-game for common


Ignore:
Timestamp:
Feb 5, 2013, 7:02:32 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
384b7e0, 60017fc
Parents:
60b77d2
Message:

The client shows the map and converts between screen and map coordinates

Location:
common
Files:
2 edited
2 moved

Legend:

Unmodified
Added
Removed
  • common/Common.h

    r60b77d2 r62ee2ce  
    1818   int x;
    1919   int y;
    20 } PLAYER_POS;
     20} POSITION;
    2121
    2222#endif
  • common/Player.h

    r60b77d2 r62ee2ce  
    3636   string password;
    3737   sockaddr_in addr;
    38    PLAYER_POS pos;
     38   POSITION pos;
    3939};
    4040
  • common/WorldMap.cpp

    r60b77d2 r62ee2ce  
    1 #include "Map.h"
     1#include "WorldMap.h"
    22
    33using namespace std;
    44
    5 Map::Map(int width, int height)
     5WorldMap::WorldMap(int width, int height)
    66{
    77   this->width = width;
     
    2020}
    2121
    22 Map::~Map()
     22WorldMap::~WorldMap()
    2323{
    2424   for (int x=0; x<width; x++)
     
    2828}
    2929
    30 void Map::setElement(int x, int y, TerrainType t)
     30WorldMap::TerrainType WorldMap::getElement(int x, int y)
     31{
     32   return (*(*vctMap)[x])[y];
     33}
     34
     35void WorldMap::setElement(int x, int y, TerrainType t)
    3136{
    3237   (*(*vctMap)[x])[y] = t;
    3338}
    3439
    35 Map* Map::createDefaultMap()
     40WorldMap* WorldMap::createDefaultMap()
    3641{
    37    Map* m = new Map(20l, 20);
     42   WorldMap* m = new WorldMap(12l, 12);
    3843
    39    for(int x=0; x<20; x++)
     44   for(int x=0; x<12; x++)
    4045   {   
    41       for(int y=0; y<20; y++)
     46      for(int y=0; y<12; y++)
    4247      {
    43          if (x ==0 || y == 0 || x == 19 || y == 19)
     48         if (x ==0 || y == 0 || x == 11 || y == 11)
    4449            m->setElement(x, y, TERRAIN_OCEAN);
    4550         else
     
    4853   }
    4954
     55   m->setElement(5, 5, TERRAIN_ROCK);
     56
    5057   return m;
    5158}
  • common/WorldMap.h

    r60b77d2 r62ee2ce  
    1 #ifndef _MAP_H
    2 #define _MAP_H
     1#ifndef _WORLDMAP_H
     2#define _WORLDMAP_H
    33
    44#include <vector>
     
    66using namespace std;
    77
    8 class Map {
     8class WorldMap {
    99public:
    1010   enum TerrainType {
    1111      TERRAIN_NONE,
    1212      TERRAIN_GRASS,
    13       TERRAIN_OCEAN
     13      TERRAIN_OCEAN,
     14      TERRAIN_ROCK
    1415   };
    1516
     
    1718   vector<vector<TerrainType>*>* vctMap;
    1819
    19    Map(int width, int height);
     20   WorldMap(int width, int height);
    2021
    21    ~Map();
     22   ~WorldMap();
    2223
     24   TerrainType getElement(int x, int y);
    2325   void setElement(int x, int y, TerrainType type);
    2426
    25    static Map* createDefaultMap();
     27   static WorldMap* createDefaultMap();
    2628};
    2729
Note: See TracChangeset for help on using the changeset viewer.