資源描述:
《貪吃蛇c語言代碼》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、貪吃蛇c語言代碼#include#include#include#include#defineNULL0#defineUP18432#defineDOWN20480#defineLEFT19200#defineRIGHT19712#defineESC283#defineENTER7181structsnake{intcenterx;intcentery;intnewx;intnewy;structsnake*next;};structsnake*head;intgrade=60;/*控制速度的*******/inta
2、,b;/*背靜遮的位置*/void*far1,*far2,*far3,*far4;/*蛇身指針背靜遮的指針蟲子*/intsize1,size2,size3,size4;/***全局變量**/intch=RIGHT;/**************存按鍵開始蛇的方向?yàn)镽IGHT***********/intchy=RIGHT;intflag=0;/*********判斷是否退出游戲**************/intcontrol=4;/***********判斷上次方向和下次方向不沖突***/intnextshow=1;/*******控制下次蛇身是否顯示***************/int
3、scenterx;/***************隨即矩形中心坐標(biāo)***************/intscentery;intsx;/*******在ab未改變前得到他們的值保證隨機(jī)矩形也不在此出現(xiàn)*******/intsy;/************************蛇身初始化**************************/voidsnakede(){structsnake*p1,*p2;head=p1=p2=(structsnake*)malloc(sizeof(structsnake));p1->centerx=80;p1->newx=80;p1->centery=58;
4、p1->newy=58;p1=(structsnake*)malloc(sizeof(structsnake));p2->next=p1;p1->centerx=58;p1->newx=58;p1->centery=58;p1->newy=58;p1->next=NULL;}/*******************end*******************/voidwelcome()/*************游戲開始界面 ,可以選擇 速度**********/{intkey;intsize;intx=240;inty=300;intf;void*buf;setfillstyle(SOLI
5、D_FILL,BLUE);bar(98,100,112,125);setfillstyle(SOLID_FILL,RED);bar(98,112,112,114);setfillstyle(SOLID_FILL,GREEN);bar(100,100,110,125);size=imagesize(98,100,112,125);buf=malloc(size);getimage(98,100,112,125,buf);cleardevice();setfillstyle(SOLID_FILL,BLUE);bar(240,300,390,325);outtextxy(193,310,"spee
6、d:");setfillstyle(SOLID_FILL,RED);bar(240,312,390,314);setcolor(YELLOW);outtextxy(240,330,"DOWN");outtextxy(390,330,"UP");outtextxy(240,360,"ENTERtostart...");outtextxy(270,200,"SNAKE");fei(220,220);feiyang(280,220);yang(340,220);putimage(x,y,buf,COPY_PUT);setcolor(RED);rectangle(170,190,410,410);w
7、hile(1){if(bioskey(1))/********8選擇速度部分************/key=bioskey(0);switch(key){caseENTER:f=1;break;caseDOWN:if(x>=240){putimage(x-=2,y,buf,COPY_PUT);grade++;key=0;break;}caseUP:if(x<=375){putimage(x+=2,y,buf