




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、/*運(yùn)行是按任意鍵開始,不過呢,反向也算輸喲*/#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; /*蛇身長度 */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; /*沒有食物*/ 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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 精益生產(chǎn)方式與企業(yè)精益化管理探討
- 供暖行業(yè)部門管理辦法
- 殯葬管理辦法實(shí)施效果
- 金融碩士課程體系核心知識(shí)圖譜構(gòu)建
- 高效農(nóng)田建設(shè)與管理策略研究
- 北京通風(fēng)廊道管理辦法
- 小學(xué)教師教學(xué)研究成果展示
- 煤礦安全檢查工證件查詢
- 機(jī)場勘測項(xiàng)目管理辦法
- 安全生產(chǎn)知培訓(xùn)
- 中遠(yuǎn)海運(yùn)招聘筆試題庫2025
- 中小學(xué)小班化教學(xué)模式與支持體系構(gòu)建研究
- 溫州市2024-2025學(xué)年高一下學(xué)期6月期末-英語試卷及答案
- 2025至2030中國核應(yīng)急機(jī)器人行業(yè)市場現(xiàn)狀分析及競爭格局與投資發(fā)展報(bào)告
- 導(dǎo)管室護(hù)理管理制度
- 降低跌倒事件的發(fā)生率QC圈
- 深靜脈血栓的試題及答案
- 2025年安徽省郵政行業(yè)職業(yè)技能大賽(快遞員賽項(xiàng))備賽試題庫(含答案)
- 汽車產(chǎn)業(yè)鏈協(xié)同發(fā)展-洞察闡釋
- 滴灌帶造顆粒合同協(xié)議
- 學(xué)??倓?wù)后勤工作總結(jié)模版
評論
0/150
提交評論