I can't seem to figure out why it keeps repeating level one anyone got a suggestion on how to fix it?

#include <iostream.h>
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>

int mx=14;
int my=1;
int i, j;
char direction = ' ';
char facing = 'S';
char matrix[100][100];


void gotoxy(short x, short y)
{
      HANDLE hConsoleOutput;
      COORD Cursor_an_Pos = {x,y};
      hConsoleOutput = GetStdHandle (STD_OUTPUT_HANDLE);
      SetConsoleCursorPosition(hConsoleOutput, Cursor_an_Pos);
}



void loadlevel(int levelnumber)
{     
	if(levelnumber == 1)
	{
		for(i=0; i<60; i++)
		{
				for(j=0; j<60; j++)
				{
				strcpy(matrix[0], "----------------------------------------");
				strcpy(matrix[1], "| | |      |   | | |   |         |     |");
				strcpy(matrix[2], "| | |----  |   | | |-- | ----    |     |");
				strcpy(matrix[3], "|        |   | | | |   |   | |    |    |");
				strcpy(matrix[4], "|  ----  |---| | | | --|-  | |----| -  |");
				strcpy(matrix[5], "| |    | |   |   |       | | |    |  | |");
				strcpy(matrix[6], "| |----| |  -|-  |--     | | |  --|- | |");
				strcpy(matrix[7], "| |                      | |           |");
				strcpy(matrix[8], "|-|-           -----     | |-----   ---|");
				strcpy(matrix[9], "|           |    |                  |  |");
				strcpy(matrix[10],"|     ---   |-   |  --------        |  |");
				strcpy(matrix[11],"|   |  |         |       |       |     |");
				strcpy(matrix[12],"|   |  |  ----   |       |  ---  |---  |");
				strcpy(matrix[13],"| | |  |      |  |       |  |  |     | |");
				strcpy(matrix[14],"| | | -|      |  |    ---|  |  |     | |");
				strcpy(matrix[15],"| | |     |   |  | |     |     |     | |");
				strcpy(matrix[16],"|-| |---  |   |  | |-    |   --|--   | |");
				strcpy(matrix[17],"|         |   |          |         |   |");
				strcpy(matrix[18],"|  --  ---|   |------    |-------  |   |");
				strcpy(matrix[19],"|  | |           |           | | | | | |");
				strcpy(matrix[20],"|--| |---  ---   |-----------| |-|-|-| |");
				strcpy(matrix[21],"|          |     |           |       | |");
				strcpy(matrix[22],"|          |     |      -----|-      | |");
				strcpy(matrix[23],"|          | |   |                 | | |");
				strcpy(matrix[24],"| --  -----|-|---|                 | | |");
				strcpy(matrix[25],"| |     |    |       |           | |    ");
				strcpy(matrix[26],"| |     |    |  ---  |---   ---  |-|--- ");
				strcpy(matrix[27],"| |   | | |  |               |   |      ");
				strcpy(matrix[28],"| |   |-|-|  |  -------      |  -|-    |");
				strcpy(matrix[29],"| | | | | |  |    |          | |       |");
				strcpy(matrix[30],"| | | | | |  |    |----------| |  -----|");
				strcpy(matrix[31],"| | |   |    | |  |            |     | |");
				strcpy(matrix[32],"| | |---|----| |  |  ---     --|-----| |");
				strcpy(matrix[33],"|       |      |               |     | |");
				strcpy(matrix[34],"|-----  |      |     ----------|  ---| |");
				strcpy(matrix[35],"|       |    | |               |  |    |");
				strcpy(matrix[36],"|-----  |    |-|          -----|  |    |");
				strcpy(matrix[37],"|       |  | |     |              | |  |");
				strcpy(matrix[38],"|       |  | |    -|-             | |  |");
				strcpy(matrix[39],"|  | |     |                      | |  |");
				strcpy(matrix[40],"|  | |---  |             ---------| |--|");
				strcpy(matrix[41],"|  | |   | |    |    | | |             |");
				strcpy(matrix[42],"|  | |   | |    |    |-|-|         ----|");
				strcpy(matrix[43],"|  | |     |    | |         |  |       |");
				strcpy(matrix[44],"|  | |-----|    |-|-        |  | ----  |");
				strcpy(matrix[45],"|  |    |           |       |  |     | |");
				strcpy(matrix[46],"|  |----|  ------   |---    |  |  -  | |");
				strcpy(matrix[47],"|     |    |            |   |  |   | | |");
				strcpy(matrix[48]," ------------------------OOO----------- ");


				}
		  }
	}
	if(levelnumber == 2)
	{
		for(i=0; i<60; i++)
		{
				for(j=0; j<60; j++)
				{
					//The left middle maze section.
				strcpy(matrix[0], " ");
				strcpy(matrix[1], "------------------------------------------");
				strcpy(matrix[2], "|      | |            |  |    |  |       |");
				strcpy(matrix[3], "|---   | | -----      |  |    |  |       |");
				strcpy(matrix[4], "|   |  | |   |   |       |    |  |       |");
				strcpy(matrix[5], "|   |  | |-  | --|  -----|    |  |  -----|");
				strcpy(matrix[6], "|   |  |     |       |        |  |  |    |");
				strcpy(matrix[7], "|  -|  |---  |       |    ----|  |  |    |");
				strcpy(matrix[8], "| |     |  | | |  |    |         |  | |  |");
				strcpy(matrix[9], "| |---  |  | | |  |    |         |  | |  |");
				strcpy(matrix[10],"| |     |      |  |    |         |  | |  |");
				strcpy(matrix[11],"| |---  |  ----|- |----|   ------|  | |  |");
				strcpy(matrix[12],"|     |                  | |  |       |  |");
				strcpy(matrix[13],"|     |              ----| |  |   ----|  |");
				strcpy(matrix[14],"|   | |                | | |  |    |  |  |");
				strcpy(matrix[15],"|---| |---    ---      | | |  |    |  |  |");
				strcpy(matrix[16],"| | |         |        |      |    |     |");
				strcpy(matrix[17],"| | |         |  ------|  --- |    |   --|");
				strcpy(matrix[18],"| |   | | |   |    |   |   |       |   | |");
				strcpy(matrix[19],"| |---|-| |   |----|   |   |       |   | |");
				strcpy(matrix[20],"|       | |            |   |           | |"); 
				strcpy(matrix[21],"|       | |----       -|---|   --------| |");
				strcpy(matrix[22],"|   |   |                 |   |          |");
				strcpy(matrix[23],"|---|   |------    ---    |   |          |");
				strcpy(matrix[24],"|   |            | |  |    |             |");
				strcpy(matrix[25],"|   |            | |  |   -|---    ------|");
				strcpy(matrix[26],"| | |            | |  |            |   | |");
				strcpy(matrix[27],"| | |        ----|-|  |-------     |   | |");
				strcpy(matrix[28],"| |     |    |   |                 |   | |");
				strcpy(matrix[29],"| |-----|    |   |                 |   | |");
				strcpy(matrix[30],"|     | |    | | |    |   |            | |");
				strcpy(matrix[31],"|-----| |----| | |-   |   |     -------| |");
				strcpy(matrix[32],"|   |          |      |   |              |");
				strcpy(matrix[33],"|   |    ------|-     |---|   ---  ---   |");
				strcpy(matrix[34],"|   |              |           | | |  |  |");
				strcpy(matrix[35],"|   |  --    ------|        ---| | |  |  |");
				strcpy(matrix[36],"|      | | | |                 | | |  |  |");
				strcpy(matrix[37],"|------| |-|-|        -----    | | |  |--|");
				strcpy(matrix[38],"|                        |         |     |");
				strcpy(matrix[39],"|    ----       ------   |    -----|     |");
				strcpy(matrix[40],"|  | |     |          |  |           |   |");
				strcpy(matrix[41],"|  | |---  |  --------|  |        ---|   |");
				strcpy(matrix[42],"|          |    |   |       |      |     |");
				strcpy(matrix[43],"|----   ---|    |   |-------|      |--   |");
				strcpy(matrix[44],"|             | |               |        |");
				strcpy(matrix[45],"|  --   ---   |-|    -----   ---|   -----|");
				strcpy(matrix[46],"| |           |           |     |     |  |");
				strcpy(matrix[47],"| |           |           |     |---  |  |");
				strcpy(matrix[48],"| |           |           |   | |   |    |");
				strcpy(matrix[49],"| |     ------|--------   |   | |   |----|");
				strcpy(matrix[50],"| |  |  |   |               |            |");
				strcpy(matrix[51],"| |  |  |-  |  ------  -----|---------   |");
				strcpy(matrix[52],"| |  |      |  |       |              |  |");
				strcpy(matrix[53]," --------------------OOOOO--------------- ");
				}
		  }
	}



   
	if(levelnumber == 3)
	{
		for(i=0; i<60; i++)
		{
				for(j=0; j<60; j++)
				{
				strcpy(matrix[0], " ");
				strcpy(matrix[1], " ------------------------------------------------- ");
				strcpy(matrix[2], "|       | |   | |-----| |          |  | | | |     |");
				strcpy(matrix[3], "|       | |  |          |      --  |  | | | | ----|");
				strcpy(matrix[4], "|   |   | |  |--------| |      |   |  | | |       |");
				strcpy(matrix[5], "|-  |---| |    ----   | |---   | --|  | | |       |");
				strcpy(matrix[6], "|   |       |  |      |     |         |   |       |");
				strcpy(matrix[7], "|   |  --   |  |    --|-    |   -     |   |  -----|");
				strcpy(matrix[8], "| |                 |   |   |   |     |   |       |");
				strcpy(matrix[9], "| |--   -   ----  --|  -|   |   | ----|   |       |");
				strcpy(matrix[10],"|        |  |       |       |   | |   |   |       |");
				strcpy(matrix[11],"|    --  |  |--   --| ------|   | | --| --|-      |");
				strcpy(matrix[12],"|        |  |   | | |           |     |      |    |");
				strcpy(matrix[13],"|        |  |---| | |     ------| ----|     -|----|");
				strcpy(matrix[14],"| |   |         | |       |     |           |     |");
				strcpy(matrix[15],"| |---|         | |--    -|--   |-       ---| ----|");
				strcpy(matrix[16],"| |   |       |   |      |   |  | |               |");
				strcpy(matrix[17],"| |   |       |   | -----|   |  | |    ---  ------|");
				strcpy(matrix[18],"|   |    |    |     |    |   |  | |  |    |  | |  |");
				strcpy(matrix[19],"|  -|-   |    |  ---|--  |   |  | |--|-   |  | |  |");
				strcpy(matrix[20],"| | |    |    |   |    |     |  |    |    |  | |  |");
				strcpy(matrix[21],"| | |  --|  --|   |    |     |  |    |    | -| |  |");
				strcpy(matrix[22],"|      |   |  | | | |  |     |       |      |  |  |");
				strcpy(matrix[23],"|----  |   |  |-|-| |  |     |   --  |      |  |  |");
				strcpy(matrix[24],"|      |   |        |  |     |   | | |      |     |");
				strcpy(matrix[25],"|-     |  -|   --   |  |   --|---| | |--  --|--   |");
				strcpy(matrix[26],"|   |     |         |  |         | | |  |       | |");
				strcpy(matrix[27],"|-  | ----|----     | -|-       -| | |- |-----  |-|");
				strcpy(matrix[28],"|         |         |  |       |              | | |");
				strcpy(matrix[29],"|-      --|---      |  |       |-     -  -----| | |");
				strcpy(matrix[30],"| |  | |          | |  |       |   | | |          |");
				strcpy(matrix[31],"| |--| |          |-|- |       |  -| | |--        |");
				strcpy(matrix[32],"|    | |      |   |    |   |   |     |    |  |    |");
				strcpy(matrix[33],"|    |-|      |  -|--- |---|   |  ---|    |  |    |");
				strcpy(matrix[34],"| |           | |                |        |  |  | |");
				strcpy(matrix[35],"| |   --    --|-|    ---    ---  |        |  |--|-|");
				strcpy(matrix[36],"| | |      |    | |     |      | |   |    |       |");
				strcpy(matrix[37],"| | |      |  --|-|     |      | |---|--  |--     |");
				strcpy(matrix[38],"| | |   |         |   | |   |  | |              | |");
				strcpy(matrix[39],"| | | --|-   -----|   | |   |  | |-------       | |");
				strcpy(matrix[40],"| |     |   |   | |   | |   |  |           |    | |");
				strcpy(matrix[41],"| |     |   |   |-|   |-|   |--|  ------   |  --| |");
				strcpy(matrix[42],"|   | | | | |     | |     | |         |    |      |");
				strcpy(matrix[43],"|-  | |-| | |     | |--   | |-------  |    |------|");
				strcpy(matrix[44],"|   |     |       | |     |   | |   | | |  |      |");
				strcpy(matrix[45],"|   |-   -|---    | |  ---|-  | | --| | |  |      |");
				strcpy(matrix[46],"| | |             |         |   |   |   |  |  | | |");
				strcpy(matrix[47],"| | |             |         |---| --|---|  |  | | |");
				strcpy(matrix[48],"| | | |           |               |           | | |");
				strcpy(matrix[49]," ----------OOO------------------------------------ ");
				}
		  }
	}



	if(levelnumber == 4)
	{
		for(i=0; i<60; i++)
		{
				for(j=0; j<60; j++)
				{
					//The top right maze section.
				strcpy(matrix[0], " ");
				strcpy(matrix[1], " ------------------------------------------ ");
				strcpy(matrix[2], "|       |     |  |  |   |  |               |");
				strcpy(matrix[3], "|---    |    |   |  |   |  |               |");
				strcpy(matrix[4], "|   |   |    |   |  |   |  |               |");
				strcpy(matrix[5], "|   |   |--  |-- |  |-  |  |  -------------|");
				strcpy(matrix[6], "| | |            |  |   |  | |         |   |");
				strcpy(matrix[7], "| | |  --------- |  |  -|  | |    ---  |   |");
				strcpy(matrix[8], "| |   |      |             | |         |   |");
				strcpy(matrix[9], "| |---|      |--  --  -----| |         |   |");
				strcpy(matrix[10], "| |          |      |      |           |   |");
				strcpy(matrix[11],"| |          |--    |      |           |   |");
				strcpy(matrix[12],"| |        | |   |  |      |       |       |");
				strcpy(matrix[13],"|-|  ---   | |---|  |------|---    |       |");
				strcpy(matrix[14],"  |        |     |     |       |   |       |");
				strcpy(matrix[15]," -|--      |     |     |       |   |---    |");
				strcpy(matrix[16],"    |  |         |     |       |     |     |");
				strcpy(matrix[17]," -  |  |   ------|---  |   ----|     |     |");
				strcpy(matrix[18],"| |      | |           |             |     |");
				strcpy(matrix[19],"| |  --  | |   ------- |-------      |     |");
				strcpy(matrix[20],"|        | | | |      |      |  |     |    |");
				strcpy(matrix[21],"|        |-|-| |     -|  --  |  |-----|    |");
				strcpy(matrix[22],"| |          | | |  |      |    |     |    |");
				strcpy(matrix[23],"| |--------  |-| |  |  ----|--  |   --|--  |");
				strcpy(matrix[24],"| |              |  |      |    |          |");
				strcpy(matrix[25],"| |      --------|  |      |    |        --|");
				strcpy(matrix[26],"|    |  |        |  |      |    |     | |  |");
				strcpy(matrix[27],"|    |  |  --    |  |---   |  --|    -|-|  |");
				strcpy(matrix[28],"|    |  | |      |                    |    |");
				strcpy(matrix[29],"| ---|- | |------|   -------    ---   |   -|");
				strcpy(matrix[30],"|       |    |       |      |    |    |  | |");
				strcpy(matrix[31],"|       |-   |-      |      |-   |    |  | |");
				strcpy(matrix[32],"|         |  |       |        |  |    |    |");
				strcpy(matrix[33],"|-----    |  |-      |  ---   |  |   -|    |");
				strcpy(matrix[34],"|   |     |          |   |    |  |         |");
				strcpy(matrix[35],"|-  |---  |   -------|   |   -|  |    -----|");
				strcpy(matrix[36],"|   |   | |  |         | |           |     |");
				strcpy(matrix[37],"|   |   |-|  |  ---    | |      -   -|     |");
				strcpy(matrix[38],"| |     | |  | |   |   | |         |    |  |");
				strcpy(matrix[39],"| |-  --| |  | |   |   | |----    -|    |  |");
				strcpy(matrix[40],"| | | | |      |   |             |      |  |");
				strcpy(matrix[41],"| | | | |     -|   |---       ---|      |  |");
				strcpy(matrix[42],"| | | |          |     |       |    |   |  |");
				strcpy(matrix[43],"| | | |          |  ---|       |    |---|--|");
				strcpy(matrix[44],"|   |   |  |   | | |   |       |    | | |  |");
				strcpy(matrix[45],"|   |   |  |   | | |   |   --- |   -| | |  |");
				strcpy(matrix[46],"|   |   |  |   |   |   | | |   |           |");
				strcpy(matrix[47],"|   |---|  |   |---|   | | |  -|--     ----|");
				strcpy(matrix[48],"| |        |           | | |               |");
				strcpy(matrix[49]," -----------------------OOO---------------- ");

				}
		  }
	}



	if(levelnumber == 4)
	{
		for(i=0; i<60; i++)
		{
				for(j=0; j<60; j++)
				{
				//center center maze.
				strcpy(matrix[0], " ");
				strcpy(matrix[1], " -------------------------------------------------- ");
				strcpy(matrix[2], "|         | | |                |      |   |  |     |");
				strcpy(matrix[3], "|         | | |------    ---   |---  -|-- |  |  ---|");
				strcpy(matrix[4], "|         | |        |  |   |  |   |  |      |     |");
				strcpy(matrix[5], "| ------  | |        |  |---|  |   | -|----  |     |");
				strcpy(matrix[6], "| |     | | |        |         | | |     | |       |");
				strcpy(matrix[7], "| | --- | | |   ---  |   ---   | | |     | |  -----|");
				strcpy(matrix[8], "| | | | | | |  |   | |  |        |   | | |   |     |");
				strcpy(matrix[9], "| | | | | |-|--|-  | |  |   -----|---|-| |   |     |");
				strcpy(matrix[10],"| | | | | |      | | |  |   | |              |  |  |");
				strcpy(matrix[11],"| | | | | |      | | |--|-  | |        ------|  |  |");
				strcpy(matrix[12],"| | | | | |   |  | |          |                 |  |");
				strcpy(matrix[13],"| | | |-|-|   |  | |-         |---              |  |");
				strcpy(matrix[14],"| | |         |  |   |          |   |     |     |  |");
				strcpy(matrix[15],"| | |         |  |   |-----  ---|   | ----|-----|  |");
				strcpy(matrix[16],"| | |     |   |  |         |    |   | |            |");
				strcpy(matrix[17],"| | |     |   |  |         | ---|-- |-|            |");
				strcpy(matrix[18],"| | | | | |   |  |         | |                     |");
				strcpy(matrix[19],"| | | | | |   |  |  --     | |                     |");
				strcpy(matrix[20],"| |   | | |   |  |  |      | |     |               |");
				strcpy(matrix[21],"| |   | | |   |  |--|--    | |     |---  --------  |");
				strcpy(matrix[22],"| |     | |            | | | |     |   | | |     | |");
				strcpy(matrix[23],"| |-----| |            | | | |     |   | | |     | |");
				strcpy(matrix[24],"|         |            | | | |       |   | |   |   |");
				strcpy(matrix[25],"|-------- |------------|-| | |    ---|---| |-  |---|");
				strcpy(matrix[26],"|         |     |          | | | |     |     |     |");
				strcpy(matrix[27],"|  -----  |     |  --------|-|-| |     |     |     |");
				strcpy(matrix[28],"|       | |   |   |   |      | | |           | | | |");
				strcpy(matrix[29],"|       |-|   |  -|   |  --  | | |           | | | |");
				strcpy(matrix[30],"|     |       | | |   |    |                 | | | |");
				strcpy(matrix[31],"| ----|  ---  | | | --|    |   ----       ---| | |-|");
				strcpy(matrix[32],"| | | |     | |   |        |       |       | | |   |");
				strcpy(matrix[33],"| | |-|-    | |---| -----  |       |      -| | | --|");
				strcpy(matrix[34],"| |                      | | | |   |     |     |   |");
				strcpy(matrix[35],"| |---              -----| | | | --|  ---|  -  |-  |");
				strcpy(matrix[36],"|       |     | |   |      | | | |     | | |       |");
				strcpy(matrix[37],"|-----  |     |-|   |---   |-|-| |   --| | |    -  |");
				strcpy(matrix[38],"|     | | |   |          |   | | |  |            | |");
				strcpy(matrix[39],"|     | |-|---|--        |-  | | | -|----        | |");
				strcpy(matrix[40],"| |   |             |       |  | |       |   | |   |");
				strcpy(matrix[41],"|-|  -|  --   --  --|  ---  |--| |   --  |  -| |-- |");
				strcpy(matrix[42],"|   |      | |  | |                  | |           |");
				strcpy(matrix[43],"|   |      | |  |-|---    -----      | |           |");
				strcpy(matrix[44],"|     |   |           |        |   | | |  |  | | | |");
				strcpy(matrix[45],"|   --|-  |---        |        |   |-|-|  |  | | | |");
				strcpy(matrix[46],"|  |             | |  |   |    | | |      |  | | | |");
				strcpy(matrix[47],"|--|  ----       | |--|   |    | | |------|- |-| | |");
				strcpy(matrix[48],"|         | | |       |   |      | |           | | |");
				strcpy(matrix[49],"|         | | | ---   |   |  ----|-|   --------| | |");
				strcpy(matrix[50],"| | | | |   |  | | |  |   |        | | |         | |");
				strcpy(matrix[51],"| |-|-| |   |--| | |--|   |--    --| | |  -------|-|");
				strcpy(matrix[52],"|       |             |   |        | | |           |");
				strcpy(matrix[53]," -----------------------------------OOO------------ ");

				}
		  }
	}



	if(levelnumber == 4)
	{
		for(i=0; i<60; i++)
		{
				for(j=0; j<60; j++)
				{
					//Center right maze.
				strcpy(matrix[0], " ");
				strcpy(matrix[1], " -------------------------------------------- ");
				strcpy(matrix[2], "|                  |  |        |             |");
				strcpy(matrix[3], "|---    ---    ----|  |     ---|-----        |");
				strcpy(matrix[4], "|    | |   |  |       | |      |     | |     |");
				strcpy(matrix[5], "|----| |   |  | -   --| |      |---  | |     |");
				strcpy(matrix[6], "|      |   |  |    |  | |            | |     |");
				strcpy(matrix[7], "|------|  -|  |--  |- | |         ---| |     |");
				strcpy(matrix[8], "| |  |   |       |    | |            | |     |");
				strcpy(matrix[9], "| |  |  -|   --- |----| |------------| |     |");
				strcpy(matrix[10],"| |  |        |  |                     |     |");
				strcpy(matrix[11],"| |  |  ---   |  |----------       ----|     |");
				strcpy(matrix[12],"|    | |   |  |           |   | |  |         |");
				strcpy(matrix[13],"|    |-|   |  |-------    |  -|-|  |         |");
				strcpy(matrix[14],"|        |    |       | | | |   |  |   |     |");
				strcpy(matrix[15],"|-       |--- |  ---  | | |-|   |--|   |     |");
				strcpy(matrix[16],"| |                 |   |   | | |      |     |");
				strcpy(matrix[17],"| |   ---           |  -|---|-| |     -|     |");
				strcpy(matrix[18],"| |  |     |      | | |            | |       |");
				strcpy(matrix[19],"| |  |     |------|-|-|  --     ---| |       |");
				strcpy(matrix[20],"| |  |     |      |        |   |   | |       |");
				strcpy(matrix[21],"| |  |     |----- |------  |-  |   | |----   |");
				strcpy(matrix[22],"|      |                 |   |       |       |");
				strcpy(matrix[23],"|      |-   -----     ---|   |---    |       |");
				strcpy(matrix[24],"|        |         |     |   |   |           |");
				strcpy(matrix[25],"|----   -|  -----  |     |   |-  |     ------|");
				strcpy(matrix[26],"|    |     |   |   |     |       |        |  |");
				strcpy(matrix[27],"|  --|  ---|-  |   |  ---|       |--------|  |");
				strcpy(matrix[28],"| |    |       |   | |     |   |     |    |  |");
				strcpy(matrix[29],"| |    |       |---| |     |   |--   |    |  |");
				strcpy(matrix[30],"|      |       |     |     |   |       |     |");
				strcpy(matrix[31],"|------|     --|     |-----|   |   --- |   --|");
				strcpy(matrix[32],"|              |     |     |   |  |    |     |");
				strcpy(matrix[33],"|        ----  |  ---|     |---|  |    |     |");
				strcpy(matrix[34],"|            | |               |  |    |     |");
				strcpy(matrix[35],"|    -----  -| |        -----  |  |  --|---  |");
				strcpy(matrix[36],"| |            |             | |  |          |");
				strcpy(matrix[37],"| |  -----     |------       | |  |------   -|");
				strcpy(matrix[38],"| | |                 |      | |     |       |");
				strcpy(matrix[39],"| | |----------       |   ---| |     |   ----|");
				strcpy(matrix[40],"| | |          |  |      |   | |     | |   | |");
				strcpy(matrix[41],"|-|-|   ---    |  |      |  -| |-  --|-|   | |");
				strcpy(matrix[42],"|          |   |  |   |  |       |     | | | |");
				strcpy(matrix[43],"|---     --|   |--|---|  |-------|    -|-| | |");
				strcpy(matrix[44],"|       |             |                | |   |");
				strcpy(matrix[45],"|  ---  |  -------    |   ---------   -| |-  |");
				strcpy(matrix[46],"|   |   | |       |   |  |                 | |");
				strcpy(matrix[47],"|   |   | |  ---  |   |  |  -----     ---  | |");
				strcpy(matrix[48],"|   |     |     | |      |    |    |     | | |");
				strcpy(matrix[49],"|   | ----|  -  | | -----|--- |    |-    | | |");
				strcpy(matrix[50],"|           | | | |           |          | | |");
				strcpy(matrix[51],"|--   ------| | | | ---    ---|---       | |-|");
				strcpy(matrix[52],"|             | | |    |  |              | | |");
				strcpy(matrix[53]," --------------   --------------------------- ");
				}
		  }
	}
}

