俄罗斯方块C语言版.doc

上传人:自*** 文档编号:126896151 上传时间:2020-03-28 格式:DOC 页数:9 大小:33KB
返回 下载 相关 举报
俄罗斯方块C语言版.doc_第1页
第1页 / 共9页
俄罗斯方块C语言版.doc_第2页
第2页 / 共9页
俄罗斯方块C语言版.doc_第3页
第3页 / 共9页
俄罗斯方块C语言版.doc_第4页
第4页 / 共9页
俄罗斯方块C语言版.doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《俄罗斯方块C语言版.doc》由会员分享,可在线阅读,更多相关《俄罗斯方块C语言版.doc(9页珍藏版)》请在金锄头文库上搜索。

1、/*-俄罗斯方块C语言版-*/ #include #include #include #include #include int r,p,q=0,score=0,speed=25; int image2010; /* */static int brickX74=0,1,2,3,0,1,1,2,2,1,1,0,1,1,2,2,0,0,1,2,2,2,1,0,0,1,1,2;static int brickY74=0,0,0,0,0,0,1,1,0,0,1,1,0,1,0,1,0,1,1,1,0,1,1,1,0,0,1,0;/*存放方块的x,y坐标*/unsigned int x4; unsign

2、ed int y4;/*函数声明*/void Welcome(void); /*欢迎界面*/void Display(int binimage2010); /* 显示游戏面板函数*/void GotoXY(int x, int y); /*输出定位函数*/void Pause(void); /*暂停*/void Block_Random(); /*随机生成一个砖块*/int move(int offsetX,int offsetY,int binImage2010); /*左移、右移、下移*/int rotate( int binImage2010); /*旋转函数*/void output(

3、 int binImage2010); /*输出到显示面板*/unsigned int removeFullLines(); /*检查是否有一行填满*/void copyimage(int destimage2010,int sourceimage2010); /*拷贝数组*/int score; /记录分数int difficulty; /难度/*-*/ int main(void) int i,j; int gameOver=0; /游戏是否结束 int brickInFlight=0; /砖块是否处于飞行状态 int brickType=0; /砖块类别 unsigned int ini

4、tOrientation=0; /初始状态 int notCollide=0; /砖块是否冲突 int arrowKey=0; int tempimage2010; score=0;difficulty=500; for(i=0;i20;i+) for(j=0;j10;j+) /*初始化游戏面板*/imageij=0; for(i=0;i20;i+) for(j=0;j10;j+) /*初始化临时游戏面板*/tempimageij=0; Welcome(); /*欢迎界面*/Display(image); /*显示游戏面板*/ 开始游戏 while (!gameOver) if (!brick

5、InFlight) / 没有砖块落下时,需要新建一个砖块. / 新建砖块需要随机指定砖块的形状和初始状态.copyimage(tempimage,image); Block_Random(); notCollide = move(10/2, 0,image); /检查是否冲突 if (notCollide) brickInFlight = 1; output(tempimage); Display(tempimage); / 显示image else / 新建砖块同游戏面板的顶部有冲突,表明面板剩余空间已经放不下新砖块。/游戏结束 gameOver = 1; brickInFlight = 0

6、; /if (brickInFlight) else / 当前有砖块正在下落,因此需要检测用户的按键 copyimage(tempimage,image);if(kbhit()/*Checks the console for keyboard input*/ /检测是否有键按下 arrowKey = getch(); / 检查用户输入 if (arrowKey = d|arrowKey = 6) /*右移*/notCollide=move(1, 0,image); else if (arrowKey = a|arrowKey = 4) /*左移*/notCollide=move(-1, 0,i

7、mage);else if (arrowKey = w|arrowKey = 8) /*旋转*/ notCollide=rotate(image);else if (arrowKey = x|arrowKey = 2) /*下移*/notCollide=move(0, 1,image); else if (arrowKey = s) /一键加速下落 notCollide=move(0, 1,image);while(notCollide) notCollide=move(0, 1,image);if (notCollide) output(tempimage);Display(tempimag

8、e);copyimage(tempimage,image); else if (arrowKey = p) /*暂停*/Pause(); / 砖块靠重力下落.Sleep(difficulty); notCollide=move(0, 1,image); if (notCollide) output(tempimage); Display(tempimage); else / 砖块落在底部或已固定的砖块上,不再下落. brickInFlight = 0; / Add this brick permanently to the bin. output(image); Display(tempima

9、ge); / 检查是否需要消行switch (removeFullLines() /计分方式。这里还可以实现更复杂的计分方式case 1:score+;break; case 2:score+=3;break; case 3:score+=5;break; case 4:score+=8;break; switch(score/100) /等级确定case 0:difficulty=500;break; case 1:difficulty=200;break; case 2:difficulty=170;break; case 3:difficulty=150;break; case 4:di

10、fficulty=120;break; case 5:difficulty=100;break; case 6:difficulty=70;break; case 7:difficulty=50;break; case 8:difficulty=20;break; case 9:difficulty=0;break; / 检查消行后,更新外部图像面板 copyimage(tempimage,image); Display(tempimage); GotoXY(1,24); printf(Game Over); getch(); return 0; /*-*/ void Display(int binimage2010) int i,j; GotoXY(1,1); for(i=0;i20;i+) printf(); for(j=0;j10;j+) switch(binimageij) case 0:printf( );break; case 1:printf();break;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > IT计算机/网络 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号