intMoveSnake() { Snakenode temp; int flag = 0; temp = snake.snakeNode[snake.length - 1]; //记录蛇尾 for (int i = snake.length - 1; i >= 1; i--) snake.snakeNode[i] = snake.snakeNode[i - 1]; GotoXY(snake.snakeNode[1].x, snake.snakeNode[1].y); printf("*");
//响应键盘的操作 if (_kbhit()) { direction = _getch(); switch (direction) { case UP: if (now_Dir != DOWN) now_Dir = direction; break; case DOWN: if (now_Dir != UP) now_Dir = direction; break; case RIGHT: if (now_Dir != LEFT) now_Dir = direction; break; case LEFT: if (now_Dir != RIGHT) now_Dir = direction; break; } }
switch (now_Dir) { case UP:snake.snakeNode[0].y--; break; //上移 case DOWN:snake.snakeNode[0].y++; break; //下移 case LEFT:snake.snakeNode[0].x--; break; //左移 case RIGHT:snake.snakeNode[0].x++; break; //右移 }