void printgrid()
{
      for (int i=0; i<60; i++)
      {
            for ( int j=0; j<60; j++)
            {
                  printf("%c", matrix[i][j]);
            }
            printf("\n");
      }
}

void changelevel(int &currentlevel)
{
	int clear = 0;
	if(currentlevel == 1 && matrix[my][mx+1] == 'O' && facing == 'S'||'A'||'D'||'W' && my == 48 && mx == 26||27||28)
	{
		currentlevel = 2;
		my = 1;
		mx = 14;
		clear = 1;
	}
	if(currentlevel == 2 && matrix[my][mx+1] == 'O' && facing == 'S' && my == 53 && mx == 22||23||24||25||26)
	{
		currentlevel = 3;
		my = 2;
		mx = 14;
		clear = 1;
	}
	if(currentlevel == 3 && matrix[my][mx+1] == 'O' && facing == 'S' && my == 49 && mx == 12||13||14)
	{
		currentlevel = 4;
		my = 2;
		mx = 14;
		clear = 1;
	}
	if(currentlevel == 4 && matrix[my][mx+1] == 'O' && facing == 'S' && my == 49 && mx == 25||26||27)
	{
		currentlevel = 5;
		my = 2;
		mx = 14;
		clear = 1;
	}
	if(currentlevel == 5 && matrix[my][mx+1] == 'O' && facing == 'S' && my == 53 && mx == 38||39||40)
	{
		currentlevel = 6;
		my = 2;
		mx = 14;
		clear = 1;
	}
	if(currentlevel == 6 && matrix[my][mx-5] == 'O' && facing == 'S' && my == 53 && mx == 16||17||18)
	{
		currentlevel = 1;
		my = 2;
		mx = 14;
		clear = 1;
	}
	if(clear == 1)
	{
		loadlevel(currentlevel);
		system("cls");
		printgrid();
		gotoxy(mx,my);
		printf("@");
		gotoxy(0, 0);
		gotoxy(0, 21);
	}
}







