| else { //eat if(headx==randomNode.x&&heady==randomNode.y) { Enqueue(randomNode); setfillstyle(SOLID_FILL,BLUE); bar(randomNode.x+1,randomNode.y+1,randomNode.x-1+BlockWidth,randomNode.y-1+BlockHeight); neednode=true; } else //no eat { newNode.x=headx; newNode.y=heady; newNode.next=NULL; Enqueue(newNode); outNode=Dequeue(); setfillstyle(SOLID_FILL,LIGHTGRAY); bar(outNode.x+1,outNode.y+1,outNode.x+BlockWidth-1,outNode.y+BlockHeight-1); setfillstyle(SOLID_FILL,BLUE); bar(newNode.x+1,newNode.y+1,newNode.x-1+BlockWidth,newNode.y-1+BlockHeight); } } delay(speed); } } void ClearKeyBuf() { do bioskey(0); while(bioskey(1)); } void Foot(int x,int y) { setcolor(BLUE); outtextxy(x,y,"writer:[T]RealXL E-MAIL:realgeneral@hotmail.com"); } void Head(int x,int y) { setcolor(RED); outtextxy(x,y,"GREEDY SNAKE"); } void Enqueue(Node inNode) { Node *p=new Node; p->x=inNode.x; p->y=inNode.y; p->next=inNode.next; snake.tail->next=p; snake.tail=p; snake.length++; } |