//向上的移动指令
void directUp()
{
int nextRow = row - 1;
int nextCol = col;
if(gameMap[nextRow][nextCol] != '#')
{
gameMap[row][col] = ' ';
gameMap[nextRow][nextCol] = '0';
row = nextRow;
col = nextCol;
}
}
//向下的移动指令
void directDown()
{
int nextRow = row + 1;
int nextCol = col;
if(gameMap[nextRow][nextCol] != '#')
{
gameMap[row][col] = ' ';
gameMap[nextRow][nextCol] = '0';
row = nextRow;
col = nextCol;
}
}
//向左的移动指令
void directLeft()
{
int nextRow = row;
int nextCol = col - 1;
if(gameMap[nextRow][nextCol] != '#')
{
gameMap[row][col] = ' ';
gameMap[nextRow][nextCol] = '0';
row = nextRow;
col = nextCol;
}
}
//向右的移动指令
void directRight()
{
int nextRow = row;
int nextCol = col + 1;
if(gameMap[nextRow][nextCol] != '#')
{
gameMap[row][col] = ' ';
gameMap[nextRow][nextCol] = '0';
row = nextRow;
col = nextCol;
}
}
int main()
{
//打印地图
mapPrint();
while(1)
{
//接收用户输入的方向
rewind(stdin);
char direct = getDirection();
//小人移动
switch(direct)
{
case 'w':
case 'W':
directUp();
break;
case 's':
case 'S':
directDown();
break;
case 'a':
case 'A':
directLeft();
break;
case 'd':
case 'D':
directRight();
break;
case 'q':
case 'Q':
printf("game over !\n");
return 0;