int main()
{

int level = 1;
system("COLOR 0B");
loadlevel(level);
printgrid();

gotoxy(mx,my);

printf("@");
gotoxy(0, 0);
gotoxy(0, 21);


while (mx>0 && my>0)
{
	  loadlevel(level);


      if (kbhit())
      {
            direction=getch();

            if ((direction == 'd') || (direction == 'a') || (direction == 'w') || (direction == 's') || (direction == 'S') || (direction == 'D') || (direction == 'A') || (direction == 'W') || (direction == 'e') || (direction == 'E'))
			{
                  if (direction == 's' || direction == 'S')
                  {
						gotoxy(mx,my);
						printf("@");
						facing = 'S';
						if(matrix[my+1][mx] == ' ')
						{
							gotoxy(mx,my);
							printf(" ");
							my++;
							gotoxy(mx,my);
							printf("@");
						}
                  }
                  if (direction == 'w' || direction == 'W')
                  {
					gotoxy(mx,my);
					printf("@");
					facing = 'W';
					if(matrix[my-1][mx] == ' ')
					{
						gotoxy(mx,my);
						printf(" ");
						my--;
						gotoxy(mx,my);
						printf("@");
					}
                  }
                  if (direction == 'a' || direction == 'A')
                  {
					gotoxy(mx,my);
					printf("@");
					facing = 'A';
					if(matrix[my][mx-1] == ' ')
					{
						gotoxy(mx,my);
						printf(" ");
						mx--;
						gotoxy(mx,my);
						printf("@");
					}
                  }
                  if (direction == 'd' || direction == 'D')
				  {
					gotoxy(mx,my);
					printf("@");
					facing = 'D';
					if(matrix[my][mx+1] == ' ')
					{
						gotoxy(mx,my);
						printf(" ");
						mx++;
						gotoxy(mx,my);
						printf("@");
					}
				  }
				  if(direction == 'e' || direction == 'E')
				  {
					  changelevel(level);
				  }

                  direction = ' ';
				  gotoxy(0,21);
			}
      }
}

return 0;
}

First off, cool maze program. I compiled it and ran it in Dev C++ and was able to manuever through the maze and have my character move in the direction I wished to what (I believe) is the goal (a hole in the wall on the right side of the maze). I tried to go through this wall, but nothing happened (it appears at least). That's hundreds of lines of code. What is SUPPOSED to happen when one goes through that hole in the wall on the right wall? Is a variable supposed to be set or a function called? If so, which one, and what line is it on? I say this because if you include these details, you may get more answers. Most people aren't going to go through 600 lines of code if they haven't been told where to focus.

Again, very nice maze and maneuver options.

The hole on the side of the first maze does nothing it is the hole at the bottom that is suppost to take you to the next level but it keeps repeating level one for some reason.

directions for moving and changing levels

press 's' to go down
press 'a' to go left
press 'w' to go up
press 'd' to go right

and press 'e' when you get to the letter 'O' to change levels


oh and nothing is suppost to happen when you go thorough that hole in the right wall...I just haven't finished and all of these pieces are going to go into a bigger maze.


I keep having a problem with my void function that changes the level...for some reason it keeps repeating level 1.

something in this code here is messing up.

void changelevel(int &currentlevel)
{	
int clear = 0;	
if(currentlevel == 1 && matrix[my][mx+1] == 'O' && facing == 'S'||'A'||'D'||'W' && my == 48 && mx == 26||27||28)
	
{		
currentlevel = 2;		
my = 1;		
mx = 14;		
clear = 1;	
}	
if(currentlevel == 2 && matrix[my][mx+1] == 'O' && facing == 'S' && my == 53 && mx == 22||23||24||25||26)
	
{		
currentlevel = 3;		
my = 2;		
mx = 14;		
clear = 1;	
}	
if(currentlevel == 3 && matrix[my][mx+1] == 'O' && facing == 'S' && my == 49 && mx == 12||13||14)
	
{		
currentlevel = 4;		
my = 2;		
mx = 14;		
clear = 1;	
}	

if(currentlevel == 4 && matrix[my][mx+1] == 'O' && facing == 'S' && my == 49 && mx == 25||26||27)
	
{		
currentlevel = 5;		
my = 2;		
mx = 14;		
clear = 1;	
}	

if(currentlevel == 5 && matrix[my][mx+1] == 'O' && facing == 'S' && my == 53 && mx == 38||39||40)
	
{		
currentlevel = 6;		
my = 2;		
mx = 14;		
clear = 1;	
}	

if(currentlevel == 6 && matrix[my][mx-5] == 'O' && facing == 'S' && my == 53 && mx == 16||17||18)	
{		
currentlevel = 1;		
my = 2;		
mx = 14;		
clear = 1;	
}	
if(clear == 1)	
{	
	
loadlevel(currentlevel);		
system("cls");		
printgrid();		
gotoxy(mx,my);		
printf("@");		
gotoxy(0, 0);		
gotoxy(0, 21);	
}
}

currentlevel is always 1 in changelevel(), the if(currentlevel == 1 && code must not be executing. ;)

Yes I figured that out....I just haven't figured out how to fix it yet...that's why I'm asking

#include <iostream>
//#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
//#include <ctype.h>
#include <fstream>
using namespace std;

int mx=14;
int my=1;
int i, j;
char direction = ' ';
char facing = 'S';
char matrix[100][100];

void gotoxy(short x, short y) {
	HANDLE hConsoleOutput;
	COORD Cursor_an_Pos = { x, y };
	hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hConsoleOutput, Cursor_an_Pos);
}

