俄罗斯方块C程序(1).doc_第1页
俄罗斯方块C程序(1).doc_第2页
俄罗斯方块C程序(1).doc_第3页
俄罗斯方块C程序(1).doc_第4页
俄罗斯方块C程序(1).doc_第5页
已阅读5页,还剩24页未读 继续免费阅读

下载本文档

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

文档简介

最简单,最基本的俄罗斯方块C程序悬赏分:20 - 解决时间:2007-12-31 13:04 最好能帮我加一点注释,谢谢了 提问者: xiaobaiooo - 二级最佳答案这有http:/iiii.imbbs.in/ 0回答者: ceoceoimceo - 三级 2007-12-12 19:39 我来评论 相关内容 求个最简单的VC+俄罗斯方块程序代码52009-9-12 c语言 编写俄罗斯方块的程序 要求有详细的中文注释182009-5-15 怎样用C程序编写俄罗斯方块啊12008-6-14 c语言难吗?我想知道学完可以编什么样的程序?俄罗斯方块?/2006-4-2 有哪位C语言高手能解决我的一个难题:如何编一程序“五子棋”或“俄罗斯方块”2007-4-1更多关于俄罗斯方块C程序的问题查看同主题问题: 俄罗斯方块 程序 等待您来回答 最佳拍档怎么破解 Super Junior100214 MBC Star Dance Battle的小提琴伴奏 国外杂志发表文章所在刊物的封面目录怎么找? 建功国际旅游 争做文明大学生 演讲稿 英语专业 过了司法考试和注册会计师 适合做什么? super junior四辑的全部歌曲的链接 阿部美幸的super lovers单行本出到哪里了 关于super junior四辑地问题。 其他回答共 3 条*/面向对象课程设计:俄罗斯方块游戏修改版 制作人: 李梦松 时间:2007-5 单位: 湖工工程技术学院 工学系 软件(一)班 */#include #include #include #include #include #include #include /常数定义区 #define UNIT 28 #define ROWS 16 #define COLUMNS 12 /枚举定义区 enum Booleanfalse,true; /全局变量 int speed=9; int hard=9; int numrow=0; Boolean candown; Boolean over; /对象定义区 /Location对象:Location是所有图形的基类 class Location protected: int unit; /所有图形的基本单位长度。 public: int x,y; /在容器中的逻辑坐标 int left,top; /在屏幕中的物理坐标 int color; Location(int x,int y,int left,int top,int unit,int color); ; Location:Location(int x,int y,int left,int top,int unit,int color) this-x=x; this-y=y; this-left=left; this-top=top; this-unit=unit; this-color=color; /Brick对象:Brick是一个长方形的图形对象,由它可以组成俄罗斯方块所需要的各种形状。 class Brick:public Location public: Brick(int x,int y,int left,int top,int unit,int color); void show(); void hide(); ; Brick:Brick(int x,int y,int left,int top,int unit,int color):Location(x,y,left,top,unit,color) ; void Brick:show() /显示Brick int tempColor; tempColor=getcolor(); setfillstyle(1,color); bar(left+1,top+1,left+unit-1,top+unit-1); setfillstyle(0,color); setcolor(tempColor); void Brick:hide() /隐藏Brick int tempColor; tempColor=getcolor(); setfillstyle(1,getbkcolor(); bar(left+1,top+1,left+unit-1,top+unit-1); setfillstyle(0,getbkcolor(); setcolor(tempColor); /Figure对象:在Figure中有一个n*n的矩阵,在相应的位置上放置Brick对象就可以形成组合图形。 /每一种Figure图形由4个Brick对象组成。 class Figure:public Location protected: int shape;/shape取值06,分别代表7种不同的图形。 public: int state;/state共有0,1,2,3四个值,分别表示图形的四种摆放角度。 int map442;/map的下标依次表示:4个状态(state),4个Brick,x和y坐标 Brick *p_bk4; /表示组成Figure的4个Brick Figure(int x,int y,int left,int top,int unit,int color,int shape,int state); Figure(); void setBricks(); void show(); void hide(); ; Figure:Figure(int x,int y,int left,int top,int unit,int color,int shape,int state):Location(x,y,left,top,unit,color) this-shape=shape; this-state=state; /要想增加更多图形,只需扩充Brick的数目和相应的map的矩阵值。 if(this-shape=0) /长条形 map000=0;map001=1; map010=1;map011=1; map020=2;map021=1; map030=3;map031=1; map100=1;map101=0; map110=1;map111=1; map120=1;map121=2; map130=1;map131=3; map200=0;map201=1; map210=1;map211=1; map220=2;map221=1; map230=3;map231=1; map300=1;map301=0; map310=1;map311=1; map320=1;map321=2; map330=1;map331=3; else if(shape=1) /正方形. map000=0;map001=0; map010=1;map011=0; map020=0;map021=1; map030=1;map031=1; map100=0;map101=0; map110=1;map111=0; map120=0;map121=1; map130=1;map131=1; map200=0;map201=0; map210=1;map211=0; map220=0;map221=1; map230=1;map231=1; map300=0;map301=0; map310=1;map311=0; map320=0;map321=1; map330=1;map331=1; else if(shape=2) /T字形. map000=0;map001=1; map010=1;map011=1; map020=2;map021=1; map030=1;map031=2; map100=1;map101=0; map110=0;map111=1; map120=1;map121=1; map130=1;map131=2; map200=1;map201=0; map210=0;map211=1; map220=1;map221=1; map230=2;map231=1; map300=1;map301=0; map310=1;map311=1; map320=2;map321=1; map330=1;map331=2; else if(shape=3) /正Z形. map000=0;map001=0; map010=1;map011=0; map020=1;map021=1; map030=2;map031=1; map100=1;map101=0; map110=0;map111=1; map120=1;map121=1; map130=0;map131=2; map200=0;map201=0; map210=1;map211=0; map220=1;map221=1; map230=2;map231=1; map300=1;map301=0; map310=0;map311=1; map320=1;map321=1; map330=0;map331=2; else if(shape=4) /反Z形. map000=1;map001=0; map010=2;map011=0; map020=0;map021=1; map030=1;map031=1; map100=0;map101=0; map110=0;map111=1; map120=1;map121=1; map130=1;map131=2; map200=1;map201=0; map210=2;map211=0; map220=0;map221=1; map230=1;map231=1; map300=0;map301=0; map310=0;map311=1; map320=1;map321=1; map330=1;map331=2; else if(shape=5) /正L形. map000=1;map001=0; map010=1;map011=1; map020=1;map021=2; map030=2;map031=2; map100=0;map101=1; map110=1;map111=1; map120=2;map121=1; map130=0;map131=2; map200=0;map201=0; map210=1;map211=0; map220=1;map221=1; map230=1;map231=2; map300=2;map301=0; map310=0;map311=1; map320=1;map321=1; map330=2;map331=1; else if(shape=6) /反L形. map000=1;map001=0; map010=1;map011=1; map020=0;map021=2; map030=1;map031=2; map100=0;map101=0; map110=0;map111=1; map120=1;map121=1; map130=2;map131=1; map200=1;map201=0; map210=2;map211=0; map220=1;map221=1; map230=1;map231=2; map300=0;map301=1; map310=1;map311=1; map320=2;map321=1; map330=2;map331=2; int bk_x,bk_y,bk_left,bk_top; for(int i=0;i4;i+) bk_x=mapstatei0; bk_y=mapstatei1; bk_left=left+bk_x*unit; bk_top=top+bk_y*unit; p_bki=new Brick(bk_x,bk_y,bk_left,bk_top,unit,color); Figure:Figure() delete(p_bk0); delete(p_bk1); delete(p_bk2); delete(p_bk3); void Figure:setBricks()/设置Brick的位置 int i; for(i=0;ix=mapstatei0; p_bki-y=mapstatei1; p_bki-left=left+(p_bki-x)*unit; p_bki-top=top+(p_bki-y)*unit; void Figure:show() /显示Figure for(int i=0;itophide(); /如果超过容器顶部则把Brick隐藏 else p_bki-show(); void Figure:hide()/隐藏Figure for(int i=0;ihide(); /GameBox对象:GameBox所有组合图形的容器 class GameBox:public Location protected: int rows; int columns; int flag5050; int colors5050; public: Figure * p_fg; GameBox(int x,int y,int left,int top,int unit,int color,int rows,int columns); GameBox(); void setFigure(int x,int y,int color,int shape,int state); void show(); void hardBrick(); /以下的几个函数我曾经放到Figure里定义,但发现在这里定义更合理更简单。 Boolean canLeft(); void moveLeft(); Boolean canRight(); void moveRight(); void canDown(); void moveDown(); Boolean canRotate(); void rotate(); void delFigure(); void Over() ; void hideRow(int rowNum); void showRow(int rowNum); void downRow(int rowNum); void fresh(); void clear(); ; GameBox:GameBox(int x,int y,int left,int top,int unit,int color,int rows,int columns):Location(x,y,left,top,unit,color) this-rows=rows; this-columns=columns; p_fg=NULL; int i,j; for(i=0;irows;i+) for(j=0;jsetBricks(); void GameBox:show()/显示一个GameBox int tempColor; tempColor=getcolor(); setcolor(color); rectangle(left-1,top-1,left+columns*unit+1,top+rows*unit+1); setcolor(tempColor); if(p_fg!=NULL) p_fg-show(); Boolean GameBox:canLeft() int i; Boolean can=true; int gb_x,gb_y; for(i=0;ix+p_fg-p_bki-x-1; gb_y=p_fg-y+p_fg-p_bki-y; if(gb_x0) can=false; break; return(can); void GameBox:moveLeft() p_fg-hide(); p_fg-x=p_fg-x-1; p_fg-left=p_fg-left-unit; p_fg-setBricks(); p_fg-show(); Boolean GameBox:canRight() int i; Boolean can=true; int gb_x,gb_y; for(i=0;ix+p_fg-p_bki-x+1; gb_y=p_fg-y+p_fg-p_bki-y; if(gb_xcolumns-1) can=false; break; else if(flaggb_xgb_y0) can=false; break; return(can); void GameBox:moveRight() p_fg-hide(); p_fg-x=p_fg-x+1; p_fg-left=p_fg-left+unit; p_fg-setBricks(); p_fg-show(); void GameBox:canDown() int i; int gb_x,gb_y; for(i=0;ix+p_fg-p_bki-x; gb_y=p_fg-y+p_fg-p_bki-y+1; if(gb_yrows-1) candown=false; break; else if(flaggb_xgb_y0) candown=false; break; else candown=true; void GameBox:moveDown() /下落采用的是隐藏(hide)当前位置的Figure,在下方显示(show)同样的Figure p_fg-hide(); p_fg-y=p_fg-y+1; p_fg-top=p_fg-top+unit; p_fg-setBricks(); p_fg-show(); Boolean GameBox:canRotate() int i; Boolean can=true; int gb_x,gb_y; int nextState; nextState=(p_fg-state+1)%4; for(i=0;imapnextStatei0+p_fg-x; gb_y=p_fg-mapnextStatei1+p_fg-y; if(gb_xcolumns-1|gb_yrows-1) can=false; break; else if(flaggb_xgb_y0) can=false; break; return(can); void GameBox:rotate()/变形 p_fg-hide(); p_fg-state=(p_fg-state+1)%4; p_fg-setBricks(); p_fg-show(); void GameBox:delFigure() /Figure落下时,释放对该Figure的控制 int gb_l,gb_t; int i,gb_x,gb_y; for(i=0;ix+p_fg-p_bki-x; gb_y=p_fg-y+p_fg-p_bki-y; flaggb_xgb_y=1; colorsgb_xgb_y=p_fg-color; delete(p_fg); p_fg=NULL; /*难度设计(pretty lee)*/ void GameBox:clear() /清屏 for(int k=0;krows;k+) hideRow(k); void GameBox:hardBrick()/难度函数 int tempColor,color; clear(); tempColor=getcolor(); for (int i=1;i=9-hard;i+) for (int j=1;j=columns-6;j+) int n=random(12); color=random(15)+1; flagnROWS-i=1; colorsnROWS-i=color; setfillstyle(1,color); bar(left+n*unit+1,top+(rows-i)*unit,left+(n+1)*unit-1,top+(rows-i+1)*unit-2); setfillstyle(0,color); setcolor(tempColor); /*/ void GameBox:hideRow(int rowNum) int tempColor; tempColor=getcolor(); for(int i=0;i0) setfillstyle(1,getbkcolor(); bar(left+i*unit+1,top+rowNum*unit,left+(i+1)*unit-1,top+(rowNum+1)*unit-2); flagirowNum=0; colorsirowNum=0; setfillstyle(0,getbkcolor(); setcolor(tempColor); void GameBox:showRow(int rowNum) int tempColor; tempColor=getcolor(); for(int i=0;i0) setfillstyle(1,colorsirowNum); bar(left+i*unit+1,top+rowNum*unit,left+(i+1)*unit-1,top+(rowNum+1)*unit-2); setfillstyle(0,colorsirowNum); setcolor(tempColor); void GameBox:downRow(int rowNum) for(int i=0;i0;i-) do flagSum=0; for(j=0;j=columns) /如果一排满了则消行 for(k=i;k0;k-) hideRow(k); downRow(k-1); ni+; numrow+=ni; /计算得分 if (numrow-ni)%100numrow%100) /当numrow+ni后,如果没满100,那么必有(numrow-ni)%100numrow%100 if (speed=1) if (hard=columns); void GameBox:Over() int j ; int i,gb_x,gb_y; for(i=0;ix+p_fg-p_bki-x; gb_y=p_fg-y+p_fg-p_bki-y; flaggb_xgb_y=1; colorsgb_xgb_y=p_fg-color; for(j=0;j0 & flagj00 & candown=false) over=true; break; else over=false; int getKey() /系统自带函数bioskey(0)能达到几乎相同的功能 union REGS inReg,outReg; int key_l; inReg.h.ah = 0; int86(22, &inReg, &outReg); key_l=outReg.h.ah; return(key_l); /函数指针,用来保存原来时间中断函数的句柄。 void interrupt far (*OldIntHandler)(.); /新的时间中断函数,最多1秒18次。 int ticker=0; int timeCyc=speed; Boolean ; void far interrupt TimeInt(.) /如何让中断程序带参数? ticker=(ticker+1)%timeCyc; if(ticker=0 & onTime=false) ; 回答者: 不爱到爱 - 四级 2007-12-14 20:01 void main() /*欢迎界面(pretty lee)*/ char p1,p2; int pp1,pp2; candown=true; over=false; textbackground(WHITE); gotoxy(30,8); textbackground(BLUE); /将标题移到标题位置,然后输出标题 cprintf(Welcome to the GAME WORLDrn); gotoxy(40,12); textbackground(BLACK); textcolor(WHITE); cprintf(the speed isrn); gotoxy(53,12); textcolor(BLACK); textbackground(WHITE); cprintf(%drn,10-speed); gotoxy(40,15); textbackground(BLACK); textcolor(WHITE); cprintf(the hard isrn); gotoxy(53,15); textbackground(BLACK); textcolor(WHITE); cprintf(%drn,10-hard); gotoxy(51,20); textbackground(BLACK); textcolor(WHITE); cprintf(producer is pretty leern); /*调节速度*/ re1: gotoxy(53,12); textcolor(BLACK); textbackground(WHITE); p1=getch(); pp1=p1; if (p1=H & speed1) speed=speed-1; cprintf(%drn,10-speed); goto re1; else if(pp1!=13) goto re1; else textbackground(BLACK); textcolor(WHITE); cprintf(%drn,10-speed); /*/ /*调节难度*/ re2: gotoxy(53,15);/获得光标时背景变白色 textcolor(BLACK); textbackground(WHITE); cprintf(%drn,10-hard); gotoxy(53,15);/重新定输出位置 p2=getch(); pp2=p2; if (p2=H & hard1) hard=hard-1; cprintf(%drn,10-hard); goto re2; else if(pp2!=13) goto re2; /*/ /*/ int graphdriver = DETECT,graphmode; /初始化图形系统 initgraph(&graphdriver,&graphmode,d:tc3bgi); int key,nextnum1,nextnum2,nextnum3; srand(unsigned)time(NULL); timeCyc=speed; OldIntHandler=getvect(0x1c); disable(); setvect(0x1c,TimeInt); /中断矢量入口,相当如TIMER控件 enable(

温馨提示

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

评论

0/150

提交评论