ImageVerifierCode 换一换
格式:DOCX , 页数:36 ,大小:19.32KB ,
资源ID:8589107      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/8589107.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C++俄罗斯方块代码.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

C++俄罗斯方块代码.docx

1、C+俄罗斯方块代码标准实用文案#include #include #include #include #include #include colorConsole.h / 老师的文件void begin();/ 开始游戏void frame();/ 边框设定int * getblocks();/ 方块产生void move(int line);/ 移动void drawblocks(int line);/ 方块显示void clearsquare(int line); /方块擦出void turn(int line);/ 方块旋转bool isavailable(int line); /判断是

2、否能下落void remember(int line);/ 记忆方块位置void deleteline(int line);/ 方块满一行消除bool ifgameover();/ 判断是否游戏结束void end();/ 游戏结束#define up72#define down80文档标准实用文案#define left75#define right77#define esc27HANDLE handle;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 a5

3、44=0,1,1,1,1;int a644=1,1,1,1;int a744=1,1,1,1;int row=0; / 列数int score=0;int level=0;int * block1=NULL;int * block2=NULL;int * block3=NULL;int coordinate1218=0; / 坐标数组,边框 12*18( 最后一行,两边边框计算在内 )int judge=0;文档标准实用文案int scorex=0;int temp44=0;void main() / 主函数int t=1;handle = initiate();while(t)t=0;beg