void loadlevel(int levelnumber) {
	if (levelnumber == 1) {
		for (i=0; i<60; i++) {
			for (j=0; j<60; j++) {
				strcpy(matrix[0], "----------------------------------------");
				strcpy(matrix[1], "| | |      |   | | |   |         |     |");
				strcpy(matrix[2], "| | |----  |   | | |-- | ----    |     |");
				strcpy(matrix[3], "|        |   | | | |   |   | |    |    |");
				strcpy(matrix[4], "|  ----  |---| | | | --|-  | |----| -  |");
				strcpy(matrix[5], "| |    | |   |   |       | | |    |  | |");
				strcpy(matrix[6], "| |----| |  -|-  |--     | | |  --|- | |");
				strcpy(matrix[7], "| |                      | |           |");
				strcpy(matrix[8], "|-|-           -----     | |-----   ---|");
				strcpy(matrix[9], "|           |    |                  |  |");
				strcpy(matrix[10], "|     ---   |-   |  --------        |  |");
				strcpy(matrix[11], "|   |  |         |       |       |     |");
				strcpy(matrix[12], "|   |  |  ----   |       |  ---  |---  |");
				strcpy(matrix[13], "| | |  |      |  |       |  |  |     | |");
				strcpy(matrix[14], "| | | -|      |  |    ---|  |  |     | |");
				strcpy(matrix[15], "| | |     |   |  | |     |     |     | |");
				strcpy(matrix[16], "|-| |---  |   |  | |-    |   --|--   | |");
				strcpy(matrix[17], "|         |   |          |         |   |");
				strcpy(matrix[18], "|  --  ---|   |------    |-------  |   |");
				strcpy(matrix[19], "|  | |           |           | | | | | |");
				strcpy(matrix[20], "|--| |---  ---   |-----------| |-|-|-| |");
				strcpy(matrix[21], "|          |     |           |       | |");
				strcpy(matrix[22], "|          |     |      -----|-      | |");
				strcpy(matrix[23], "|          | |   |                 | | |");
				strcpy(matrix[24], "| --  -----|-|---|                 | | |");
				strcpy(matrix[25], "| |     |    |       |           | |    ");
				strcpy(matrix[26], "| |     |    |  ---  |---   ---  |-|--- ");
				strcpy(matrix[27], "| |   | | |  |               |   |      ");
				strcpy(matrix[28], "| |   |-|-|  |  -------      |  -|-    |");
				strcpy(matrix[29], "| | | | | |  |    |          | |       |");
				strcpy(matrix[30], "| | | | | |  |    |----------| |  -----|");
				strcpy(matrix[31], "| | |   |    | |  |            |     | |");
				strcpy(matrix[32], "| | |---|----| |  |  ---     --|-----| |");
				strcpy(matrix[33], "|       |      |               |     | |");
				strcpy(matrix[34], "|-----  |      |     ----------|  ---| |");
				strcpy(matrix[35], "|       |    | |               |  |    |");
				strcpy(matrix[36], "|-----  |    |-|          -----|  |    |");
				strcpy(matrix[37], "|       |  | |     |              | |  |");
				strcpy(matrix[38], "|       |  | |    -|-             | |  |");
				strcpy(matrix[39], "|  | |     |                      | |  |");
				strcpy(matrix[40], "|  | |---  |             ---------| |--|");
				strcpy(matrix[41], "|  | |   | |    |    | | |             |");
				strcpy(matrix[42], "|  | |   | |    |    |-|-|         ----|");
				strcpy(matrix[43], "|  | |     |    | |         |  |       |");
				strcpy(matrix[44], "|  | |-----|    |-|-        |  | ----  |");
				strcpy(matrix[45], "|  |    |           |       |  |     | |");
				strcpy(matrix[46], "|  |----|  ------   |---    |  |  -  | |");
				strcpy(matrix[47], "|     |    |            |   |  |   | | |");
				strcpy(matrix[48], " ------------------------OOO----------- ");

			}
		}
	}
	if (levelnumber == 2) {
		for (i=0; i<60; i++) {
			for (j=0; j<60; j++) {
				//The left middle maze section.
				strcpy(matrix[0], " ");
				strcpy(matrix[1], "------------------------------------------");
				strcpy(matrix[2], "|      | |            |  |    |  |       |");
				strcpy(matrix[3], "|---   | | -----      |  |    |  |       |");
				strcpy(matrix[4], "|   |  | |   |   |       |    |  |       |");
				strcpy(matrix[5], "|   |  | |-  | --|  -----|    |  |  -----|");
				strcpy(matrix[6], "|   |  |     |       |        |  |  |    |");
				strcpy(matrix[7], "|  -|  |---  |       |    ----|  |  |    |");
				strcpy(matrix[8], "| |     |  | | |  |    |         |  | |  |");
				strcpy(matrix[9], "| |---  |  | | |  |    |         |  | |  |");
				strcpy(matrix[10], "| |     |      |  |    |         |  | |  |");
				strcpy(matrix[11], "| |---  |  ----|- |----|   ------|  | |  |");
				strcpy(matrix[12], "|     |                  | |  |       |  |");
				strcpy(matrix[13], "|     |              ----| |  |   ----|  |");
				strcpy(matrix[14], "|   | |                | | |  |    |  |  |");
				strcpy(matrix[15], "|---| |---    ---      | | |  |    |  |  |");
				strcpy(matrix[16], "| | |         |        |      |    |     |");
				strcpy(matrix[17], "| | |         |  ------|  --- |    |   --|");
				strcpy(matrix[18], "| |   | | |   |    |   |   |       |   | |");
				strcpy(matrix[19], "| |---|-| |   |----|   |   |       |   | |");
				strcpy(matrix[20], "|       | |            |   |           | |");
				strcpy(matrix[21], "|       | |----       -|---|   --------| |");
				strcpy(matrix[22], "|   |   |                 |   |          |");
				strcpy(matrix[23], "|---|   |------    ---    |   |          |");
				strcpy(matrix[24], "|   |            | |  |    |             |");
				strcpy(matrix[25], "|   |            | |  |   -|---    ------|");
				strcpy(matrix[26], "| | |            | |  |            |   | |");
				strcpy(matrix[27], "| | |        ----|-|  |-------     |   | |");
				strcpy(matrix[28], "| |     |    |   |                 |   | |");
				strcpy(matrix[29], "| |-----|    |   |                 |   | |");
				strcpy(matrix[30], "|     | |    | | |    |   |            | |");
				strcpy(matrix[31], "|-----| |----| | |-   |   |     -------| |");
				strcpy(matrix[32], "|   |          |      |   |              |");
				strcpy(matrix[33], "|   |    ------|-     |---|   ---  ---   |");
				strcpy(matrix[34], "|   |              |           | | |  |  |");
				strcpy(matrix[35], "|   |  --    ------|        ---| | |  |  |");
				strcpy(matrix[36], "|      | | | |                 | | |  |  |");
				strcpy(matrix[37], "|------| |-|-|        -----    | | |  |--|");
				strcpy(matrix[38], "|                        |         |     |");
				strcpy(matrix[39], "|    ----       ------   |    -----|     |");
				strcpy(matrix[40], "|  | |     |          |  |           |   |");
				strcpy(matrix[41], "|  | |---  |  --------|  |        ---|   |");
				strcpy(matrix[42], "|          |    |   |       |      |     |");
				strcpy(matrix[43], "|----   ---|    |   |-------|      |--   |");
				strcpy(matrix[44], "|             | |               |        |");
				strcpy(matrix[45], "|  --   ---   |-|    -----   ---|   -----|");
				strcpy(matrix[46], "| |           |           |     |     |  |");
				strcpy(matrix[47], "| |           |           |     |---  |  |");
				strcpy(matrix[48], "| |           |           |   | |   |    |");
				strcpy(matrix[49], "| |     ------|--------   |   | |   |----|");
				strcpy(matrix[50], "| |  |  |   |               |            |");
				strcpy(matrix[51], "| |  |  |-  |  ------  -----|---------   |");
				strcpy(matrix[52], "| |  |      |  |       |              |  |");
				strcpy(matrix[53], " --------------------OOOOO--------------- ");
			}
		}
	}

	if (levelnumber == 3) {
		for (i=0; i<60; i++) {
			for (j=0; j<60; j++) {
				strcpy(matrix[0], " ");
				strcpy(matrix[1],
						" ------------------------------------------------- ");
				strcpy(matrix[2],
						"|       | |   | |-----| |          |  | | | |     |");
				strcpy(matrix[3],
						"|       | |  |          |      --  |  | | | | ----|");
				strcpy(matrix[4],
						"|   |   | |  |--------| |      |   |  | | |       |");
				strcpy(matrix[5],
						"|-  |---| |    ----   | |---   | --|  | | |       |");
				strcpy(matrix[6],
						"|   |       |  |      |     |         |   |       |");
				strcpy(matrix[7],
						"|   |  --   |  |    --|-    |   -     |   |  -----|");
				strcpy(matrix[8],
						"| |                 |   |   |   |     |   |       |");
				strcpy(matrix[9],
						"| |--   -   ----  --|  -|   |   | ----|   |       |");
				strcpy(matrix[10],
						"|        |  |       |       |   | |   |   |       |");
				strcpy(matrix[11],
						"|    --  |  |--   --| ------|   | | --| --|-      |");
				strcpy(matrix[12],
						"|        |  |   | | |           |     |      |    |");
				strcpy(matrix[13],
						"|        |  |---| | |     ------| ----|     -|----|");
				strcpy(matrix[14],
						"| |   |         | |       |     |           |     |");
				strcpy(matrix[15],
						"| |---|         | |--    -|--   |-       ---| ----|");
				strcpy(matrix[16],
						"| |   |       |   |      |   |  | |               |");
				strcpy(matrix[17],
						"| |   |       |   | -----|   |  | |    ---  ------|");
				strcpy(matrix[18],
						"|   |    |    |     |    |   |  | |  |    |  | |  |");
				strcpy(matrix[19],
						"|  -|-   |    |  ---|--  |   |  | |--|-   |  | |  |");
				strcpy(matrix[20],
						"| | |    |    |   |    |     |  |    |    |  | |  |");
				strcpy(matrix[21],
						"| | |  --|  --|   |    |     |  |    |    | -| |  |");
				strcpy(matrix[22],
						"|      |   |  | | | |  |     |       |      |  |  |");
				strcpy(matrix[23],
						"|----  |   |  |-|-| |  |     |   --  |      |  |  |");
				strcpy(matrix[24],
						"|      |   |        |  |     |   | | |      |     |");
				strcpy(matrix[25],
						"|-     |  -|   --   |  |   --|---| | |--  --|--   |");
				strcpy(matrix[26],
						"|   |     |         |  |         | | |  |       | |");
				strcpy(matrix[27],
						"|-  | ----|----     | -|-       -| | |- |-----  |-|");
				strcpy(matrix[28],
						"|         |         |  |       |              | | |");
				strcpy(matrix[29],
						"|-      --|---      |  |       |-     -  -----| | |");
				strcpy(matrix[30],
						"| |  | |          | |  |       |   | | |          |");
				strcpy(matrix[31],
						"| |--| |          |-|- |       |  -| | |--        |");
				strcpy(matrix[32],
						"|    | |      |   |    |   |   |     |    |  |    |");
				strcpy(matrix[33],
						"|    |-|      |  -|--- |---|   |  ---|    |  |    |");
				strcpy(matrix[34],
						"| |           | |                |        |  |  | |");
				strcpy(matrix[35],
						"| |   --    --|-|    ---    ---  |        |  |--|-|");
				strcpy(matrix[36],
						"| | |      |    | |     |      | |   |    |       |");
				strcpy(matrix[37],
						"| | |      |  --|-|     |      | |---|--  |--     |");
				strcpy(matrix[38],
						"| | |   |         |   | |   |  | |              | |");
				strcpy(matrix[39],
						"| | | --|-   -----|   | |   |  | |-------       | |");
				strcpy(matrix[40],
						"| |     |   |   | |   | |   |  |           |    | |");
				strcpy(matrix[41],
						"| |     |   |   |-|   |-|   |--|  ------   |  --| |");
				strcpy(matrix[42],
						"|   | | | | |     | |     | |         |    |      |");
				strcpy(matrix[43],
						"|-  | |-| | |     | |--   | |-------  |    |------|");
				strcpy(matrix[44],
						"|   |     |       | |     |   | |   | | |  |      |");
				strcpy(matrix[45],
						"|   |-   -|---    | |  ---|-  | | --| | |  |      |");
				strcpy(matrix[46],
						"| | |             |         |   |   |   |  |  | | |");
				strcpy(matrix[47],
						"| | |             |         |---| --|---|  |  | | |");
				strcpy(matrix[48],
						"| | | |           |               |           | | |");
				strcpy(matrix[49],
						" ----------OOO------------------------------------ ");
			}
		}
	}

	if (levelnumber == 4) {
		for (i=0; i<60; i++) {
			for (j=0; j<60; j++) {
				//The top right maze section.
				strcpy(matrix[0], " ");
				strcpy(matrix[1],
						" ------------------------------------------ ");
				strcpy(matrix[2],
						"|       |     |  |  |   |  |               |");
				strcpy(matrix[3],
						"|---    |    |   |  |   |  |               |");
				strcpy(matrix[4],
						"|   |   |    |   |  |   |  |               |");
				strcpy(matrix[5],
						"|   |   |--  |-- |  |-  |  |  -------------|");
				strcpy(matrix[6],
						"| | |            |  |   |  | |         |   |");
				strcpy(matrix[7],
						"| | |  --------- |  |  -|  | |    ---  |   |");
				strcpy(matrix[8],
						"| |   |      |             | |         |   |");
				strcpy(matrix[9],
						"| |---|      |--  --  -----| |         |   |");
				strcpy(matrix[10],
						"| |          |      |      |           |   |");
				strcpy(matrix[11],
						"| |          |--    |      |           |   |");
				strcpy(matrix[12],
						"| |        | |   |  |      |       |       |");
				strcpy(matrix[13],
						"|-|  ---   | |---|  |------|---    |       |");
				strcpy(matrix[14],
						"  |        |     |     |       |   |       |");
				strcpy(matrix[15],
						" -|--      |     |     |       |   |---    |");
				strcpy(matrix[16],
						"    |  |         |     |       |     |     |");
				strcpy(matrix[17],
						" -  |  |   ------|---  |   ----|     |     |");
				strcpy(matrix[18],
						"| |      | |           |             |     |");
				strcpy(matrix[19],
						"| |  --  | |   ------- |-------      |     |");
				strcpy(matrix[20],
						"|        | | | |      |      |  |     |    |");
				strcpy(matrix[21],
						"|        |-|-| |     -|  --  |  |-----|    |");
				strcpy(matrix[22],
						"| |          | | |  |      |    |     |    |");
				strcpy(matrix[23],
						"| |--------  |-| |  |  ----|--  |   --|--  |");
				strcpy(matrix[24],
						"| |              |  |      |    |          |");
				strcpy(matrix[25],
						"| |      --------|  |      |    |        --|");
				strcpy(matrix[26],
						"|    |  |        |  |      |    |     | |  |");
				strcpy(matrix[27],
						"|    |  |  --    |  |---   |  --|    -|-|  |");
				strcpy(matrix[28],
						"|    |  | |      |                    |    |");
				strcpy(matrix[29],
						"| ---|- | |------|   -------    ---   |   -|");
				strcpy(matrix[30],
						"|       |    |       |      |    |    |  | |");
				strcpy(matrix[31],
						"|       |-   |-      |      |-   |    |  | |");
				strcpy(matrix[32],
						"|         |  |       |        |  |    |    |");
				strcpy(matrix[33],
						"|-----    |  |-      |  ---   |  |   -|    |");
				strcpy(matrix[34],
						"|   |     |          |   |    |  |         |");
				strcpy(matrix[35],
						"|-  |---  |   -------|   |   -|  |    -----|");
				strcpy(matrix[36],
						"|   |   | |  |         | |           |     |");
				strcpy(matrix[37],
						"|   |   |-|  |  ---    | |      -   -|     |");
				strcpy(matrix[38],
						"| |     | |  | |   |   | |         |    |  |");
				strcpy(matrix[39],
						"| |-  --| |  | |   |   | |----    -|    |  |");
				strcpy(matrix[40],
						"| | | | |      |   |             |      |  |");
				strcpy(matrix[41],
						"| | | | |     -|   |---       ---|      |  |");
				strcpy(matrix[42],
						"| | | |          |     |       |    |   |  |");
				strcpy(matrix[43],
						"| | | |          |  ---|       |    |---|--|");
				strcpy(matrix[44],
						"|   |   |  |   | | |   |       |    | | |  |");
				strcpy(matrix[45],
						"|   |   |  |   | | |   |   --- |   -| | |  |");
				strcpy(matrix[46],
						"|   |   |  |   |   |   | | |   |           |");
				strcpy(matrix[47],
						"|   |---|  |   |---|   | | |  -|--     ----|");
				strcpy(matrix[48],
						"| |        |           | | |               |");
				strcpy(matrix[49],
						" -----------------------OOO---------------- ");

			}
		}
	}

	if (levelnumber == 5) {
		for (i=0; i<60; i++) {
			for (j=0; j<60; j++) {
				//center center maze.
				strcpy(matrix[0], " ");
				strcpy(matrix[1],
						" -------------------------------------------------- ");
				strcpy(matrix[2],
						"|         | | |                |      |   |  |     |");
				strcpy(matrix[3],
						"|         | | |------    ---   |---  -|-- |  |  ---|");
				strcpy(matrix[4],
						"|         | |        |  |   |  |   |  |      |     |");
				strcpy(matrix[5],
						"| ------  | |        |  |---|  |   | -|----  |     |");
				strcpy(matrix[6],
						"| |     | | |        |         | | |     | |       |");
				strcpy(matrix[7],
						"| | --- | | |   ---  |   ---   | | |     | |  -----|");
				strcpy(matrix[8],
						"| | | | | | |  |   | |  |        |   | | |   |     |");
				strcpy(matrix[9],
						"| | | | | |-|--|-  | |  |   -----|---|-| |   |     |");
				strcpy(matrix[10],
						"| | | | | |      | | |  |   | |              |  |  |");
				strcpy(matrix[11],
						"| | | | | |      | | |--|-  | |        ------|  |  |");
				strcpy(matrix[12],
						"| | | | | |   |  | |          |                 |  |");
				strcpy(matrix[13],
						"| | | |-|-|   |  | |-         |---              |  |");
				strcpy(matrix[14],
						"| | |         |  |   |          |   |     |     |  |");
				strcpy(matrix[15],
						"| | |         |  |   |-----  ---|   | ----|-----|  |");
				strcpy(matrix[16],
						"| | |     |   |  |         |    |   | |            |");
				strcpy(matrix[17],
						"| | |     |   |  |         | ---|-- |-|            |");
				strcpy(matrix[18],
						"| | | | | |   |  |         | |                     |");
				strcpy(matrix[19],
						"| | | | | |   |  |  --     | |                     |");
				strcpy(matrix[20],
						"| |   | | |   |  |  |      | |     |               |");
				strcpy(matrix[21],
						"| |   | | |   |  |--|--    | |     |---  --------  |");
				strcpy(matrix[22],
						"| |     | |            | | | |     |   | | |     | |");
				strcpy(matrix[23],
						"| |-----| |            | | | |     |   | | |     | |");
				strcpy(matrix[24],
						"|         |            | | | |       |   | |   |   |");
				strcpy(matrix[25],
						"|-------- |------------|-| | |    ---|---| |-  |---|");
				strcpy(matrix[26],
						"|         |     |          | | | |     |     |     |");
				strcpy(matrix[27],
						"|  -----  |     |  --------|-|-| |     |     |     |");
				strcpy(matrix[28],
						"|       | |   |   |   |      | | |           | | | |");
				strcpy(matrix[29],
						"|       |-|   |  -|   |  --  | | |           | | | |");
				strcpy(matrix[30],
						"|     |       | | |   |    |                 | | | |");
				strcpy(matrix[31],
						"| ----|  ---  | | | --|    |   ----       ---| | |-|");
				strcpy(matrix[32],
						"| | | |     | |   |        |       |       | | |   |");
				strcpy(matrix[33],
						"| | |-|-    | |---| -----  |       |      -| | | --|");
				strcpy(matrix[34],
						"| |                      | | | |   |     |     |   |");
				strcpy(matrix[35],
						"| |---              -----| | | | --|  ---|  -  |-  |");
				strcpy(matrix[36],
						"|       |     | |   |      | | | |     | | |       |");
				strcpy(matrix[37],
						"|-----  |     |-|   |---   |-|-| |   --| | |    -  |");
				strcpy(matrix[38],
						"|     | | |   |          |   | | |  |            | |");
				strcpy(matrix[39],
						"|     | |-|---|--        |-  | | | -|----        | |");
				strcpy(matrix[40],
						"| |   |             |       |  | |       |   | |   |");
				strcpy(matrix[41],
						"|-|  -|  --   --  --|  ---  |--| |   --  |  -| |-- |");
				strcpy(matrix[42],
						"|   |      | |  | |                  | |           |");
				strcpy(matrix[43],
						"|   |      | |  |-|---    -----      | |           |");
				strcpy(matrix[44],
						"|     |   |           |        |   | | |  |  | | | |");
				strcpy(matrix[45],
						"|   --|-  |---        |        |   |-|-|  |  | | | |");
				strcpy(matrix[46],
						"|  |             | |  |   |    | | |      |  | | | |");
				strcpy(matrix[47],
						"|--|  ----       | |--|   |    | | |------|- |-| | |");
				strcpy(matrix[48],
						"|         | | |       |   |      | |           | | |");
				strcpy(matrix[49],
						"|         | | | ---   |   |  ----|-|   --------| | |");
				strcpy(matrix[50],
						"| | | | |   |  | | |  |   |        | | |         | |");
				strcpy(matrix[51],
						"| |-|-| |   |--| | |--|   |--    --| | |  -------|-|");
				strcpy(matrix[52],
						"|       |             |   |        | | |           |");
				strcpy(matrix[53],
						" -----------------------------------OOO------------ ");

			}
		}
	}

	if (levelnumber == 6) {
		for (i=0; i<60; i++) {
			for (j=0; j<60; j++) {
				//Center right maze.
				strcpy(matrix[0], " ");
				strcpy(matrix[1],
						" -------------------------------------------- ");
				strcpy(matrix[2],
						"|                  |  |        |             |");
				strcpy(matrix[3],
						"|---    ---    ----|  |     ---|-----        |");
				strcpy(matrix[4],
						"|    | |   |  |       | |      |     | |     |");
				strcpy(matrix[5],
						"|----| |   |  | -   --| |      |---  | |     |");
				strcpy(matrix[6],
						"|      |   |  |    |  | |            | |     |");
				strcpy(matrix[7],
						"|------|  -|  |--  |- | |         ---| |     |");
				strcpy(matrix[8],
						"| |  |   |       |    | |            | |     |");
				strcpy(matrix[9],
						"| |  |  -|   --- |----| |------------| |     |");
				strcpy(matrix[10],
						"| |  |        |  |                     |     |");
				strcpy(matrix[11],
						"| |  |  ---   |  |----------       ----|     |");
				strcpy(matrix[12],
						"|    | |   |  |           |   | |  |         |");
				strcpy(matrix[13],
						"|    |-|   |  |-------    |  -|-|  |         |");
				strcpy(matrix[14],
						"|        |    |       | | | |   |  |   |     |");
				strcpy(matrix[15],
						"|-       |--- |  ---  | | |-|   |--|   |     |");
				strcpy(matrix[16],
						"| |                 |   |   | | |      |     |");
				strcpy(matrix[17],
						"| |   ---           |  -|---|-| |     -|     |");
				strcpy(matrix[18],
						"| |  |     |      | | |            | |       |");
				strcpy(matrix[19],
						"| |  |     |------|-|-|  --     ---| |       |");
				strcpy(matrix[20],
						"| |  |     |      |        |   |   | |       |");
				strcpy(matrix[21],
						"| |  |     |----- |------  |-  |   | |----   |");
				strcpy(matrix[22],
						"|      |                 |   |       |       |");
				strcpy(matrix[23],
						"|      |-   -----     ---|   |---    |       |");
				strcpy(matrix[24],
						"|        |         |     |   |   |           |");
				strcpy(matrix[25],
						"|----   -|  -----  |     |   |-  |     ------|");
				strcpy(matrix[26],
						"|    |     |   |   |     |       |        |  |");
				strcpy(matrix[27],
						"|  --|  ---|-  |   |  ---|       |--------|  |");
				strcpy(matrix[28],
						"| |    |       |   | |     |   |     |    |  |");
				strcpy(matrix[29],
						"| |    |       |---| |     |   |--   |    |  |");
				strcpy(matrix[30],
						"|      |       |     |     |   |       |     |");
				strcpy(matrix[31],
						"|------|     --|     |-----|   |   --- |   --|");
				strcpy(matrix[32],
						"|              |     |     |   |  |    |     |");
				strcpy(matrix[33],
						"|        ----  |  ---|     |---|  |    |     |");
				strcpy(matrix[34],
						"|            | |               |  |    |     |");
				strcpy(matrix[35],
						"|    -----  -| |        -----  |  |  --|---  |");
				strcpy(matrix[36],
						"| |            |             | |  |          |");
				strcpy(matrix[37],
						"| |  -----     |------       | |  |------   -|");
				strcpy(matrix[38],
						"| | |                 |      | |     |       |");
				strcpy(matrix[39],
						"| | |----------       |   ---| |     |   ----|");
				strcpy(matrix[40],
						"| | |          |  |      |   | |     | |   | |");
				strcpy(matrix[41],
						"|-|-|   ---    |  |      |  -| |-  --|-|   | |");
				strcpy(matrix[42],
						"|          |   |  |   |  |       |     | | | |");
				strcpy(matrix[43],
						"|---     --|   |--|---|  |-------|    -|-| | |");
				strcpy(matrix[44],
						"|       |             |                | |   |");
				strcpy(matrix[45],
						"|  ---  |  -------    |   ---------   -| |-  |");
				strcpy(matrix[46],
						"|   |   | |       |   |  |                 | |");
				strcpy(matrix[47],
						"|   |   | |  ---  |   |  |  -----     ---  | |");
				strcpy(matrix[48],
						"|   |     |     | |      |    |    |     | | |");
				strcpy(matrix[49],
						"|   | ----|  -  | | -----|--- |    |-    | | |");
				strcpy(matrix[50],
						"|           | | | |           |          | | |");
				strcpy(matrix[51],
						"|--   ------| | | | ---    ---|---       | |-|");
				strcpy(matrix[52],
						"|             | | |    |  |              | | |");
				strcpy(matrix[53],
						" --------------   --------------------------- ");
			}
		}
	}
}

