|
贪吃蛇源程序(10) break; default: break; } show_level(); }
/* sub function: calulate_hop() */ /* function: calculate the shortest path from snake head to */ /* the food it will eaten. */ void calculate_hop() { hopcount = (snake_head.posx >= current->posx) ? ((snake_head.posx - current->posx) / SCALE) : ((current->posx - snake_head.posx) / SCALE); hopcount += (snake_head.posy >= current->posy) ? ((snake_head.posy - current->posy) / SCALE) : ((current->posy - snake_head.posy) / SCALE); }
/* sub function: release() */ /* function:free memory before exit game or restart */ void release(SNAKE_HEAD snake_head) { FOOD_INFOR_PTR traceon,last; traceon = snake_head.next; snake_head.eatenC = 0; snake_head.next = NULL; snake_head.hop = 0; while(traceon) if(traceon->next != NULL) traceon = traceon->next; else break; while(traceon) { last = traceon->pre; free(traceon); traceon = last; } } /* sub function: show_level()x */ /* function:show level information to player anytime */ void show_level() { char str[20]; int size; void *buf; settextstyle(DEFAULT_FONT,0,1); setcolor(DEFAULT_COLOR); sprintf(str,"Level:%d",level); size = imagesize(0,border_LT.y,textwidth(str),border_LT.y + textheight(str));
|