title: How to make movable character in maze with C++
body: <p>So I have my maze printed out once the user presses 1 in order to launch the map and other variables. I have declared the player as a smiley face or set equal to 1. However, I would like to make this character movable throughout the maze but am having trouble doing so. I have created a player move as a space in order for it to move without overwriting other code. I was thinking of using a switch statement and detecting user input and then changing the X and Y positions based on that but I dont know how to put it in my mapCreation function. I was also wondering if you guys could help me generate the variables such as treasures at random locations throughout the map and if it is a wall or '|' then dont print. My treasures spawn but at the same location. Any input on any of my questions would really help! Thank you!</p>
  
  <p>** Ignore the cases as they were just being used previously but now I dont have a use for them.</p>
  
  <p>**UPDATE
  If anyone has a link somewhere that would help that would also be helpful! Thank you!</p>
  
  <pre><code>// Header Files
  #include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  
  
  using namespace std; 
  
  HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); // For use of SetConsoleTextAttribute()
  
  
  #define LEVEL_COUNT (2)
  const char* maze[LEVEL_COUNT][12] = 
  {
          {
              "||||||||||||\n",
              "|       |  |\n",
              "|       |  |\n",
              "|    ||||  |",
              "|          |",
              "|          |",
              "||||||     |",
              "| |        |",
              "| |    |   |",
              "|      |   |",
              "|      |   |",
              "||||||||||||",
          },
         {
              "||||||||||||",
              "|       |  |",
              "|   |||||  |",
              "|       |  |",
              "|          |",
              "|       ||||",
              "|          |",
              "|   |      |",
              "|   |      |",
              "|||||||    |",
              "|          |",
              "||||||||||||",
          }, 
  };
  
  // Function Prototypes
  
  void titleScreen(); // Prints Title and instructions
  
  void mapCreation( char arr[][12], int level);
  
  void drawMap(char arr[][12]);
  
  bool update(char arr[][12], int &amp;level, int &amp;lives, int &amp;score);
  
  void loadMap( char arr[][12], int level);
  
  // Player Struct
  struct Player{
      int x;
      int y;
      char move;
  };
  
  
  
  // Main Program
  int main ()
      {
      // initialize variables
      int option;
      char baseMap[12][12];
      int level = 1;
      int lives = 3;
      int score = 0;
      bool gameOver = false;
      bool levelCompleted = false;
  
  
      SetConsoleTextAttribute(console, 240); // change background to white
  
      system("CLS");// clears screen in order to remove black background
  
      titleScreen(); // Display Title
  
      do // do-while loop starts
      {
  
      cin &gt;&gt; option; // take in input
  
          if(option == 1) // temporary option to check for next screen
              {
              //Display Maze
  
              system("CLS");// clears screen in order to remove black background
  
                   mapCreation( baseMap, 1 ); // Create map, this one is map 1
  
                   drawMap(baseMap); // iterate throup the map and print it out
                      //   update(baseMap, level, lives, score);
  
  
  
               }
            if(option == 2)
              {
              //Display Maze
  
              system("CLS");// clears screen in order to remove black background
  
                   mapCreation( baseMap, 2 ); // Create map, this one is map 1
  
                   drawMap(baseMap); // iterate throup the map and print it out
                      //   update(baseMap, level, lives, score);
               }
  
          }
      while( option !=1); // condition of do-while loop
  
      system("pause"); // Pause for user, only temporary
  
      return 0;
  
  }
  
  
  
  
  
  
  
  
  void titleScreen(){
  
      cout &lt;&lt; " Welcome to Treasure Hunter!\n\n";
      cout &lt;&lt; "In order to beat this game you must find the treasure\n";
      cout &lt;&lt; " that is located in the maze. You can move using the \n";
      cout &lt;&lt; " arrow keys or WASD.\n\n";
      cout &lt;&lt; " Warning! There are traps that will take life away as\n";
      cout &lt;&lt; " well as add life! However, they are hidden so be careful!\n ";
      cout &lt;&lt; " Goodluck and have fun!\n\n\n\n";
      cout &lt;&lt; " Press Ctrl+C to quit\n";
  
  
  }
  
  
  void mapCreation( char arr[12][12], int level )
      {
        int traps = 0;   
        int lives = 0;
        int treasure = 0;
        int x ;
        int y ;
          for(int i = 0; i &lt; 12; i++)
              {
               for(int j = 0; j &lt; 12; j++)
                  {
                   arr[i][j] = 0;
                  }
  
              }
  
          // load the map:
          loadMap(arr,level);
  
          switch (level)
          {
          case 1:
  
  
  
  
          break;
  
          case 2: // Level 2 Map
  
          break;
          }
      }
  
  void drawMap(char arr[12][12])
      {
          // Declare variables to be prtined out
        Player player;
        player.x = 1;
        player.y = 1;
        player.move = ' ';
        int traps = 0;   
        int lives = 0;
        int treasure = 0;
        // Lives,Traps, and Treasure x and y positions
        int Trap_Y,Trap_X,Lives_X,Lives_Y,Traps_X,Traps_Y; 
        // Randomly place variables
        Trap_X = (rand() % 10);
        Trap_Y = (rand() % 10);  
        Lives_X = (rand() % 12);
        Lives_Y = (rand() % 12);
        Traps_X = (rand() % 12);
        Traps_Y = (rand() % 12);    
  
       for(int i = 0; i &lt; 12; i++)
          {
          cout &lt;&lt; endl; // print out new line
           for(int j = 0; j &lt; 12; j++ )
              {
                  if(player.x == i &amp;&amp; player.y == j)
                  arr[player.x][player.y] = 1;                        
  
  
  
  
                  // If variables are  not equal to a wall character print it out
                   if(arr[Trap_X][Trap_Y] != '|' )                         
                  arr[Trap_X][Trap_Y] = 4; // treasure is 4
                  treasure++;
                  if(arr[Lives_X][Lives_Y] != '|')// traps are 2
                   arr[Lives_X][Lives_Y]= 2; 
                   traps++;
                  if(arr[Traps_X][Traps_Y] != '|') // lives are 3
                   arr[Traps_X][Traps_Y]= 3;
                   lives++;
  
  
                  cout &lt;&lt; arr[i][j];
  
              }
          }
          cout &lt;&lt; endl;
      }
  
  /*bool update(char arr[][12], int &amp;level, int &amp;lives, int &amp;score)
      {
       bool levelCompleted = false;
       bool gameOver = false;
      }
  */
  
  
  void loadMap( char arr[][12], int level)
  {
       if((level &lt; 0) || (level &gt;= LEVEL_COUNT))
           return;
  
       for(int i = 0; i &lt; 12; i++)
       {
           const char* row = maze[level][i];
           for(int j = 0; j &lt; 12; j++)
           {
               if(row[j] == 0)
                   break; // end of string
               if(row[j] == ' ')
                   arr[i][j] = 0;  // set spaces to zero
               else
                   arr[i][j] = row[j];
           }
       }
  }
  </code></pre>