void printgrid() {
	for (int i=0; i<60; i++) {
		for (int j=0; j<60; j++) {
			printf("%c", matrix[i][j]);
		}
		printf("\n");
	}
}

void changelevel(int &currentlevel) {
	int clear = 0;

	if (currentlevel == 1 && matrix[my][mx+1] == 'O' && facing == 'S'||'A'||'D'
			||'W' && my == 48 && (mx == 26||27||28)) {
		currentlevel++;

		my = 1;
		mx = 14;
		clear = 1;
	}
	if (currentlevel == 2 && matrix[my][mx+1] == 'O' && facing == 'S' && my
			== 53 && (mx == 22||23||24||25||26)) {
		currentlevel = 3;
		my = 2;
		mx = 14;
		clear = 1;
	}
	if (currentlevel == 3 && matrix[my][mx+1] == 'O' && facing == 'S' && my
			== 49 && (mx == 12||13||14)) {
		currentlevel = 4;
		my = 2;
		mx = 14;
		clear = 1;
	}
	if (currentlevel == 4 && matrix[my][mx+1] == 'O' && facing == 'S' && my
			== 49 && (mx == 25||26||27)) {
		currentlevel = 5;
		my = 2;
		mx = 14;
		clear = 1;
	}
	if (currentlevel == 5 && matrix[my][mx+1] == 'O' && facing == 'S' && my
			== 53 && (mx == 38||39||40)) {
		currentlevel = 6;
		my = 2;
		mx = 14;
		clear = 1;
	}
	if (currentlevel == 6 && matrix[my][mx-5] == 'O' && facing == 'S' && my
			== 53 && (mx == 16||17||18)) {
		currentlevel = 1;
		my = 2;
		mx = 14;
		clear = 1;
	}
	if (clear == 1) {
		loadlevel(currentlevel);
		system("cls");
		printgrid();
		gotoxy(mx, my);
		printf("@");
		gotoxy(0, 0);
		gotoxy(0, 21);
	}
}

