这个怎么弄得啊?不理解为什么。。。
程序代码:
void keyjiance() //按键检测函数定义 { char key; //好像两个函数衔接不上。。。我的按键不起作用。。它只按我最初设定的方向走。。 if(_kbhit()) { key = getch(); switch(key) { case 'w' : headir -> direction == 'w';break; case 's' : headir -> direction == 's';break; case 'd' : headir -> direction == 'd';break; case 'a' : headir -> direction == 'a';break; default : break; } } } void snake_move() //蛇身移动函数定义 { p = head; if(headir -> direction == 'w') { if(food -> x == head -> x && food -> y == head -> y) { gotoxy(food -> x,food -> y); printf(" "); creat_node(head -> x,head -> y -1); //添加结点 creat_food(); //产生食物 } else { creat_node(head -> x,head -> y -1); shanchu_tail(); //删除尾结点 } } if(headir -> direction == 's') { if(food -> x == head -> x && food -> y == head -> y) { gotoxy(food -> x,food -> y); printf(" "); creat_node(head -> x,head -> y + 1); creat_food(); } else { creat_node(head -> x,head -> y + 1); shanchu_tail(); } } if(headir -> direction == 'd') { if(food -> x == head -> x && food -> y == head -> y) { gotoxy(food -> x,food -> y); printf(" "); creat_node(head -> x + 1,head -> y); creat_food(); } else { creat_node(head -> x + 1,head -> y); shanchu_tail(); } } if(headir -> direction == 'a') { if(food -> x == head -> x && food -> y == head -> y) { gotoxy(food -> x,food -> y); printf(" "); creat_node(head -> x -1,head -> y); creat_food(); } else { creat_node(head -> x - 1,head -> y); shanchu_tail(); } } }