title: C++ Text Adventure Game: 2D Array's as a map
body: <p>OK, so Im working on a pretty simple Text Adventure game. Right now I have a functioning menu, and a very simple "battle mode" which will be converted into a random encounter as soon as I can. What Im having trouble with right now though is the map.</p>
  
  <p>The idea is to use a 2D Array system as a map, with locations being stored as co-ordinates (if that makes sense.) You can enter 4 directions, "North, East, South and West" to move around, and there are 3 types places you can go. A field, a forest, and a castle. And the map itself, is 5 by 6 in size.</p>
  
  <p>What I want to do is make it so you start in the centre at co-ordinates 2, 2 and you can move around to, say a field for example (designated by a 1 with the integers at the top) it says "You are in a field" and do similar stuff for moving towards the castle, the forests, etc. I also want it to tell the player if they try move to a location marked with a 0 that they can't go there and stop them from moving.  </p>
  
  <p>Has anyone got any advice?</p>
  
  <p>EDIT: OK, so I ran through my program again and I've managed to get rid of some errors but I still have a bunch more left (26 to be exact, and 1 warning.)
  Is anyone willing to offer me some suggestions?</p>
  
  <pre><code>#pragma once
  #include "Map.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  Map::Map()
  {
  }
  
  void main()
  {
      // Declare variables &amp; functions
      int locationy;
      int locationx;
  
      char oper;
      char location;
  
      int pond = 0;
      int field = 1;
      int forest = 2;
      int castle = 3;
  
      int mapy;
      int mapx;
      int map;
  
      //These two values declare the start location on the array map for the player
      int mapy = 3;
      int mapx = 3;
  
      //These two variables track your current position on the map
      mapy = 2;
      mapx = 2;
  
      map[locationy][locationx];
  
      //Declares the amount of space within an array
      int map[6][6] = 
      {
          { 0, 0, 0, 0, 0, 0 },
          { 0, 2, 1, 2, 1, 0 },
          { 0, 1, 2, 1, 2, 0 },
          { 0, 1, 2, 2, 1, 0 },
          { 0, 1, 3, 1, 2, 0 },
          { 0, 0, 0, 0, 0, 0 }
      };
  
      //Asks the player where they want to go around the map
      cout &lt;&lt; "Where to?" &lt;&lt; endl;
  
      //Request for user to enter an direction (I.e., North, East, South, West.)
      cout &lt;&lt; "Please choose  North, East, South or West" &lt;&lt; endl;
  
      //Displays the inputted values
      cin &gt;&gt; oper;
  
      //Pauses system so we can see what the program does
      system("pause");
  
      //Checks input from the player
      if (cin == "North")
      {
          //Moves location upwards on the y axis
          if (map[locationx][locationy + 1] != 0) { locationy += 1; };
          else { cout &lt;&lt; "That is water, dude. Swimming in platemail is NOT recommended.\n";
      }
  
      //Checks input from the player
          if (cin == "East")
      {
          //Moves location to the right on the x axis
          if (map[locationx + 1][locationy] != 0) { locationy += 1; };
          else { cout &lt;&lt; "That is water, dude. Swimming in platemail is NOT recommended.\n";
      }
  
      //Checks input from the player
      if (cin == "South")
      {
          //Moves location downwards on the y axis
          if (map[locationx][locationy - 1] != 0) { locationy += 1; }
          else { cout &lt;&lt; "That is water, dude. Swimming in platemail is NOT recommended.\n";
      }
  
      //Checks input from the player
      if (cin == "West")
      {
          //Moves location to the left on the x axis
          if (map[locationx - 1][locationy] != 0) { locationy += 1; }
          else { cout &lt;&lt; "That is water, dude. Swimming in platemail is NOT recommended.\n"
  
      };
  }
  
  Map::~Map()
  {
      ;
  }
  </code></pre>