int main() {

	int level = 1;
	system("COLOR 0B");
	loadlevel(level);
	printgrid();

	gotoxy(mx, my);

	printf("@");
	gotoxy(0, 0);
	gotoxy(0, 21);

	while (mx>0 && my>0) {
		loadlevel(level);

		if (kbhit()) {
			direction=getch();

			if ((direction == 'd') || (direction == 'a') || (direction == 'w')
					|| (direction == 's') || (direction == 'S') || (direction
					== 'D') || (direction == 'A') || (direction == 'W')
					|| (direction == 'e') || (direction == 'E')) {
				if (direction == 's' || direction == 'S') {
					gotoxy(mx, my);
					printf("@");
					facing = 'S';
					if (matrix[my+1][mx] == ' ') {
						gotoxy(mx, my);
						printf(" ");
						my++;
						gotoxy(mx, my);
						printf("@");
					}
				}
				if (direction == 'w' || direction == 'W') {
					gotoxy(mx, my);
					printf("@");
					facing = 'W';
					if (matrix[my-1][mx] == ' ') {
						gotoxy(mx, my);
						printf(" ");
						my--;
						gotoxy(mx, my);
						printf("@");
					}
				}
				if (direction == 'a' || direction == 'A') {
					gotoxy(mx, my);
					printf("@");
					facing = 'A';
					if (matrix[my][mx-1] == ' ') {
						gotoxy(mx, my);
						printf(" ");
						mx--;
						gotoxy(mx, my);
						printf("@");
					}
				}
				if (direction == 'd' || direction == 'D') {
					gotoxy(mx, my);
					printf("@");
					facing = 'D';
					if (matrix[my][mx+1] == ' ') {
						gotoxy(mx, my);
						printf(" ");
						mx++;
						gotoxy(mx, my);
						printf("@");
					}
				}
				if (direction == 'e' || direction == 'E') {
					changelevel(level);

				}

				direction = ' ';
				gotoxy(0, 21);
			}
		}

	}
	return 0;
}

fixed version

#include <iostream>
//#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
//#include <ctype.h>
#include <fstream>
using namespace std;

int mx=14;
int my=1;
int i, j;
char direction = ' ';
char facing = 'S';
char matrix[100][100];

void gotoxy(short x, short y) {
	HANDLE hConsoleOutput;
	COORD Cursor_an_Pos = { x, y };
	hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hConsoleOutput, Cursor_an_Pos);
}

