Code:
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <process.h>
#include <iostream.h>
#include <conio_mingw.h>
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
#define ESCAPE 1
int ShowBoard();
char i[15][15] =
{
{'+', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '+'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', 2, ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|'},
{'+', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '+'}
};
int main()
{
int update = 1;
int x = 7, y = 7;
system("CLS");
Sleep(150);
ShowBoard();
// Sleep(100);
do
{
i[x][y] = 2;
if( kbhit() )
{
char keyCode = getch();
// Left movement
if( keyCode == 75 ) //75 - 52
{
ShowBoard();
i[x][y] = ' ';
y--;
cout<<"Left!\n\n\n\n\n\n";
}
// Down movement
else if( keyCode == 80 ) //80 - 50
{
ShowBoard();
i[x][y] = ' ';
x++;
cout<<"Down!\n\n\n\n\n\n";
}
// Right movement
else if( keyCode == 77 ) //77 - 54
{
ShowBoard();
i[x][y] = ' ';
y++;
cout<<"Right!\n\n\n\n\n\n";
}
// Up movement
else if( keyCode == 72 ) //72 - 56
{
ShowBoard();
i[x][y] = ' ';
x--;
cout<<"Up!\n\n\n\n\n\n";
};
};
} while ( 1 );
return 0;
}
int ShowBoard()
{
cout<<i[0][0]<<i[0][1]<<i[0][2]<<i[0][3]<<i[0][4]<<i[0][5]<<i[0][6]<<i[0][7]<<i[0][8]<<i[0][9]<<i[0][10]<<i[0][11]<<i[0][12]<<i[0][13]<<i[0][14]<<"\n";
cout<<i[1][0]<<i[1][1]<<i[1][2]<<i[1][3]<<i[1][4]<<i[1][5]<<i[1][6]<<i[1][7]<<i[1][8]<<i[1][9]<<i[1][10]<<i[1][11]<<i[1][12]<<i[1][13]<<i[1][14]<<"\n";
cout<<i[2][0]<<i[2][1]<<i[2][2]<<i[2][3]<<i[2][4]<<i[2][5]<<i[2][6]<<i[2][7]<<i[2][8]<<i[2][9]<<i[2][10]<<i[2][11]<<i[2][12]<<i[2][13]<<i[2][14]<<"\n";
cout<<i[3][0]<<i[3][1]<<i[3][2]<<i[3][3]<<i[3][4]<<i[3][5]<<i[3][6]<<i[3][7]<<i[3][8]<<i[3][9]<<i[3][10]<<i[3][11]<<i[3][12]<<i[3][13]<<i[3][14]<<"\n";
cout<<i[4][0]<<i[4][1]<<i[4][2]<<i[4][3]<<i[4][4]<<i[4][5]<<i[4][6]<<i[4][7]<<i[4][8]<<i[4][9]<<i[4][10]<<i[4][11]<<i[4][12]<<i[4][13]<<i[4][14]<<"\n";
cout<<i[5][0]<<i[5][1]<<i[5][2]<<i[5][3]<<i[5][4]<<i[5][5]<<i[5][6]<<i[5][7]<<i[5][8]<<i[5][9]<<i[5][10]<<i[5][11]<<i[5][12]<<i[5][13]<<i[5][14]<<"\n";
cout<<i[6][0]<<i[6][1]<<i[6][2]<<i[6][3]<<i[6][4]<<i[6][5]<<i[6][6]<<i[6][7]<<i[6][8]<<i[6][9]<<i[6][10]<<i[6][11]<<i[6][12]<<i[6][13]<<i[6][14]<<"\n";
cout<<i[7][0]<<i[7][1]<<i[7][2]<<i[7][3]<<i[7][4]<<i[7][5]<<i[7][6]<<i[7][7]<<i[7][8]<<i[7][9]<<i[7][10]<<i[7][11]<<i[7][12]<<i[7][13]<<i[7][14]<<"\n";
cout<<i[8][0]<<i[8][1]<<i[8][2]<<i[8][3]<<i[8][4]<<i[8][5]<<i[8][6]<<i[8][7]<<i[8][8]<<i[8][9]<<i[8][10]<<i[8][11]<<i[8][12]<<i[8][13]<<i[8][14]<<"\n";
cout<<i[9][0]<<i[9][1]<<i[9][2]<<i[9][3]<<i[9][4]<<i[9][5]<<i[9][6]<<i[9][7]<<i[9][8]<<i[9][9]<<i[9][10]<<i[9][11]<<i[9][12]<<i[9][13]<<i[9][14]<<"\n";
cout<<i[10][0]<<i[10][1]<<i[10][2]<<i[10][3]<<i[10][4]<<i[10][5]<<i[10][6]<<i[10][7]<<i[10][8]<<i[10][9]<<i[10][10]<<i[10][11]<<i[10][12]<<i[10][13]<<i[10][14]<<"\n";
cout<<i[11][0]<<i[11][1]<<i[11][2]<<i[11][3]<<i[11][4]<<i[11][5]<<i[11][6]<<i[11][7]<<i[11][8]<<i[11][9]<<i[11][10]<<i[11][11]<<i[11][12]<<i[11][13]<<i[11][14]<<"\n";
cout<<i[12][0]<<i[12][1]<<i[12][2]<<i[12][3]<<i[12][4]<<i[12][5]<<i[12][6]<<i[12][7]<<i[12][8]<<i[12][9]<<i[12][10]<<i[12][11]<<i[12][12]<<i[12][13]<<i[12][14]<<"\n";
cout<<i[13][0]<<i[13][1]<<i[13][2]<<i[13][3]<<i[13][4]<<i[13][5]<<i[13][6]<<i[13][7]<<i[13][8]<<i[13][9]<<i[13][10]<<i[13][11]<<i[13][12]<<i[13][13]<<i[13][14]<<"\n";
cout<<i[14][0]<<i[14][1]<<i[14][2]<<i[14][3]<<i[14][4]<<i[14][5]<<i[14][6]<<i[14][7]<<i[14][8]<<i[14][9]<<i[14][10]<<i[14][11]<<i[14][12]<<i[14][13]<<i[14][14]<<"\n";
return 0;
}
Please don't flame for the Global Variables. It's the only way I could think of apart from putting it all in a class.