1. 蛇移动的思想:
其实就是删除头节点 ,增加尾节点;一句代码搞定
struct Snake *p; p =head; head = head -> next; free(p) 防止造成多的空间节点
2.增加尾节点代码思想:
2.1 .开辟new 节点的空间 struct Snake *new = (struct Snake *)malloc (sizeof(struct Snake));
2.2 . 新节点的行 new ->hang = tail -> hang;
新节点的列 new ->lie =tail -> lie+1;
增加new节点 :tail -> next = new;
新的尾巴 : tail = new ;
void addNode()
{struct Snake *new = (struct Snake *)malloc(sizeof(struct Snake));new -> hang = tail -> hang;new -> lie = tail -> lie+1;tail -> next = new;tail = new;
}void deleteNode()
{struct Snake *p;p = head;head = head ->next;free(p); // fang zhi zao cheng hen duo kong yu de jie dian
}void moveSnake()
{struct Snake *p;struct Snake *new;addNode();deleteNode();
}
int main()
{int ctr;initNcurses();initSnakebody();gamePic();while(1){ctr = getch();if(ctr == KEY_RIGHT){moveSnake();gamePic();}}getch();endwin();return 0;
}