void loadlevel(int levelnumber) {
	if (levelnumber == 1) {
		strcpy(matrix[0], "----------------------------------------");
		strcpy(matrix[1], "| | |      |   | | |   |         |     |");
		strcpy(matrix[2], "| | |----  |   | | |-- | ----    |     |");
		strcpy(matrix[3], "|        |   | | | |   |   | |    |    |");
		strcpy(matrix[4], "|  ----  |---| | | | --|-  | |----| -  |");
		strcpy(matrix[5], "| |    | |   |   |       | | |    |  | |");
		strcpy(matrix[6], "| |----| |  -|-  |--     | | |  --|- | |");
		strcpy(matrix[7], "| |                      | |           |");
		strcpy(matrix[8], "|-|-           -----     | |-----   ---|");
		strcpy(matrix[9], "|           |    |                  |  |");
		strcpy(matrix[10], "|     ---   |-   |  --------        |  |");
		strcpy(matrix[11], "|   |  |         |       |       |     |");
		strcpy(matrix[12], "|   |  |  ----   |       |  ---  |---  |");
		strcpy(matrix[13], "| | |  |      |  |       |  |  |     | |");
		strcpy(matrix[14], "| | | -|      |  |    ---|  |  |     | |");
		strcpy(matrix[15], "| | |     |   |  | |     |     |     | |");
		strcpy(matrix[16], "|-| |---  |   |  | |-    |   --|--   | |");
		strcpy(matrix[17], "|         |   |          |         |   |");
		strcpy(matrix[18], "|  --  ---|   |------    |-------  |   |");
		strcpy(matrix[19], "|  | |           |           | | | | | |");
		strcpy(matrix[20], "|--| |---  ---   |-----------| |-|-|-| |");
		strcpy(matrix[21], "|          |     |           |       | |");
		strcpy(matrix[22], "|          |     |      -----|-      | |");
		strcpy(matrix[23], "|          | |   |                 | | |");
		strcpy(matrix[24], "| --  -----|-|---|                 | | |");
		strcpy(matrix[25], "| |     |    |       |           | |    ");
		strcpy(matrix[26], "| |     |    |  ---  |---   ---  |-|--- ");
		strcpy(matrix[27], "| |   | | |  |               |   |      ");
		strcpy(matrix[28], "| |   |-|-|  |  -------      |  -|-    |");
		strcpy(matrix[29], "| | | | | |  |    |          | |       |");
		strcpy(matrix[30], "| | | | | |  |    |----------| |  -----|");
		strcpy(matrix[31], "| | |   |    | |  |            |     | |");
		strcpy(matrix[32], "| | |---|----| |  |  ---     --|-----| |");
		strcpy(matrix[33], "|       |      |               |     | |");
		strcpy(matrix[34], "|-----  |      |     ----------|  ---| |");
		strcpy(matrix[35], "|       |    | |               |  |    |");
		strcpy(matrix[36], "|-----  |    |-|          -----|  |    |");
		strcpy(matrix[37], "|       |  | |     |              | |  |");
		strcpy(matrix[38], "|       |  | |    -|-             | |  |");
		strcpy(matrix[39], "|  | |     |                      | |  |");
		strcpy(matrix[40], "|  | |---  |             ---------| |--|");
		strcpy(matrix[41], "|  | |   | |    |    | | |             |");
		strcpy(matrix[42], "|  | |   | |    |    |-|-|         ----|");
		strcpy(matrix[43], "|  | |     |    | |         |  |       |");
		strcpy(matrix[44], "|  | |-----|    |-|-        |  | ----  |");
		strcpy(matrix[45], "|  |    |           |       |  |     | |");
		strcpy(matrix[46], "|  |----|  ------   |---    |  |  -  | |");
		strcpy(matrix[47], "|     |    |            |   |  |   | | |");
		strcpy(matrix[48], " ------------------------OOO----------- ");

	}
	if (levelnumber == 2) {
		//The left middle maze section.
		strcpy(matrix[0], " ");
		strcpy(matrix[1], "------------------------------------------");
		strcpy(matrix[2], "|      | |            |  |    |  |       |");
		strcpy(matrix[3], "|---   | | -----      |  |    |  |       |");
		strcpy(matrix[4], "|   |  | |   |   |       |    |  |       |");
		strcpy(matrix[5], "|   |  | |-  | --|  -----|    |  |  -----|");
		strcpy(matrix[6], "|   |  |     |       |        |  |  |    |");
		strcpy(matrix[7], "|  -|  |---  |       |    ----|  |  |    |");
		strcpy(matrix[8], "| |     |  | | |  |    |         |  | |  |");
		strcpy(matrix[9], "| |---  |  | | |  |    |         |  | |  |");
		strcpy(matrix[10], "| |     |      |  |    |         |  | |  |");
		strcpy(matrix[11], "| |---  |  ----|- |----|   ------|  | |  |");
		strcpy(matrix[12], "|     |                  | |  |       |  |");
		strcpy(matrix[13], "|     |              ----| |  |   ----|  |");
		strcpy(matrix[14], "|   | |                | | |  |    |  |  |");
		strcpy(matrix[15], "|---| |---    ---      | | |  |    |  |  |");
		strcpy(matrix[16], "| | |         |        |      |    |     |");
		strcpy(matrix[17], "| | |         |  ------|  --- |    |   --|");
		strcpy(matrix[18], "| |   | | |   |    |   |   |       |   | |");
		strcpy(matrix[19], "| |---|-| |   |----|   |   |       |   | |");
		strcpy(matrix[20], "|       | |            |   |           | |");
		strcpy(matrix[21], "|       | |----       -|---|   --------| |");
		strcpy(matrix[22], "|   |   |                 |   |          |");
		strcpy(matrix[23], "|---|   |------    ---    |   |          |");
		strcpy(matrix[24], "|   |            | |  |    |             |");
		strcpy(matrix[25], "|   |            | |  |   -|---    ------|");
		strcpy(matrix[26], "| | |            | |  |            |   | |");
		strcpy(matrix[27], "| | |        ----|-|  |-------     |   | |");
		strcpy(matrix[28], "| |     |    |   |                 |   | |");
		strcpy(matrix[29], "| |-----|    |   |                 |   | |");
		strcpy(matrix[30], "|     | |    | | |    |   |            | |");
		strcpy(matrix[31], "|-----| |----| | |-   |   |     -------| |");
		strcpy(matrix[32], "|   |          |      |   |              |");
		strcpy(matrix[33], "|   |    ------|-     |---|   ---  ---   |");
		strcpy(matrix[34], "|   |              |           | | |  |  |");
		strcpy(matrix[35], "|   |  --    ------|        ---| | |  |  |");
		strcpy(matrix[36], "|      | | | |                 | | |  |  |");
		strcpy(matrix[37], "|------| |-|-|        -----    | | |  |--|");
		strcpy(matrix[38], "|                        |         |     |");
		strcpy(matrix[39], "|    ----       ------   |    -----|     |");
		strcpy(matrix[40], "|  | |     |          |  |           |   |");
		strcpy(matrix[41], "|  | |---  |  --------|  |        ---|   |");
		strcpy(matrix[42], "|          |    |   |       |      |     |");
		strcpy(matrix[43], "|----   ---|    |   |-------|      |--   |");
		strcpy(matrix[44], "|             | |               |        |");
		strcpy(matrix[45], "|  --   ---   |-|    -----   ---|   -----|");
		strcpy(matrix[46], "| |           |           |     |     |  |");
		strcpy(matrix[47], "| |           |           |     |---  |  |");
		strcpy(matrix[48], "| |           |           |   | |   |    |");
		strcpy(matrix[49], "| |     ------|--------   |   | |   |----|");
		strcpy(matrix[50], "| |  |  |   |               |            |");
		strcpy(matrix[51], "| |  |  |-  |  ------  -----|---------   |");
		strcpy(matrix[52], "| |  |      |  |       |              |  |");
		strcpy(matrix[53], " --------------------OOOOO--------------- ");
	}

	if (levelnumber == 3) {
		strcpy(matrix[0], " ");
		strcpy(matrix[1], " ------------------------------------------------- ");
		strcpy(matrix[2], "|       | |   | |-----| |          |  | | | |     |");
		strcpy(matrix[3], "|       | |  |          |      --  |  | | | | ----|");
		strcpy(matrix[4], "|   |   | |  |--------| |      |   |  | | |       |");
		strcpy(matrix[5], "|-  |---| |    ----   | |---   | --|  | | |       |");
		strcpy(matrix[6], "|   |       |  |      |     |         |   |       |");
		strcpy(matrix[7], "|   |  --   |  |    --|-    |   -     |   |  -----|");
		strcpy(matrix[8], "| |                 |   |   |   |     |   |       |");
		strcpy(matrix[9], "| |--   -   ----  --|  -|   |   | ----|   |       |");
		strcpy(matrix[10], "|        |  |       |       |   | |   |   |       |");
		strcpy(matrix[11], "|    --  |  |--   --| ------|   | | --| --|-      |");
		strcpy(matrix[12], "|        |  |   | | |           |     |      |    |");
		strcpy(matrix[13], "|        |  |---| | |     ------| ----|     -|----|");
		strcpy(matrix[14], "| |   |         | |       |     |           |     |");
		strcpy(matrix[15], "| |---|         | |--    -|--   |-       ---| ----|");
		strcpy(matrix[16], "| |   |       |   |      |   |  | |               |");
		strcpy(matrix[17], "| |   |       |   | -----|   |  | |    ---  ------|");
		strcpy(matrix[18], "|   |    |    |     |    |   |  | |  |    |  | |  |");
		strcpy(matrix[19], "|  -|-   |    |  ---|--  |   |  | |--|-   |  | |  |");
		strcpy(matrix[20], "| | |    |    |   |    |     |  |    |    |  | |  |");
		strcpy(matrix[21], "| | |  --|  --|   |    |     |  |    |    | -| |  |");
		strcpy(matrix[22], "|      |   |  | | | |  |     |       |      |  |  |");
		strcpy(matrix[23], "|----  |   |  |-|-| |  |     |   --  |      |  |  |");
		strcpy(matrix[24], "|      |   |        |  |     |   | | |      |     |");
		strcpy(matrix[25], "|-     |  -|   --   |  |   --|---| | |--  --|--   |");
		strcpy(matrix[26], "|   |     |         |  |         | | |  |       | |");
		strcpy(matrix[27], "|-  | ----|----     | -|-       -| | |- |-----  |-|");
		strcpy(matrix[28], "|         |         |  |       |              | | |");
		strcpy(matrix[29], "|-      --|---      |  |       |-     -  -----| | |");
		strcpy(matrix[30], "| |  | |          | |  |       |   | | |          |");
		strcpy(matrix[31], "| |--| |          |-|- |       |  -| | |--        |");
		strcpy(matrix[32], "|    | |      |   |    |   |   |     |    |  |    |");
		strcpy(matrix[33], "|    |-|      |  -|--- |---|   |  ---|    |  |    |");
		strcpy(matrix[34], "| |           | |                |        |  |  | |");
		strcpy(matrix[35], "| |   --    --|-|    ---    ---  |        |  |--|-|");
		strcpy(matrix[36], "| | |      |    | |     |      | |   |    |       |");
		strcpy(matrix[37], "| | |      |  --|-|     |      | |---|--  |--     |");
		strcpy(matrix[38], "| | |   |         |   | |   |  | |              | |");
		strcpy(matrix[39], "| | | --|-   -----|   | |   |  | |-------       | |");
		strcpy(matrix[40], "| |     |   |   | |   | |   |  |           |    | |");
		strcpy(matrix[41], "| |     |   |   |-|   |-|   |--|  ------   |  --| |");
		strcpy(matrix[42], "|   | | | | |     | |     | |         |    |      |");
		strcpy(matrix[43], "|-  | |-| | |     | |--   | |-------  |    |------|");
		strcpy(matrix[44], "|   |     |       | |     |   | |   | | |  |      |");
		strcpy(matrix[45], "|   |-   -|---    | |  ---|-  | | --| | |  |      |");
		strcpy(matrix[46], "| | |             |         |   |   |   |  |  | | |");
		strcpy(matrix[47], "| | |             |         |---| --|---|  |  | | |");
		strcpy(matrix[48], "| | | |           |               |           | | |");
		strcpy(matrix[49], " ----------OOO------------------------------------ ");

	}

	if (levelnumber == 4) {
		//The top right maze section.
		strcpy(matrix[0], " ");
		strcpy(matrix[1], " ------------------------------------------ ");
		strcpy(matrix[2], "|       |     |  |  |   |  |               |");
		strcpy(matrix[3], "|---    |    |   |  |   |  |               |");
		strcpy(matrix[4], "|   |   |    |   |  |   |  |               |");
		strcpy(matrix[5], "|   |   |--  |-- |  |-  |  |  -------------|");
		strcpy(matrix[6], "| | |            |  |   |  | |         |   |");
		strcpy(matrix[7], "| | |  --------- |  |  -|  | |    ---  |   |");
		strcpy(matrix[8], "| |   |      |             | |         |   |");
		strcpy(matrix[9], "| |---|      |--  --  -----| |         |   |");
		strcpy(matrix[10], "| |          |      |      |           |   |");
		strcpy(matrix[11], "| |          |--    |      |           |   |");
		strcpy(matrix[12], "| |        | |   |  |      |       |       |");
		strcpy(matrix[13], "|-|  ---   | |---|  |------|---    |       |");
		strcpy(matrix[14], "  |        |     |     |       |   |       |");
		strcpy(matrix[15], " -|--      |     |     |       |   |---    |");
		strcpy(matrix[16], "    |  |         |     |       |     |     |");
		strcpy(matrix[17], " -  |  |   ------|---  |   ----|     |     |");
		strcpy(matrix[18], "| |      | |           |             |     |");
		strcpy(matrix[19], "| |  --  | |   ------- |-------      |     |");
		strcpy(matrix[20], "|        | | | |      |      |  |     |    |");
		strcpy(matrix[21], "|        |-|-| |     -|  --  |  |-----|    |");
		strcpy(matrix[22], "| |          | | |  |      |    |     |    |");
		strcpy(matrix[23], "| |--------  |-| |  |  ----|--  |   --|--  |");
		strcpy(matrix[24], "| |              |  |      |    |          |");
		strcpy(matrix[25], "| |      --------|  |      |    |        --|");
		strcpy(matrix[26], "|    |  |        |  |      |    |     | |  |");
		strcpy(matrix[27], "|    |  |  --    |  |---   |  --|    -|-|  |");
		strcpy(matrix[28], "|    |  | |      |                    |    |");
		strcpy(matrix[29], "| ---|- | |------|   -------    ---   |   -|");
		strcpy(matrix[30], "|       |    |       |      |    |    |  | |");
		strcpy(matrix[31], "|       |-   |-      |      |-   |    |  | |");
		strcpy(matrix[32], "|         |  |       |        |  |    |    |");
		strcpy(matrix[33], "|-----    |  |-      |  ---   |  |   -|    |");
		strcpy(matrix[34], "|   |     |          |   |    |  |         |");
		strcpy(matrix[35], "|-  |---  |   -------|   |   -|  |    -----|");
		strcpy(matrix[36], "|   |   | |  |         | |           |     |");
		strcpy(matrix[37], "|   |   |-|  |  ---    | |      -   -|     |");
		strcpy(matrix[38], "| |     | |  | |   |   | |         |    |  |");
		strcpy(matrix[39], "| |-  --| |  | |   |   | |----    -|    |  |");
		strcpy(matrix[40], "| | | | |      |   |             |      |  |");
		strcpy(matrix[41], "| | | | |     -|   |---       ---|      |  |");
		strcpy(matrix[42], "| | | |          |     |       |    |   |  |");
		strcpy(matrix[43], "| | | |          |  ---|       |    |---|--|");
		strcpy(matrix[44], "|   |   |  |   | | |   |       |    | | |  |");
		strcpy(matrix[45], "|   |   |  |   | | |   |   --- |   -| | |  |");
		strcpy(matrix[46], "|   |   |  |   |   |   | | |   |           |");
		strcpy(matrix[47], "|   |---|  |   |---|   | | |  -|--     ----|");
		strcpy(matrix[48], "| |        |           | | |               |");
		strcpy(matrix[49], " -----------------------OOO---------------- ");

	}

	if (levelnumber == 5) {

		//center center maze.
		strcpy(matrix[0], " ");
		strcpy(matrix[1], " -------------------------------------------------- ");
		strcpy(matrix[2], "|         | | |                |      |   |  |     |");
		strcpy(matrix[3], "|         | | |------    ---   |---  -|-- |  |  ---|");
		strcpy(matrix[4], "|         | |        |  |   |  |   |  |      |     |");
		strcpy(matrix[5], "| ------  | |        |  |---|  |   | -|----  |     |");
		strcpy(matrix[6], "| |     | | |        |         | | |     | |       |");
		strcpy(matrix[7], "| | --- | | |   ---  |   ---   | | |     | |  -----|");
		strcpy(matrix[8], "| | | | | | |  |   | |  |        |   | | |   |     |");
		strcpy(matrix[9], "| | | | | |-|--|-  | |  |   -----|---|-| |   |     |");
		strcpy(matrix[10], "| | | | | |      | | |  |   | |              |  |  |");
		strcpy(matrix[11], "| | | | | |      | | |--|-  | |        ------|  |  |");
		strcpy(matrix[12], "| | | | | |   |  | |          |                 |  |");
		strcpy(matrix[13], "| | | |-|-|   |  | |-         |---              |  |");
		strcpy(matrix[14], "| | |         |  |   |          |   |     |     |  |");
		strcpy(matrix[15], "| | |         |  |   |-----  ---|   | ----|-----|  |");
		strcpy(matrix[16], "| | |     |   |  |         |    |   | |            |");
		strcpy(matrix[17], "| | |     |   |  |         | ---|-- |-|            |");
		strcpy(matrix[18], "| | | | | |   |  |         | |                     |");
		strcpy(matrix[19], "| | | | | |   |  |  --     | |                     |");
		strcpy(matrix[20], "| |   | | |   |  |  |      | |     |               |");
		strcpy(matrix[21], "| |   | | |   |  |--|--    | |     |---  --------  |");
		strcpy(matrix[22], "| |     | |            | | | |     |   | | |     | |");
		strcpy(matrix[23], "| |-----| |            | | | |     |   | | |     | |");
		strcpy(matrix[24], "|         |            | | | |       |   | |   |   |");
		strcpy(matrix[25], "|-------- |------------|-| | |    ---|---| |-  |---|");
		strcpy(matrix[26], "|         |     |          | | | |     |     |     |");
		strcpy(matrix[27], "|  -----  |     |  --------|-|-| |     |     |     |");
		strcpy(matrix[28], "|       | |   |   |   |      | | |           | | | |");
		strcpy(matrix[29], "|       |-|   |  -|   |  --  | | |           | | | |");
		strcpy(matrix[30], "|     |       | | |   |    |                 | | | |");
		strcpy(matrix[31], "| ----|  ---  | | | --|    |   ----       ---| | |-|");
		strcpy(matrix[32], "| | | |     | |   |        |       |       | | |   |");
		strcpy(matrix[33], "| | |-|-    | |---| -----  |       |      -| | | --|");
		strcpy(matrix[34], "| |                      | | | |   |     |     |   |");
		strcpy(matrix[35], "| |---              -----| | | | --|  ---|  -  |-  |");
		strcpy(matrix[36], "|       |     | |   |      | | | |     | | |       |");
		strcpy(matrix[37], "|-----  |     |-|   |---   |-|-| |   --| | |    -  |");
		strcpy(matrix[38], "|     | | |   |          |   | | |  |            | |");
		strcpy(matrix[39], "|     | |-|---|--        |-  | | | -|----        | |");
		strcpy(matrix[40], "| |   |             |       |  | |       |   | |   |");
		strcpy(matrix[41], "|-|  -|  --   --  --|  ---  |--| |   --  |  -| |-- |");
		strcpy(matrix[42], "|   |      | |  | |                  | |           |");
		strcpy(matrix[43], "|   |      | |  |-|---    -----      | |           |");
		strcpy(matrix[44], "|     |   |           |        |   | | |  |  | | | |");
		strcpy(matrix[45], "|   --|-  |---        |        |   |-|-|  |  | | | |");
		strcpy(matrix[46], "|  |             | |  |   |    | | |      |  | | | |");
		strcpy(matrix[47], "|--|  ----       | |--|   |    | | |------|- |-| | |");
		strcpy(matrix[48], "|         | | |       |   |      | |           | | |");
		strcpy(matrix[49], "|         | | | ---   |   |  ----|-|   --------| | |");
		strcpy(matrix[50], "| | | | |   |  | | |  |   |        | | |         | |");
		strcpy(matrix[51], "| |-|-| |   |--| | |--|   |--    --| | |  -------|-|");
		strcpy(matrix[52], "|       |             |   |        | | |           |");
		strcpy(matrix[53], " -----------------------------------OOO------------ ");

	}

	if (levelnumber == 6) {

		//Center right maze.
		strcpy(matrix[0], " ");
		strcpy(matrix[1], " -------------------------------------------- ");
		strcpy(matrix[2], "|                  |  |        |             |");
		strcpy(matrix[3], "|---    ---    ----|  |     ---|-----        |");
		strcpy(matrix[4], "|    | |   |  |       | |      |     | |     |");
		strcpy(matrix[5], "|----| |   |  | -   --| |      |---  | |     |");
		strcpy(matrix[6], "|      |   |  |    |  | |            | |     |");
		strcpy(matrix[7], "|------|  -|  |--  |- | |         ---| |     |");
		strcpy(matrix[8], "| |  |   |       |    | |            | |     |");
		strcpy(matrix[9], "| |  |  -|   --- |----| |------------| |     |");
		strcpy(matrix[10], "| |  |        |  |                     |     |");
		strcpy(matrix[11], "| |  |  ---   |  |----------       ----|     |");
		strcpy(matrix[12], "|    | |   |  |           |   | |  |         |");
		strcpy(matrix[13], "|    |-|   |  |-------    |  -|-|  |         |");
		strcpy(matrix[14], "|        |    |       | | | |   |  |   |     |");
		strcpy(matrix[15], "|-       |--- |  ---  | | |-|   |--|   |     |");
		strcpy(matrix[16], "| |                 |   |   | | |      |     |");
		strcpy(matrix[17], "| |   ---           |  -|---|-| |     -|     |");
		strcpy(matrix[18], "| |  |     |      | | |            | |       |");
		strcpy(matrix[19], "| |  |     |------|-|-|  --     ---| |       |");
		strcpy(matrix[20], "| |  |     |      |        |   |   | |       |");
		strcpy(matrix[21], "| |  |     |----- |------  |-  |   | |----   |");
		strcpy(matrix[22], "|      |                 |   |       |       |");
		strcpy(matrix[23], "|      |-   -----     ---|   |---    |       |");
		strcpy(matrix[24], "|        |         |     |   |   |           |");
		strcpy(matrix[25], "|----   -|  -----  |     |   |-  |     ------|");
		strcpy(matrix[26], "|    |     |   |   |     |       |        |  |");
		strcpy(matrix[27], "|  --|  ---|-  |   |  ---|       |--------|  |");
		strcpy(matrix[28], "| |    |       |   | |     |   |     |    |  |");
		strcpy(matrix[29], "| |    |       |---| |     |   |--   |    |  |");
		strcpy(matrix[30], "|      |       |     |     |   |       |     |");
		strcpy(matrix[31], "|------|     --|     |-----|   |   --- |   --|");
		strcpy(matrix[32], "|              |     |     |   |  |    |     |");
		strcpy(matrix[33], "|        ----  |  ---|     |---|  |    |     |");
		strcpy(matrix[34], "|            | |               |  |    |     |");
		strcpy(matrix[35], "|    -----  -| |        -----  |  |  --|---  |");
		strcpy(matrix[36], "| |            |             | |  |          |");
		strcpy(matrix[37], "| |  -----     |------       | |  |------   -|");
		strcpy(matrix[38], "| | |                 |      | |     |       |");
		strcpy(matrix[39], "| | |----------       |   ---| |     |   ----|");
		strcpy(matrix[40], "| | |          |  |      |   | |     | |   | |");
		strcpy(matrix[41], "|-|-|   ---    |  |      |  -| |-  --|-|   | |");
		strcpy(matrix[42], "|          |   |  |   |  |       |     | | | |");
		strcpy(matrix[43], "|---     --|   |--|---|  |-------|    -|-| | |");
		strcpy(matrix[44], "|       |             |                | |   |");
		strcpy(matrix[45], "|  ---  |  -------    |   ---------   -| |-  |");
		strcpy(matrix[46], "|   |   | |       |   |  |                 | |");
		strcpy(matrix[47], "|   |   | |  ---  |   |  |  -----     ---  | |");
		strcpy(matrix[48], "|   |     |     | |      |    |    |     | | |");
		strcpy(matrix[49], "|   | ----|  -  | | -----|--- |    |-    | | |");
		strcpy(matrix[50], "|           | | | |           |          | | |");
		strcpy(matrix[51], "|--   ------| | | | ---    ---|---       | |-|");
		strcpy(matrix[52], "|             | | |    |  |              | | |");
		strcpy(matrix[53], " --------------   --------------------------- ");

	}
}

