void snake::move_snake() { if(direction!=0) { if(direction==UP){node n('*',head->Pos_x,head->Pos_y-1); insert_body(n);} else if(direction==DOWN){node n2('*',head->Pos_x,head->Pos_y+1); insert_body(n2);} else if(direction==LEFT){node n3('*',head->Pos_x-2,head->Pos_y); insert_body(n3);} else if(direction==RIGHT){node n4('*',head->Pos_x+2,head->Pos_y); insert_body(n4);} if(head->Pos_x!=apple_x||head->Pos_y!=apple_y)//判断是否吃苹果 delete_tail(); else creat_food(); show_food(); } }
int main() { INITSCR(); INITINFOWIN(); INITGAMEWIN(); food Tfood=creat_food(); snake Tsnake = init_snake(); //创建贪吃蛇 draw_food(Tfood,Tsnake); /* 开始游戏 */ while(start_game(Tsnake,Tfood)>0) ; getch(); destory_snake(Tsnake); endwin(); return 0; }