打砖块游戏.docx_第1页
打砖块游戏.docx_第2页
打砖块游戏.docx_第3页
打砖块游戏.docx_第4页
打砖块游戏.docx_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/*=ProgramDescription=*/*程序名称:game.c */ /*程序目的:打砖块游戏演示 */ /*=*/#include graphics.h#include stdio.h#include conio.h /*所需的头文件*/int on; /*声明具有开关作用的全局变量*/static int score; /*声明静态的记分器变量*/* 定义开始界面函数*/int open() setviewport(100,100,500,380,1); /*设置图形窗口区域*/ setcolor(4); /*设置作图色*/ rectangle(0,0,399,279); /*以矩形填充所设的图形窗口区域*/ setfillstyle(SOLID_FILL,7); /*设置填充方式*/ floodfill(50,50,4); /*设置填充范围*/ setcolor(8); settextstyle(0,0,9); /*文本字体设置*/ outtextxy(90,80,BALL); /*输出文本内容*/ settextstyle(0,0,1); outtextxy(110,180,version 1.0); outtextxy(110,190,made by ddt); setcolor(128); settextstyle(0,0,1); outtextxy(120,240,Press any key to continue.);/*定义退出界面函数*/int quitwindow() char s100; /*声明用于存放字符串的数组*/ setviewport(100,150,540,420,1); setcolor(YELLOW); rectangle(0,0,439,279); setfillstyle(SOLID_FILL,7); floodfill(50,50,14); setcolor(12); settextstyle(0,0,8); outtextxy(120,80,End); settextstyle(0,0,2); outtextxy(120,200,quit? Y/N); sprintf(s,Your score is:%d,score);/*格式化输出记分器的值*/ outtextxy(120,180,s); on=1; /*初始化开关变量*/*主函数*/main() int gdriver,gmode; gdriver=DETECT; /*设置图形适配器*/ gmode=VGA; /*设置图形模式*/ registerbgidriver(EGAVGA_driver); /*建立独立图形运行程序*/ initgraph(&gdriver,&gmode,); /*图形系统初试化*/ setbkcolor(14); open(); /*调用开始界面函数*/ getch(); /*暂停*/while(1) /*此大循环体控制游戏的反复重新进行*/ int driver,mode,l=320,t=400,r,a,b,dl=5,n,x=200,y=400,r1=10,dx=-2,dy=-2;/*初始化小球相关参数*/ int left100,top100,right100,bottom100,i,j,k,off=1,m,num100100;/*方砖阵列相关*/ static int pp; static int phrase; /*一系列起开关作用的变量*/ int oop=15; pp=1; score=0; driver=DETECT; mode=VGA; registerbgidriver(EGAVGA_driver); initgraph(&driver,&mode,); setbkcolor(10); cleardevice(); /*图形状态下清屏*/ clearviewport(); /*清除现行图形窗口内容*/ b=t+6; r=l+60; setcolor(1); rectangle(0,0,639,479); setcolor(4); rectangle(l,t,r,b); setfillstyle(SOLID_FILL,1); floodfill(l+2,t+2,4); for(i=0,k=0;i=6;i+) /*此循环绘制方砖阵列*/ topi=k; bottomi=topi+20; k=k+21; oop-; for(j=0,m=0;jr|x+r1r) phrase=0; if(x-r1=r|x+r1=l) if(y=t&phrase=1) dy=-dy;y=t-1-r1; if(off=0) continue; for(i=0;i=6;i+) /*此循环用于判断、控制方砖阵列的撞击、擦除*/ for(j=0;j=7;j+) if(x+r1=leftj)|(x-r1=leftj) if( y-r1topi&y-r1=topi&y+r1=topi&y+r1=topi&y-r1=leftj&x+r1rightj)|(x-r1leftj) if(numij=0) continue; setcolor(10); rectangle(leftj,topi,rightj,bottomi); setfillstyle(SOLID_FILL,10); floodfill(leftj+1,topi+1,10); dx=-dx; numij=0; score=score+10; printf(%dbbb,score); if(x+r1639) /*控制小球的弹射范围*/ dx=-dx;x=638-r1; if(x=479) off=0;quitwindow();break; if(y=r1) dy=-dy;y=r1+1; if(score=560) off=0;quitwindow();break; setcolor(6); circle(x,y,r1); setfillstyle(SOLID_FILL,14); floodfill(x,y,6); delay(1000); setcolor(10); circle(x,y,r1); setfillstyle(SOLID_FILL,10); floodfill(x,y,10); a=getch(); setcolor(10); rectangle(l,t,r,b); setfillstyle(SOLID_FILL,10); floodfill(l+2,t+2,10); if(a=77&l=15) dl=-20;l=l+dl; if(a=y&on=1) break; if(a=n&on=1) break; if(a=27) quitwindow();off=0; r=l+60; setcolor(4);

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论