1、c语言数据结构程序设计俄罗斯方块解读课程论文(设计)课程名称 数据结构课程设计指导老师 所在学院 专业年级 提交日期 成 绩 小组成员表姓名学号承担任务俄罗斯方块的基本算法实现系统调试游戏场景的规划与实现游戏得分算法分析、游戏后期测试 开场动画制作ppt游戏结束条件判断游戏得分算法分析、游戏后期测试开场动画制作ppt课程设计实验起止日期:2012-2013学年 第二学期系别班级学号姓名实 验 题 目设计性 口综合性俄罗斯方块小游戏在本次课程设计中,我负责编写游戏的界面和场景。这是很重要的工作,直接关系到玩家的游戏体验和对游戏的评价。所以我充分发挥想象力和创造 力在场景位置安排上下了一番苦工,
2、也和组内成员进行过多次的探讨,最终自写出了一个具有美感的游戏场景,力求让用户在游戏中体验到给多的快感。我更重要的是在此次程序设计中与组员在游戏框架上的讨论中学到了很多新评知识,对数据结构的理解也在实践中得到了提高。价能够实现实验要求的功能全部 部分算法有新意有一般程序运行通过全部 部分教 师 评 语算法注释说明完善仅有功能说明接口参数说明有无按期上交打印文档资料及源程序所有部分综合设计说明报告结构合理 不合理用户使用说明完整 不全现场演示操作有准备有无问题解答流畅流畅 不流畅独立完成实验能不能体现团队合作精神。能够 不能成绩、需求分析我们对俄罗斯方块这个游戏一点也不陌生, 知道游戏的玩法和实现
3、后,我们很快就着手开干。游戏要有出现场景、方块、消除方块得分、判断游戏结束等几个大功能。结构清晰简 洁便于分工。二、 算法原理介绍游戏主要使用了数组这个数据结构。 不过与以往的程序不同, 这个游戏有一个大数组包含很多个小数组,大数组不断的吸收小数组内的元素,达到条件得分。三、 概要设计1、功能块各函数列表-鏗I game classes 軌-_j Globalsgameoverf)gotoxyint 比 int yJudgelnOmain|.next boxflrollD_scoreO.showm方p& box3 box_ next step2boxtype flagsW gamespeed3
4、gamespeedl keyy key1“ map3 map_xp map_yw maCxMAX,2 nextboxVJh r * ClassView 冒 FileView 2、场景的设置 int map2817=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,-1,-1,-1,-1,-1,-1,-1,-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if(j=1|j=2|j=15|j=16)printf(丨);else if(i=26|i=27)pri ntf( );else if(mapij=1) printf( ); else if(mapij=0) printf( );3、其余功能的实现(如方块的出现 下落 旋转 得分计算 游戏结束条件判断等)(1)旋转 void roll() int i,j;p_xn ext=p_x;p_yn ext=p_y;for(i=0;i5;i+) for(j=0;j5;i-) for(j=3;j15;j+) if(mapij=1) flags=1; else flags=0; break;if(fla
9、gs=1) pointrank+; for(j=3;j5;k-) mapkj=mapk-1j; i+; switch(pointrank)case 1: scores=scores+10;break;case 2: scores=scores+25;break;case 3: scores=scores+40;break;case 4: scores=scores+60;break;default: scores=scores+0; gotoxy(40,15);printf(Your Score:%d,scores); pointrank=0;showmap();Sleep(300);3)游戏
10、结束判断 int gameover()int i;for(i=3;i15;i+) if(map5i=1) return 1;return 0;四、测试分析1、游戏开始界面 2、游戏进行中,操作键为键盘数字 2、4、6、8,其中 2为加速下落, 4为左移,6 为右移, 8 为旋转。3、游戏介绍,按任意键退出游戏。游戏结束条件:当方块高度到达顶部时,游戏自动停止,并提示 Game Over。总结: 需求分析方面: 我们对俄罗斯方块这个游戏一点也不陌生,知道游戏的玩法和实现 后,我们很快就着手开干。游戏要有出现场景方块消除方块得分判 断游戏结束 等几个大功能。结构清晰简洁便于分工。问题:设计过程中遇
11、到了些许难题, 那就是如何才能可以在屏幕上指定位置 显示内容。一开始发现很困难,不过在和组员讨论过后,我们发现 gotoxy ()函数,十分简单的就解决了这个难题。数据结构:游戏主要使用了数组这个数据结构。 不过与以往的程序不同, 这个游 戏有一个大数组包含很多个小数组, 大数组不断的吸收小数组内的元 素,达到条件得分。代码#include#include#include#include#include#define MAX_BOX 7intp_x=5,p_y=1,map_x=1,map_y=1,p_xnext=5,p_ynext=1,scores=0,key1=0,flags=0,games
12、peed=200,gamespeed1=20 0,pointrank=0;int MAX_X=17,MAX_Y=28;char key; int box55=0;int box_next_step55=0;int nextbox55=0;int boxtypeMAX_BOX55= 0,0,0,0,0,0,0,1,0,0,0,0,1,0,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0,0,0,0,
16、0,0,0,0,0,1,1, 0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 0,1,1
17、,1,1,1,1,1,1,1,1,1,1,1,1,1,1 ;extern void showlogo();void gotoxy(int x,int y)/gotoxy 在 TC 中是在 system.h 库文件里的一个函COORD c;c.X=x-1; c.Y=y-1;SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c); void showmap()int i,j;for(i=5;i28;i+)for(j=1;j17;j+)gotoxy(2*j,i);if(j=1|j=2|j=15|j=16)printf(丨);else
18、 if(i=26|i=27)printf(” );else if(mapij=1) printf( );else if(mapij=0) printf( );void next_box()int type,i,j;srand(time(NULL);type=rand()%6;for(i=0;i5;i+)for(j=0;j5;j+)nextboxij=boxtypetypeij;gotoxy(40,6);printf(Next:);gotoxy(40,7);for(i=0;i5;i+)for(j=0;j5;j+)gotoxy(40+2*j,7+i);if(nextboxij=1) printf(
19、 ); else printf( );int judgein()int i,j;for(i=0;i5;i+)for(j=0;j5;j+)if(box_next_stepij=1)if(mapp_ynext+ip_xnext+j=1) return 0;return 1;int gameover()int i;for(i=3;i15;i+)if(map5i=1)return 1;return 0;void roll()p_xnext=p_x;p_ynext=p_y;int i,j;for(i=0;i5;i+)for(j=0;j5;i-)for(j=3;j15;j+)if(mapij=1) fla
20、gs=1; else flags=0;break;if(flags=1)pointrank+;for(j=3;j5;k-)mapkj=mapk-1j;i+;switch(pointrank)case 1:scores=scores+10;break;case 2:scores=scores+25;break;case 3:scores=scores+40;break;case 4:scores=scores+60;break;default:scores=scores+0; gotoxy(40,15);printf(Your Score:%d,scores); pointrank=0;show
21、map();Sleep(300);void main()showlogo(); gotoxy(50,20);printf(w 转向 s 加速下降 ); gotoxy(50,21);printf(a 左 d 右 );int type,flag1=1,i,j,flag=0,flag2=1; showmap();next_box();Sleep(1000); srand(time(NULL); type=rand()%6;for(i=0;i5;i+)for(j=0;j5;j+)boxij=boxtypetypeij;for(i=0;i5;i+)for(j=0;j5;j+)gotoxy(2*p_x+2
22、*j,p_y+i); if(boxij=1&mapp_y+ip_x+j=0) printf( ); gotoxy(40,15); printf(Your Score:0); Sleep(gamespeed);Here:while(1)if(!kbhit()for(i=0;i5;i+)for(j=0;j5;j+)box_next_stepij=boxij;p_xnext=p_x;p_ynext=p_y+1;flag1=judgein();if(flag1=0)for(i=0;i5;i+)for(j=0;j5;j+)gotoxy(2*p_x+2*j,p_y+i);if(boxij=1&mapp_y
23、+ip_x+j=0) printf( );for(i=0;i5;i+)for(j=0;j5;j+)if(boxij=1)mapp_y+ip_x+j=1;flag=gameover();if(flag!=0)gotoxy(10,10);printf( );gotoxy(10,12);printf( );gotoxy(10,11); printf( Game Over ); gotoxy(40,20);break;/ 应该修改!elsescore();p_x=5;p_y=1;for(i=0;i5;i+)for(j=0;j5;j+)boxij=nextboxij;next_box();Sleep(3
24、00);elsefor(i=0;i5;i+)for(j=0;j5;j+)gotoxy(2*p_x+2*j,p_y+i); if(boxij=1&mapp_y+ip_x+j=0) printf( );p_y+;for(i=0;i5;i+)for(j=0;j5;j+)gotoxy(2*p_x+2*j,p_y+i);if(boxij=1&mapp_y+ip_x+j=0)printf( );Sleep(gamespeed); gamespeed=gamespeed1;goto Here;else key=getch();switch(key)casew:caseW:roll();flag2=judge
25、in();if(flag2=1) for(i=0;i5;i+) for(j=0;j5;j+) gotoxy(2*p_x+2*j,p_y+i);if(boxij=1&mapp_y+ip_x+j=0) printf( );for(i=0;i5;i+)for(j=0;j5;j+) boxij=box_next_stepij;goto Here;casea:caseA:p_xnext=p_x-1;p_ynext=p_y;flag2=judgein();if(flag2=1) for(i=0;i5;i+) for(j=0;j5;j+) gotoxy(2*p_x+2*j,p_y+i); if(boxij=1&mapp_y+ip_x+j=0) printf( );p_x-;goto Here;cased:caseD:p_xnext=p_x+1;p_ynext=p_y;flag2=judgein();if(flag2=1) for(i=0;i5;i+) for(j=0;j5;j+) gotoxy(2*p_x+2*j,p_y+i); if(boxij=1&mapp_y+ip_x+j=0) printf( );p_x+;goto Here;case
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1