4、in();sndPlaySound(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(handle,34,10,wColors,1,Game Over);文档标准实用文案Sleep(800);end();elseif(k=1)block2=getblocks();block3=block2; /block2

5、指向将出现的方块地址block2=getblocks(); / 获取下一个新的方块block1=block3;row=52;clearsquare(16); / 擦除 next 的方块block1=block2;drawblocks(15); / 在 next 显示下一块方块图形row=34;block1=block3;for(int i=4;i=7;i+) / 所构建的方块图形最多只有占有两排,所以只用 4-7 即可对应if(*(block1+i)textout(handle,26+i*2,4,wColors,1, ); / 方块先露出下面部分文档标准实用文案Sleep(500-50*lev

6、el);for(int line=4;line=22;line+) / 方块自主下落,方块从第四排开始出现if(isavailable(line) / 检验刚产生的方块是否碰壁,碰到已落方块clearsquare(line); / 消除方块先露初的下面分drawblocks(line); / 产生完整的下落方块move(line);elseremember(line); / 落定后将这些位置对应的 all 数组中元素置 1deleteline(line); / 消行以及加分if(line=4)judge=1;文档标准实用文案break;void begin()int i=1;WORD wCol

7、ors1;wColors0=FOREGROUND_GREEN|FOREGROUND_INTENSITY;WORD wColors12;wColors10=FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY;wColors11=FOREGROUND_RED|FOREGROUND_INTENSITY;textout(handle,18,4,wColors,1, );textout(handle,18,5,wColors,1, );textout(handle,18,6,wColors,1, );textout(handle,18,7,wColo

8、rs,1, );文档标准实用文案textout(handle,18,8,wColors,1, );textout(handle,18,9,wColors,1,);textout(handle,18,10,wColors,1, );textout(handle,18,11,wColors,1, );textout(handle,18,12,wColors,1,);textout(handle,18,13,wColors,1,);textout(handle,18,14,wColors,1,);textout(handle,18,15,wColors,1,);textout(handle,18,1

9、6,wColors,1,简单 中等 );textout(handle,18,17,wColors,1,请按 1请按 2);textout(handle,18,18,wColors,1,);textout(handle,18,19,wColors,1, );textout(handle,18,20,wColors,1,困难请按 3);textout(handle,54,22,wColors,1,MADE BY );while(i)textout(handle,30,8,wColors1,2, 俄罗斯方块 );Sleep(800);textout(handle,30,8,wColors1,2, )

10、;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); / 清屏void frame() / 边框的设定WORD wColors1;wColors0=FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY;WORD wColors11;wColors10=FOREGROUND_RED|FO

11、REGROUND_INTENSITY;for(int i=0;i=11;i+)coordinatei17=1;/ 底排边框定义为1for(int j=0;j=17;j+)coordinate0 j=1;/ 两边边框定义为1coordinate11j=1;char string5;textout(handle,59,5,wColors,1,itoa(level,string,10);textout(handle,52,5,wColors,1,level: );文档标准实用文案textout(handle,52,9,wColors,1,score: 0);textout(handle,52,13,

12、wColors,1,next:);textout(handle,10,6,wColors1,1, 暂停 SPACE);textout(handle,10,7,wColors1,1, 退出 ESC);textout(handle,10,8,wColors1,1, 翻转 );textout(handle,10,9,wColors1,1, 向右 );textout(handle,10,10,wColors1,1, 向左 );textout(handle,10,11,wColors1,1, 加速 );textout(handle,33,2,wColors,1, 来 战个痛 );for(int m=13

13、;m=24;m+)textout(handle,2*m,3,wColors,1, ); / 上边框for(int n=4;n=21;n+)textout(handle,26,n,wColors,1, ); / 左边框for(int k=4;k=21;k+)textout(handle,48,k,wColors,1, ); / 右边框for(int l=13;l=23;l+)文档标准实用文案textout(handle,2*l,21,wColors,1, ); / 下边框textout(handle,26,3,wColors,1, );textout(handle,48,3,wColors,1,

14、 );textout(handle,26,21,wColors,1, );textout(handle,48,21,wColors,1, );int * getblocks() / 随机方块生成int * m=NULL;srand(time(NULL);int n=rand()%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=&a700;

15、break;return m;void drawblocks(int line) / 出现方块WORD wColors1;wColors0=FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY;for(int j=0;j=15;j+)int temp;temp=j/4;文档标准实用文案if(*(block1+j)textout(handle,row+j*2-temp*8,line+temp,wColors,1, );void clearsquare(int line) / 方块消失WORD wColors1;wColors0=FOREGROU

16、ND_BLUE|FOREGROUND_INTENSITY;if(line=4) / 针对消除刚产生的下排textout(handle,34,4,wColors,1, );textout(handle,36,4,wColors,1, );textout(handle,38,4,wColors,1, );textout(handle,40,4,wColors,1, );elsefor(int m=0;m=15;m+)int temp;文档标准实用文案temp=m/4; / 得 0-3 对应方块数组 1-4 行if(*(block1+m)textout(handle,row+m*2-temp*8,l

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

18、ow-2;drawblocks(line); / 出现新图案elserow=row+2; / 若不能移动则纵坐标不变break;case 77: / 右移row=row+2;if(isavailable(line)row=row-2;clearsquare(line+1);row=row+2;文档标准实用文案drawblocks(line);elserow=row-2;break;case 80: / 加速下落,即直接跳除循环mid=speed;break;case 27: / 终止游戏end();break;case 32: / 暂停int flag=1;while(flag)if (_kb

19、hit()文档标准实用文案if(_getch()=32)flag=0;break;elseSleep(10);default:break;Sleep(8); / 使方块延迟mid+;void turn(int line)clearsquare(line+1); / 消除原来的图案文档标准实用文案int b44=0; / 保存旋转前的方块int num=0,l=0;for(int m=0;m=3;m+)for(int n=0;n=0;i-) / 按行从下向上扫描for(int j=0;j4;j+) / 按列从左向右扫描if(bi j) / 如果为有效点,则进行 90 度旋转tempjl=bi j

20、;num=1;if(num)文档标准实用文案l+;num=0;block1=&temp00;if(isavailable(line)drawblocks(line);elsefor(int p=0;p=3;p+)for(int q=0;q=3;q+)temppq=bpq;block1=&temp00;drawblocks(line);bool isavailable(int line) / 检验,即看方块即将存在位置是否已经有 1int x,y;文档标准实用文案for(int m=0;m=15;m+)int temp;temp=m/4;x=row/2-13-4*temp+m; / 边框左边已有

21、 13 个位置y=line-4+temp; / 上面已有 4 个位置if(*(block1+m)&coordinatexy) / 相与为 1 则返回 0,否则跳出并循环继续return 0;void remember(int line) / 记忆int x,y;for(int m=0;m=15;m+)int temp;temp=m/4;x=row/2-13-temp*4+m;y=line-4+temp;if(*(block1+m) / 如果当前位置为 1,则返回原位置,并设置为 1文档标准实用文案coordinatexy-1=1;void deleteline(int l) / 消行WORD

22、wColors1;wColors0=FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY;int snum=0,b=0;for(int m=0;m=16;m+) / 从上向下消去方块if(coordinate1m=1&coordinate2m=1&coordinate3m=1&coordinate4m=1&coordinate5m=1&coordinate6m=1&coordinate7m=1&coordinate8m=1&coordinate9m=1&coordinate10m=1)textout(handle,28,m+4,wColors,1, good );Sleep(750);for(int n=1;n=m;n+)文档标准实用文案for(int j=1;j=10;j+)coordinatejm-n+1=coor

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1