Code:
const int ROW_SIZE = 20, COL_SIZE = 17;
void printMaze(char [][COL_SIZE], char *, char);
bool isMoveLegal(char );
int _tmain(int argc, _TCHAR* argv[])
{
char board[ROW_SIZE][COL_SIZE] = {{'+','-','-','-','-','-','-','-','+','-','-','-','-','-','+','-','+'},
{'|',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ',' ',' ','|',' ','|'},
{'|',' ','+','-','-','-','+',' ','|',' ','+','+',' ','+','+',' ','|'},
{'|',' ','|',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ','|',' ','|'},
{'|',' ','|',' ','+',' ','+','-','+','-','+',' ','+',' ','+',' ','|'},
{'|',' ','|',' ','|',' ',' ',' ','|',' ',' ',' ','|',' ',' ',' ','|'},
{'|',' ','+','-','+','-','+',' ','+','-','-','-','+',' ','+','-','+'},
{'|',' ',' ',' ','|',' ',' ',' ','|',' ',' ',' ','|',' ','|',' ','|'},
{'+','-','-','-','+',' ','+','-','+','-','+',' ','+',' ','|',' ','|'},
{'|',' ',' ',' ','|',' ','|',' ',' ',' ','|',' ',' ',' ','|',' ','|'},
{'|',' ','+',' ','|',' ','+',' ','+','-','+',' ','+','-','+',' ','|'},
{'|',' ','|',' ','|',' ',' ',' ','|',' ',' ',' ','|',' ',' ',' ','|'},
{'+','-','+',' ','|',' ','+','-','+','-','+',' ','+',' ','+','-','+'},
{'|',' ',' ',' ','|',' ',' ',' ','|',' ',' ',' ',' ',' ','|',' ','|'},
{'+','+','+',' ','+','+','-','-','+',' ','+','+','-','-','+',' ','|'},
{'+','+',' ',' ',' ','+',' ',' ',' ',' ',' ','|',' ',' ',' ',' ','|'},
{'|',' ',' ','+',' ',' ',' ',' ','+','+',' ','|',' ','+','+',' ','|'},
{'|',' ','+','+','-','+','-',' ','+','+',' ','+',' ','+','+',' ','|'},
{'|',' ',' ',' ',' ','|',' ',' ',' ','|',' ',' ',' ',' ','|','X','|'},
{'+','-','-','-','-','+','-','-','-','+','-','-','-','-','+','-','+'}};
char *position;
position = &board[1][1];
char symbol='^';
while (!GetAsyncKeyState(VK_ESCAPE) && *position != 'X')
{
printMaze(board, position, symbol);
char *nextPosition = position;
if (GetAsyncKeyState(VK_UP))
{
symbol = '^';
// not complete need to update
}
else if (GetAsyncKeyState(VK_DOWN))
{
symbol = 'v';
}
else if (GetAsyncKeyState(VK_RIGHT))
{
symbol = '>';
}
else if (GetAsyncKeyState(VK_LEFT))
{
symbol = '<';
}
// call isMoveLegal function to see if you can move to the new // position. If so, then update the value of the position // variable to be equal to the nextPosition variable
Sleep(100);
}
// probably insert if position of X = winning position cout you win //etc..
system("pause");
}
bool isMoveLegal(char Target)
{
bool result = false;
if (Target == ' ' || Target == 'X')
{
result = true;
}
return result;
}
void printMaze(char board[][COL_SIZE], char *player, char symbol)
{
System::Console::SetCursorPosition( 0, 0);