C++俄罗斯方块代码(北邮版)_第1页
C++俄罗斯方块代码(北邮版)_第2页
C++俄罗斯方块代码(北邮版)_第3页
C++俄罗斯方块代码(北邮版)_第4页
C++俄罗斯方块代码(北邮版)_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

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

文档简介

1、#in elude #in elude #in elude #i nclude #in elude #include eolorConsole.h/ 老师的文件void begi n();void frame();int * getbloeks();void move(i nt lin e); voiddrawbloeks(i nt lin e); voidclearsquare(i nt lin e); /void tur n(i nt lin e);bool isavailable(i nt li ne);/ void remember(i nt lin e);void deleteli

2、ne(i nt lin e);bool ifgameover();void en d();/开始游戏/边框设定/方块产生/移动/方块显示方块擦出/方块旋转判断是否能下落/记忆方块位置/方块满一行消除/判断是否游戏结束/游戏结束#defi ne up72#defi ne down80#defi ne left75#defi ne right77#defi ne esc27HANDLE han dle;int a144=1,1,1,1;int a244=0,1,1,1,1;int a344=1,1,0,1,1;int a444=0,0,1,1,1,1;int a544=0,1,1,1,1;int

3、a644=1,1,1,1;int a744=1,1,1,1;int row=0;int seore=0;in t level=0;int * block 仁 NULL;int * bloek2=NULL;int * bloek3=NULL;in t coordi nate1218=0;在内)int judge=0;/七种方块的二维数组/列数/坐标数组,边框 12*18(最后一行,两边边框计算int scorex=0;int temp44=0;void mai n()int t=1;han dle = in itiate(); while(t)t=0;begi n();sn dPIaySou n

4、d(music.wav,SND_LOOP|SND_ASYNC);frame();WORD wColors1;wColors0=FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY;for(int k=1;k=999999;k+)if(ifgameover()/判断是否结束textout(ha ndle,34,10,wColors,1,Game Over);Sleep(800);en d(); else4-7 即可对应if(*(block1+i)textout(ha ndle,26+i*2,4,wColors,1,);Sleep(500-50*

5、level);if(k=1)block2=getblocks();block3=block2;block2=getblocks();block 仁 block3;row=52;clearsquare(16);block 仁 block2;drawblocks(15);row=34;block 仁 block3;for(int i=4;i=7;i+)block2 指向将出现的方块地址/获取下一个新的方块擦除 next 的方块/在 next 显示下一块方块图形/所构建的方块图形最多只有占有两排,所以只用/主函数/方块先露出下面部分for(i nt lin e=4;li ne=22;l in e+)

6、 方块从第四排开始出现if(isavailable(l in e)块是否碰壁,碰到已落方块clearsquare(l in e);初的下面分drawblocks(li ne);F 落方块move(li ne); elseremember(l in e);all 数组中元素置 1deleteli ne(l in e); if(li ne=4) judge=1;break; void begi n()int i=1;WORD wColors1;wColors0=FOREGROUND_GREEN|FOREGROUND_INTENSITY;WORD wColors12;wColors10=FOREGR

7、OUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY;wColors11=FOREGROUND_RED|FOREGROUND_INTENSITY;些位置对应的/方块自主下落,/检验刚产生的方/消除方块先露/产生完整的/落定后将这/消行以及加分textout(ha ndle,18,4,wColors,1,textout(ha ndle,18,5,wColors,1,textout(ha ndle,18,6,wColors,1,textout(ha ndle,18,7,wColors,1,textout(ha ndle,18,8,wColors,1,text

8、out(ha ndle,18,9,wColors,1,textout(ha ndle,18,10,wColors,1,textout(ha ndle,18,11,wColors,1,Jk Jk );Jk Jk );); 人、););k ); 、););、TJHF ”););、匚);简单、匚中等);请按 1请按 2););i );困难 请按 3);textout(ha ndle,54,22,wColors,1,MADE BY ); while(i)textout(handle,30,8,wColors1,2,俄罗斯方块);Sleep(800);textout(ha ndle,30,8,wColo

9、rs1,2,);Sleep(800);if (_kbhit()/ 输入等级switch(_getch()case 1:level=1;i=0;/跳出循环break;case 2: level=4; i=0; break;case 3:level=7;i=0; break;system(cls);textout(ha ndle,18,12,wColors,1,textout(ha ndle,18,13,wColors,1,textout(ha ndle,18,14,wColors,1,textout(ha ndle,18,15,wColors,1,textout(ha ndle,18,16,wC

10、olors,1,textout(ha ndle,18,17,wColors,1,textout(ha ndle,18,18,wColors,1,textout(ha ndle,18,19,wColors,1,textout(ha ndle,18,20,wColors,1,/清屏void frame() /边框的设定WORD wColors1;wColors0=FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY;WORD wColors11;wColors10=FOREGROUND_RED|FOREGROUND_INTENSITY;for(

11、int i=0;i=11;i+)coordi natei17=1;/ 底排边框定义为 1for(i nt j=0;j=17;j+)coordi nateOj=1;/ 两边边框定义为 1coordi nate11j=1;char stri ng5;textout(ha ndle,59,5,wColors,1,itoa(level,stri ng,10);textout(ha ndle,52,5,wColors,1,level:);textout(ha ndle,52,9,wColors,1,score: 0);textout(ha ndle,52,13,wColors,1, next:);tex

12、tout(ha ndle,10,6,wColors1,1, 暂停SPACE)textout(ha ndle,10,7,wColors1,1, 退出ESC);textout(ha ndle,10,8,wColors1,1, 翻转T );textout(ha ndle,10,9,wColors1,1, 向右T);textout(handle,10,10,wColors1,1,向左J);textout(handle,10,11,wColors1,1,加速J );textout(ha ndle,33,2,wColors,1, 来战个痛 );for(i nt m=13;m=24;m+)textout(h

13、a ndle,2*m,3,wColors,1, );/ 上边框for(i nt n=4;n=21; n+)textout(handle,26,n,wColors,1,I);/ 左边框for(int k=4;k=21;k+)textout(handle,48,k,wColors,1,I);/ 右边框for(int l=13;l=23;l+)textout(ha ndle,2*l,21,wColors,1, ); / 下边框textout(ha ndle,26,3,wColors,1, F);textout(ha ndle,48,3,wColors,1,、);textout(handle,26,2

14、1,wColors,1, k ”);textout(handle,48,21,wColors,1,丄);int * getblocks()/随机方块生成int * m=NULL;sran d(time(NULL);int n=ran d()%7;switch( n)case 0:m=&a100;break;case 1:m=&a200;break;case 2:m=&a300;break;case 3:m=&a400;break;case 4:m=&a500;break;case 5:m=&a600;break;case 6:m=&a70

15、0;break;return m;void drawblocks(i nt line)/ 出现方块WORD wColors1;wColors0=FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY;for(i nt j=0;j=15;j+)int temp;temp=j/4;if(*(block1+j)textout(ha ndle,row+j*2-temp*8,li ne+temp,wColors,1,);void clearsquare(int line)/ 方块消失WORD wColors1; wColors0=FOREGROUND_B

16、LUE|FOREGROUND_INTENSITY;if(line=4)/针对消除刚产生的下排textout(ha ndle,34,4,wColors,1,textout(ha ndle,36,4,wColors,1,textout(ha ndle,38,4,wColors,1,textout(ha ndle,40,4,wColors,1,elsefor(i nt m=0;m=15;m+)int temp; temp=m/4; /得 0-3 对应方块数组 1-4 行if(*(block1+m)textout(ha ndle,row+m*2-temp*8,li ne-1+temp,wColors,

17、1,);int mid=0,speed=100-10*level; while(midspeed)if (_kbhit()switch(_getch()case 72:turn(li ne); break;case 75:row=row-2;if(isavailable(li ne) row=row+2;clearsquare(line+1); / 消除原来图案,line+1 是避免 line=4 程序void move(i nt line)/方块的左右移动,加速下落,翻转等/翻转/左移/纵坐标减 2/判断是否能移动出错row=row-2;drawblocks(line);/ 出现新图案els

18、erow=row+2;/若不能移动则纵坐标不变break;case 77:/右移row=row+2;if(isavailable(l in e)row=row-2; clearsquare(l in e+1); row=row+2;drawblocks(l in e);elserow=row-2; break;case 80:/加速下落,即直接跳除循环mid=speed;break;case 27:/终止游戏en d();break;case 32:/暂停int flag=1;while(flag)if (_kbhit()if(_getch()=32) flag=0;break;elsedef

19、ault:break;Sleep(8); mid+;void tur n(i nt line)clearsquare(l in e+1);int b44=0;int num=0,l=0;for(i nt m=0;m=3;m+)for(i nt n=0;n=0;i-)for(i nt j=O;j4;j+)if(bij)tempjl=bij;/把 b44全赋值为当前图形数组/按行从下向上扫描/按列从左向右扫描/如果为有效点,则进行 90 度旋转num=1; if(num) l+; num=0;block 仁 &temp00; if(isavailable(l in e)Sleep(10);

20、/使方块延迟/消除原来的图案/保存旋转前的方块elsedrawblocks(line);for(i nt p=0;p=3;p+)for(i nt q=0;q=3;q+)temppq=bpq;block 仁&temp00;drawblocks(line);bool isavailable(i nt li ne)int x,y;for(i nt m=0;m=15;m+)int temp;temp=m/4;x=row/2-13-4*temp+m;y=li ne-4+temp;if(*(block1+m) &coordi nate xy)/ return 0;/检验,即看方块即将存在位

21、置是否已经有1/边框左边已有 13 个位置/上面已有 4 个位置相与为 1 则返回 0,否则跳出并循环继续void remember(i nt line)int x,y;for(i nt m=0;m=15;m+)int temp; temp=m/4;x=row/2-13-temp*4+m;y=li ne-4+temp;if(*(block1+m)为 1coordinatexy-1=1; /记忆/如果当前位置为 1,则返回原位置,并设置void deleteli ne(i ntl)/消行WORD wColors1;wColors0=FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY;int snum=0,b=0;for(i nt m=0;m=16;m+)/从上向下消去方块if(coordi nate1m=1 &coordi nate2m=1 &coordi nate3

温馨提示

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

评论

0/150

提交评论