首页 c语言小游戏

c语言小游戏

举报
开通vip

c语言小游戏c语言小游戏 #include #include #include #include #include int x,y,x1,y1,vx,vy,a,b,z,n,gk=1 ; float t,i,m,jd=45 ; /*图形初始化*/ graph() { int gdriver,gmode ; gdriver=DETECT ; initgraph(&gdriver,&gmode,""); } /*艺术清屏*/ qp() { float l,m ; setcolor(14); f...

c语言小游戏
c语言小游戏 #include #include #include #include #include int x,y,x1,y1,vx,vy,a,b,z,n,gk=1 ; float t,i,m,jd=45 ; /*图形初始化*/ graph() { int gdriver,gmode ; gdriver=DETECT ; initgraph(&gdriver,&gmode,""); } /*艺术清屏*/ qp() { float l,m ; setcolor(14); for(l=1;l<=21;l=l+.02) { m=l ; while(m<480) { line(1,m,640,m); m=m+20 ; } } } /*艺术*/ ys() { float f,g ; setcolor(10); for(f=1;f<=637;f=f+.2) { setcolor(3); line(1,637-f/2,f,0); line(637,f/2,637-f,478); } for(g=1;g<=478;g=g+.2) { setcolor(BLUE); line(1,278-g/2,g,0); line(637,200+g/2,637-g,478); } } /*画点*/ hd() { int i,x,y,z ; for(i=0;i<6000;i++) { x=random(640); y=random(480); z=random(16); putpixel(x,y,z); delay(100); } } /*游戏说明*/ sm() { settextstyle(0,0,2); setcolor(13); outtextxy(0,0,"press 'w' or 's' for setting direction."); outtextxy(0,30,"press 'space' for shooting,'Esc' to quit."); } /*倒计时*/ ksyx() { sleep(2); cleardevice(); settextstyle(0,0,31); setcolor(13); outtextxy(225,100,"5"); sleep(1); cleardevice(); setcolor(14); outtextxy(225,100,"4"); sleep(1); cleardevice(); setcolor(2); outtextxy(225,100,"3"); sleep(1); cleardevice(); setcolor(10); outtextxy(225,100,"2"); sleep(1); cleardevice(); setcolor(14); outtextxy(225,100,"1"); sleep(1); cleardevice(); setcolor(10); settextstyle(0,0,6); outtextxy(50,200,"Let's play!!"); sleep(1); } /*开机动画*/ kjdh() { setbkcolor(1); cleardevice(); setcolor(13); settextstyle(1,0,4); for(i=1;i<230;i++) { delay(2000); cleardevice(); outtextxy(i,200,"software"); outtextxy(450-i,260,"Excellent!!"); } settextstyle(4,0,10); setcolor(14); outtextxy(225,50,"041"); setcolor(4); settextstyle(1,0,8); outtextxy(60,300,"We are heros"); sleep(1); settextstyle(0,0,6); for(i=320;i>1;i--) { delay(600); setcolor(10); line(i,1,i,479); line(639-i,1,639-i,479); setcolor(1); outtextxy(60,260,"Best shooter"); } hq(); hd2(); cleardevice(); setbkcolor(0); setcolor(14); ellipse(320,240,0,360,300,150); sleep(1); setcolor(2); setlinestyle(0,0,3); circle(320,240,150); sleep(1); settextstyle(1,0,4); setcolor(4); outtextxy(80,230,"Hebei University of Technology"); hd(); ys(); qp(); sleep(1); cleardevice(); setbkcolor(1); settextstyle(0,0,4); outtextxy(10,260,"Welcome to our game"); settextstyle(0,0,6); setcolor(11); outtextxy(150,330,"World!!"); hq(); } /*随机画点*/ hd2() { long int i,x,z,y ; for(i=0;i<600000;i++) { x=random(640); y=random(480); z=random(16); putpixel(x,y,z); } } /*画旗*/ hq() { int i ; setlinestyle(0,0,3); setcolor(14); line(180,30,100,230); setcolor(4); line(180,30,500,30); line(183,30,123,180); line(120,180,440,180); line(500,30,440,180); setfillstyle(9,4); floodfill(200,40,4); for(i=0;i<307;i++) { settextstyle(0,0,4); setcolor(i+12); outtextxy(200,50,"Software"); setcolor(i); settextstyle(4,0,6); outtextxy(240,110,"0 4 1"); } } /*礼花*/ lh() { int x,y,i,n=0 ; setcolor(14); while(n<=6) { setlinestyle(0,0,3); x=random(640); y=random(100); for(i=480;i>y;i--) { setcolor(0); line(x,i+1,x,i-4); setcolor(14); line(x,i,x,i-5); delay(50); } for(i=1;i<90;i++) { setcolor(i); circle(x,y,i); delay(2000); setcolor(0); circle(x,y,i); } n++; } } /*目标小旗*/ mbxq(int x,int y) { setlinestyle(0,0,1); setcolor(4); moveto(x,y); lineto(x,y-20); lineto(x+10,y-20); lineto(x,y-10); } /*地图1*/ map1() { setlinestyle(0,0,3); setbkcolor(0); setcolor(2); moveto(50,480); lineto(200,400); lineto(250,400); lineto(300,450); lineto(580,200); lineto(640,200); setcolor(3); rectangle(210,370,240,400); rectangle(610,170,640,200); mbxq(225,370); mbxq(625,170); } map2() { setlinestyle(0,0,3); setbkcolor(0); setcolor(2); moveto(50,480); lineto(200,400); lineto(300,150); lineto(350,100); lineto(400,100); lineto(450,450); lineto(580,200); lineto(640,200); setcolor(3); rectangle(360,70,390,100); rectangle(610,170,640,200); mbxq(375,70); mbxq(625,170); } map3() { setlinestyle(0,0,3); setbkcolor(0); setcolor(2); moveto(50,480); lineto(100,400); lineto(200,360); lineto(300,150); lineto(400,400); lineto(450,450); lineto(550,400); lineto(640,400); setcolor(3); rectangle(580,370,610,400); mbxq(595,370); } map4() { setlinestyle(0,0,3); setbkcolor(0); setcolor(2); moveto(50,480); lineto(100,200); lineto(200,360); lineto(300,150); lineto(450,450); lineto(600,400); lineto(640,400); setcolor(3); rectangle(600,370,640,400); mbxq(620,370); } map5() { setlinestyle(0,0,3); setbkcolor(0); setcolor(2); line(200,30,225,110); line(200,30,175,110); line(225,110,265,125); line(265,125,225,130); line(225,130,200,210); line(200,210,175,138); line(175,138,135,125); line(135,125,175,110); setfillstyle(11,2); floodfill(200,200,2); moveto(50,480); lineto(200,400); lineto(300,250); lineto(400,170); lineto(420,250); lineto(470,250); lineto(580,120); lineto(640,120); setcolor(3); rectangle(440,220,470,250); rectangle(600,90,640,120); mbxq(620,90); mbxq(455,220); } map6() { /*折线点坐标*/ int xy[6][2]= { { 50,480 } , { 120,400 } , { 220,250 } , { 320,120 } , { 430,180 } , { 640,150 } } ; setbkcolor(0); setcolor(3); rectangle(625,135,640,150); mbxq(630,135); /*射击目标*/ setcolor(2); setlinestyle(0,0,3); drawpoly(6,xy); /*折线连接*/ } /*结束动画*/ jsdh() { int i ; cleardevice(); for(i=0;i<107;i++) { setcolor(i); settextstyle(0,0,6); outtextxy(40,110,"All missions"); outtextxy(80,200,"Completed!"); } } /*力度条*/ ld() { int n=1 ; setlinestyle(0,0,3); for(a=1;a<=100;a++) { rectangle(151,470,251,480); line(150+a,470,150+a,480); delay(20000000); if(a>99) { setcolor(n); n++; a=1 ; } /*如果击键*/ if(kbhit()!=0) { setcolor(3); setfillstyle(1,3); rectangle(151,470,251,480); floodfill(200,475,3); break ; } } } /*角度设置*/ hjd() { setlinestyle(0,0,3); while(1) { x=30*cos(jd/57.3); y=480-30*sin(jd/57.3); z=490-30*sin(jd/57.3); setcolor(10); line(0,470,x,y); line(0,500,x+20,z); line(x,y,x+20,z); b=getch(); if(b=='w'&&jd<=89) { setcolor(0); /*准备清屏*/ line(0,470,x,y); line(0,500,x+20,z); line(x,y,x+20,z); jd=jd+1 ; /*清三条线后角度加1*/ } if(b=='s'&&jd>=1) { setcolor(0); line(0,470,x,y); line(0,500,x+20,z); line(x,y,x+20,z); jd=jd-1 ; } if(b==32) break ; /*如果摁空格(ASCII码32)*/ if(b==27) exit(0); /*Esc*/ } } /*炮弹爆炸*/ bz() { setcolor(4); circle(x,y,10); setfillstyle(1,4); floodfill(x,y,4); setcolor(0); for(n=10;n>0;n--) { circle(x,y,n); delay(5000000); } setcolor(4); circle(x,y,10); setfillstyle(1,4); floodfill(x-2,y,4); setcolor(0); for(n=1;n<11;n++) { circle(x,y,n); delay(5000000); } } /*主函数*/ main() { graph(); /*图形初始化*/ kjdh(); /*开机动画*/ ksyx(); /*倒计时*/ q : t=0 ; setlinestyle(0,0,3); cleardevice(); sm(); /*游戏说明*/ /*地图调用*/ switch(gk) { case 1 : map1(); break ; case 2 : map2(); break ; case 3 : map3(); break ; case 4 : map4(); break ; case 5 : map5(); break ; case 6 : map6(); break ; case 7 : jsdh(); getch(); exit(0); /*结束动画*/ } hjd(); /*角度*/ ld(); /*力度*/ vx=8*a*cos(jd/57.3); vy=8*a*sin(jd/57.3); while(1) { x=30+vx*t ; y=470-vy*t+180*t*t ; if(y<-10)y=-10 ; /*炮弹运动轨迹*/ /*如果撞击或打中目标的反应情况*/ for(i=0;i<=6.28;i=i+0.1) { x1=x+5*cos(i); y1=y+5*sin(i); if(getpixel(x1,y1)==3) { bz(); settextstyle(1,0,3); setcolor(14); outtextxy(0,50,"you are win,congratulations!!!"); lh(); /*礼花*/ getch(); gk++; /*关卡*/ goto q ; } } /*如果撞击山峰的反应情况*/ for(i=0;i<=6.28;i=i+0.1) { x1=x+5*cos(i); y1=y+5*sin(i); /*如果指定坐标颜色为2(绿)*/ if(getpixel(x1,y1)==2) { bz(); settextstyle(1,0,3); setcolor(10); outtextxy(0,50,"you are failed,please try again"); getch(); getch(); goto q ; } } /*如果超出屏幕退出*/ if(x>640||y>480) { setcolor(10); settextstyle(1,0,3); outtextxy(0,50,"you are failed,please try again"); getch(); getch(); goto q ; } setcolor(4); setfillstyle(1,4); circle(x,y,5); floodfill(x,y,4); t=t+0.01 ; delay(3000); setcolor(0); circle(x,y,5); setfillstyle(1,0); floodfill(x,y,0); } }
本文档为【c语言小游戏】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_833902
暂无简介~
格式:doc
大小:44KB
软件:Word
页数:25
分类:互联网
上传时间:2017-10-10
浏览量:30