void printgrid() {
	for (int i=0; i<60; i++) {
		for (int j=0; j<60; j++) {
			printf("%c", matrix[i][j]);
		}
		printf("\n");
	}
}

void changelevel(int &currentlevel) {
	int clear = 0;

	if (currentlevel == 1&& matrix[my+1][mx] == 'O'&& my == 47&& (mx == 26||mx== 27||mx== 28)) {
		currentlevel++;

		my = 1;
		mx = 14;
		clear = 1;
	}
	if (currentlevel == 2&& matrix[my+1][mx] == 'O'&& my== 52&& (mx == 22||mx== 23||mx== 24||mx == 25||mx == 26)) {
		currentlevel = 3;
		my = 2;
		mx = 14;
		clear = 1;
	}
	if (currentlevel == 3&& matrix[my+1][mx] == 'O'&& my== 48&& (mx == 12||mx== 13||mx== 14)) {
		currentlevel = 4;
		my = 2;
		mx = 14;
		clear = 1;
	}
	if (currentlevel == 4&& matrix[my+1][mx] == 'O'&& my== 48&& (mx == 25||mx== 26||mx== 27)) {
		currentlevel = 5;
		my = 2;
		mx = 14;
		clear = 1;
	}
	if (currentlevel == 5&& matrix[my+1][mx] == 'O'&& my== 52&& (mx == 38||mx== 39||mx== 40)) {
		currentlevel = 6;
		my = 2;
		mx = 14;
		clear = 1;
	}
	if (currentlevel == 6&& matrix[my-5][mx] == 'O'&& my== 52&& (mx == 16||mx== 17||mx== 18)) {
		currentlevel = 1;
		my = 2;
		mx = 14;
		clear = 1;
	}
	if (clear == 1) {
		loadlevel(currentlevel);
		system("cls");
		printgrid();
		gotoxy(mx, my);
		printf("@");
		gotoxy(0, 0);
		gotoxy(0, 21);
	}
}

int main() {

	int level = 1;
	system("COLOR 0B");
	loadlevel(level);
	printgrid();

	gotoxy(mx, my);

	printf("@");
	gotoxy(0, 0);
	gotoxy(0, 21);

	while (mx>0&& my>0) {
		loadlevel(level);

		if (kbhit()) {
			direction=getch();

			if ((direction == 'd') || (direction == 'a')|| (direction == 'w')|| (direction == 's')|| (direction == 'S')
					|| (direction== 'D')|| (direction == 'A')|| (direction == 'W')|| (direction == 'e')|| (direction
					== 'E')) {
				if (direction == 's'|| direction == 'S') {
					gotoxy(mx, my);
					printf("@");
					facing = 'S';
					if (matrix[my+1][mx] == ' ') {
						gotoxy(mx, my);
						printf(" ");
						my++;
						gotoxy(mx, my);
						printf("@");
					}
				}
				if (direction == 'w'|| direction == 'W') {
					gotoxy(mx, my);
					printf("@");
					facing = 'W';
					if (matrix[my-1][mx] == ' ') {
						gotoxy(mx, my);
						printf(" ");
						my--;
						gotoxy(mx, my);
						printf("@");
					}
				}
				if (direction == 'a'|| direction == 'A') {
					gotoxy(mx, my);
					printf("@");
					facing = 'A';
					if (matrix[my][mx-1] == ' ') {
						gotoxy(mx, my);
						printf(" ");
						mx--;
						gotoxy(mx, my);
						printf("@");
					}
				}
				if (direction == 'd'|| direction == 'D') {
					gotoxy(mx, my);
					printf("@");
					facing = 'D';
					if (matrix[my][mx+1] == ' ') {
						gotoxy(mx, my);
						printf(" ");
						mx++;
						gotoxy(mx, my);
						printf("@");
					}
				}
				if (direction == 'e'|| direction == 'E') {
					changelevel(level);

				}

				direction = ' ';
				gotoxy(0, 21);
			}
		}

	}
	return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.