Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Map.h"
- #include<string>
- using namespace std;
- Map::Map(int mapIndex, string name, string description, string toWest, string toEast, string toNorth, string toSouth)
- {
- Map::setName(name);
- Map::setDescription(description);
- Map::setNeighbors(toWest, toEast, toNorth, toSouth);
- Map::setMapIndex(mapIndex);
- }
- void Map::setName(string name)
- {
- Map::m_name = name;
- }
- void Map::setDescription(string description)
- {
- Map::m_description = description;
- }
- void Map::setNeighbors(string toWest, string toEast, string toNorth, string toSouth)
- {
- Map::m_toWest = toWest;
- Map::m_toEast = toEast;
- Map::m_toNorth = toNorth;
- Map::m_toSouth = toSouth;
- }
- void Map::setMapIndex(int mapIndex)
- {
- Map::m_mapIndex = mapIndex;
- }
- bool Map::hasNeighbor(string direction)
- {
- if(direction.compare("East") == 0)
- {
- return Map::m_mapIndex + 1 <= 3;
- }
- if(direction.compare("West") == 0)
- {
- return Map::m_mapIndex - 1 >= 0;
- }
- if(direction.compare("North") == 0)
- {
- return Map::m_mapIndex - 2 >= 0;
- }
- if(direction.compare("South") == 0)
- {
- return Map::m_mapIndex + 2 <= 3;
- }
- }
- int Map::getNeighbor(string direction)
- {
- if(Map::hasNeighbor(direction))
- {
- if(direction.compare("East") == 0)
- {
- return m_mapIndex + 1;
- }
- if(direction.compare("West") == 0)
- {
- return m_mapIndex - 1;
- }
- if(direction.compare("North") == 0)
- {
- return m_mapIndex - 2;
- }
- if(direction.compare("South") == 0)
- {
- return m_mapIndex + 2;
- }
- }
- else if(!Map::hasNeighbor(direction))
- {
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement