SHARE
TWEET

Map Navigator Part II Map.cpp

zCool May 13th, 2012 14 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Map.h"
  2. #include<string>
  3. using namespace std;
  4.  
  5. Map::Map(int mapIndex, string name, string description, string toWest, string toEast, string toNorth, string toSouth)
  6. {
  7.         Map::setName(name);
  8.         Map::setDescription(description);
  9.         Map::setNeighbors(toWest, toEast, toNorth, toSouth);
  10.         Map::setMapIndex(mapIndex);
  11. }
  12.  
  13. void Map::setName(string name)
  14. {
  15.         Map::m_name = name;
  16. }
  17.  
  18. void Map::setDescription(string description)
  19. {
  20.         Map::m_description = description;
  21. }
  22.  
  23. void Map::setNeighbors(string toWest, string toEast, string toNorth, string toSouth)
  24. {
  25.         Map::m_toWest = toWest;
  26.         Map::m_toEast = toEast;
  27.         Map::m_toNorth = toNorth;
  28.         Map::m_toSouth = toSouth;
  29. }
  30.  
  31. void Map::setMapIndex(int mapIndex)
  32. {
  33.         Map::m_mapIndex = mapIndex;
  34. }
  35.  
  36. bool Map::hasNeighbor(string direction)
  37. {
  38.         if(direction.compare("East") == 0)
  39.         {
  40.                 return Map::m_mapIndex + 1 <= 3;
  41.         }
  42.  
  43.         if(direction.compare("West") == 0)
  44.         {
  45.                 return Map::m_mapIndex - 1 >= 0;
  46.         }
  47.  
  48.         if(direction.compare("North") == 0)
  49.         {
  50.                 return Map::m_mapIndex - 2 >= 0;
  51.         }
  52.  
  53.         if(direction.compare("South") == 0)
  54.         {
  55.                 return Map::m_mapIndex + 2 <= 3;
  56.         }
  57. }
  58.  
  59. int Map::getNeighbor(string direction)
  60. {
  61.         if(Map::hasNeighbor(direction))
  62.         {
  63.                 if(direction.compare("East") == 0)
  64.                 {
  65.                         return m_mapIndex + 1;
  66.                 }
  67.  
  68.                 if(direction.compare("West") == 0)
  69.                 {
  70.                         return m_mapIndex - 1;
  71.                 }
  72.  
  73.                 if(direction.compare("North") == 0)
  74.                 {
  75.                         return m_mapIndex - 2;
  76.                 }
  77.  
  78.                 if(direction.compare("South") == 0)
  79.                 {
  80.                         return m_mapIndex + 2;
  81.                 }
  82.         }
  83.         else if(!Map::hasNeighbor(direction))
  84.         {
  85.                 return -1;
  86.         }
  87. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top