




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、/*運(yùn)行是按任意鍵開(kāi)始,不過(guò)呢,反向也算輸喲*/#include <stdlib.h>#include <stdio.h>#include <graphics.h>#include <dos.h>#include <conio.h>#include <bios.h>#include <math.h>#define UP 0x4800#define DOWN 0x5000#define LEFT 0x4b00#define RIGHT 0x4d00#define ESC 0x011b#define SPACE 0
2、x3920#define M 25#define N 25#define blue 1#define green 2#define red 4#define yellow 14#define yes 1#define no 0struct snake int l,t,r,b; int color; int direction;
3、0; /*0不動(dòng) 1 上 2下 3左 4右 蛇頭的方向 */qu1M*N;int d4=-25,25,-1,1; /*蛇頭移動(dòng)的方向 */int length; /*蛇身長(zhǎng)度 */int sp
4、eed=50000000; /*移動(dòng)的速度 */int head; /*蛇頭的位置 */int food;int appear;int key;int direct;int all_food;int tail,mark;int Q=1;vo
5、id draw_map() /*地圖 */int i,j,n=17,v=1; int a2525; for(i=0;i<=24;i+) for(j=0;j<=24;j+) if(j=0|j=24|i=24|i
6、=0) aij=0; /* 0 stans for block */ else aij=1; for(i=0;i<
7、=24;i+) for(j=0;j<=24;j+) if(aij=0) setfillstyle(1,green); qu1v.color=green;
8、; if(aij=1) setfillstyle(1,blue); &
9、#160; qu1v.color=blue; qu1v.l=20+n*j; qu1v.t=20+n*i; qu1v.r=35+n*
10、j; qu1v.b=35+n*i; qu1v.direction=0; bar( qu1v.l, qu1v.t, qu1v.r, qu1v.b); v+; &
11、#160; void draw_snake() int v,j; v=head=303; all_food=10; length=0; for(j=0;j<=1;j+,v-) setfillstyle(1,yellow); bar( qu1v.l, qu1v.t, qu1v.r, qu1v.b);
12、60; qu1v.color=red; qu1v.direction=4; length+; void diamond() float t; int x0=540,y0=165; int n=16,i,j,r=90; int x50,y50; t=6.28318/n;
13、60; for(i=0;i<n;i+) xi=x0+r*cos(i*t); yi=y0+r*sin(i*t); setcolor(yellow); for(i=0;i<=n-2;i+) setcolor(YELLOW);
14、; for(j=1;j<=n-1;j+) line(xi,yi,xj,yj); main()int gdrive=VGA;
15、60; int gmode=VGAHI; int class; initgraph(&gdrive,&gmode,"c:tc"); setcolor(LIGHTRED); outtextxy(450,280,"SPACE :Pause"); outtextxy(450,300,"ESC :Exit"); outtextxy(450,320,"Left");
16、60;outtextxy(450,340,"Right"); outtextxy(450,360,"Up "); outtextxy(450,380,"Down "); outtextxy(450,400,"THE FOUR KEYES TO MOVE"); setcolor(YELLOW); outtextxy(40,2," Welcome to snake game and Please any key begin !")
17、; outtextxy(450,33,"Class:"); outtextxy(450,51,"All_food:"); randomize(); diamond(); for(class=1;class<=3;class+) draw_map(); draw_snake(); appear=no;
18、60; /*沒(méi)有食物*/ getch(); while(bioskey(1)!=0) key=0; getch(); while(1) gotoxy(63,3); printf("%d",class);
19、160; gotoxy(66,4); if(all_food>=10) printf("%d",all_food); else
20、160; printf("0%d",all_food); if(all_food=0) setcolor(red+class);
21、0; outtextxy(50,450, " Congratulation and Please any key goto the next! "); break;
22、60; if(appear=no) do food=random(600); while(qu1food.color=yellow|qu1food.color=red|qu1foo
23、d.color=green|food=0); qu1food.color=red; qu1food.direction=0; setfillstyle(1,red); &
24、#160; bar(qu1food.l, qu1food.t, qu1food.r, qu1food.b); appear=yes;
25、60; star: do tail=head; mark=length;
26、; switch(qu1head.direction) case 1: head=head+d0;
27、60; direct=1;
28、; break; case 2: head=head+d1;
29、 direct=2; break; &
30、#160; case 3: head=head+d2; direct=3;
31、; break;
32、60; case 4: head=head+d3; direct=4; &
33、#160; if(qu1head.direction!=0|qu1head.color=green) /*撞墻或撞自己*/
34、60; if(Q=1) setcolor(red);
35、60; outtextxy(450,200, " Any key to exit ! "); getch();closegraph(); exit(0);
36、160; else &
37、#160; Q=1; qu1head.direction=direct;
38、0; if(head=food) appear=no; delay(speed); &
39、#160; all_food-; length+; continue; &
40、#160; qu1head.color=yellow; setfillstyle(1,yellow);
41、 bar(qu1head.l, qu1head.t, qu1head.r, qu1head.b); setfillstyle(1,red);
42、 bar( qu1tail.l, qu1tail.t, qu1tail.r, qu1tail.b); for(;length>1;length-) &
43、#160; tail=tail-dqu1tail.direction-1; setfillstyle(1,blue);
44、 bar( qu1tail.l, qu1tail.t, qu1tail.r, qu1tail.b); qu1tail.color=blue; qu1tai
45、l.direction=0; length=mark; delay(speed); while(!kbhit();
46、60; key=bioskey(0); if(qu1head.direction=1) if(key=UP)
47、60; Q=0; continue;
48、60; if(qu1head.direction=2) if(key=DOWN) Q=0;
49、160; continue; if(qu1head.direction=3) if(key=LEFT)&
50、#160; Q=0; continue;
51、60; if(qu1head.direction=4) if(key=RIGHT)
52、0; Q=0; continue; tail=head;
53、 mark=length; switch(key) ca
54、se UP : head=head+d0; direct=1;
55、0; break; case DOW
56、N : head=head+d1; direct=2;
57、60; break; case LEFT :
58、160; head=head+d2; direct=3;
59、160; break;
60、 case RIGHT: head=head+d3; direct=4;
61、 break; case ESC :
62、 exit(0); case SPACE: getch(); goto star; /* 暫停*/
63、; if(qu1head.direction!=0|qu1head.color=green) /*撞墻或撞自己*/ &
64、#160; if(Q=1)
65、160; setcolor(red); outtextxy(450,200, " Any key to exit ! ");
66、; getch();closegraph(); exit(0);
67、160; else Q=1; &
68、#160; qu1head.direction=direct; if(head=food) appear=no; delay(speed);
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 保理人合同范本
- 勞務(wù)派遣合同范本 司機(jī)
- 包工頭與臨時(shí)工人合同范本
- 勞務(wù)合同單包工合同范本
- 企業(yè)合同范本封面
- 勞務(wù)用工結(jié)算合同范本
- 單位采購(gòu)書(shū)合同范本
- 醫(yī)院影像科合同范本
- 與商城簽約合同范本
- 鐵嶺鋼板搪瓷水箱施工方案
- 第九屆鵬程杯五年級(jí)數(shù)學(xué)競(jìng)賽初試真題
- 實(shí)驗(yàn)一 外科常用手術(shù)器械課件
- 電梯結(jié)構(gòu)與原理-第2版-全套課件
- 《現(xiàn)代漢語(yǔ)》語(yǔ)音教學(xué)上課用課件
- 采購(gòu)流程各部門關(guān)系圖
- 《遙感導(dǎo)論》全套課件
- 力士樂(lè)工程機(jī)械液壓培訓(xùn)資料(共7篇)課件
- 村光伏發(fā)電申請(qǐng)書(shū)
- 降低混凝土路面裂縫發(fā)生率QC小組資料
- 【教師必備】部編版四年級(jí)語(yǔ)文上冊(cè)第二單元【集體備課】
- 支氣管擴(kuò)張的護(hù)理PPT
評(píng)論
0/150
提交評(píng)論