C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc

上传人:wj 文档编号:349094 上传时间:2023-04-28 格式:DOC 页数:18 大小:506.50KB
下载 相关 举报
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第1页
第1页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第2页
第2页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第3页
第3页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第4页
第4页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第5页
第5页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第6页
第6页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第7页
第7页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第8页
第8页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第9页
第9页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第10页
第10页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第11页
第11页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第12页
第12页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第13页
第13页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第14页
第14页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第15页
第15页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第16页
第16页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第17页
第17页 / 共18页
C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc_第18页
第18页 / 共18页
亲,该文档总共18页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc

《C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc》由会员分享,可在线阅读,更多相关《C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc(18页珍藏版)》请在冰点文库上搜索。

C++俄罗斯方块实验报告(附实验体会)Word文档下载推荐.doc

3、详细设计设计说明:

本程序运行代码如下:

#include<

conio.h>

stdlib.h>

windows.h>

#include"

colorConsole.h"

#defineSQUARE_COLORFOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY//方块的颜色

#defineup72

#definedown80

#defineleft75

#defineright77

#defineesc27

#defineMAPW12//地图的宽度

#defineMAPH20//地图的高度

BOOLisavailable(inta[],intx,inty,intw,inth);

//判定是否能放下

voidturn(inta[][4],intw,inth,int*x,inty);

//转动

int*create();

//创建方块

voidinit();

//初始化工作

voiddrawblocks(inta[],intw,inth,intx,inty,WORDwColors[],intnColors);

voidclearcache();

//清除键盘缓冲区

voidend();

voidclearsquare(int*a,intw,inth,intx,inty);

voidgameover();

voiddeletemap(intm[][MAPW],introw,intw,inth);

//消除一行

intdx=30,dy=5;

//屏幕上的偏移量

intscore=0,level=0;

intmap[MAPH][MAPW];

inta1[4][4]={{1},{1,1,1}};

inta2[4][4]={{0,1},{1,1,1}};

inta3[4][4]={{1,1},{0,1,1}};

inta4[4][4]={{0,0,1},{1,1,1}};

inta5[4][4]={{0,1,1},{1,1}};

inta6[4][4]={{1,1,1,1}};

inta7[4][4]={{1,1},{1,1}};

inta[4][4];

intmain()

{

init();

int*b=NULL;

b=create();

//预创建方块

intq=0;

intsign,blank,x,y;

while

(1)

{

for(inti=0;

i<

4;

i++)//复制方块

for(intj=0;

j<

j++)

if(a[i][j]=*(b+i*4+j))blank=i;

y=1-blank;

x=4;

clearsquare(&

a[0][0],4,4,13,13);

b=create();

HANDLEhandle;

handle=initiate();

WORDwColors[1]={FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY};

drawblocks(b,4,4,13,13,wColors,1);

wColors[0]=SQUARE_COLOR;

drawblocks(&

a[0][0],4,4,x,y,wColors,1);

clearcache();

charstring[5];

wColors[0]=FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY;

textout(handle,26+dx,5+dy,wColors,1,itoa(score,string,10));

textout(handle,26+dx,9+dy,wColors,1,itoa(level,string,10));

sign=1;

while(sign)

{

intdelay=0,max_delay=100-10*level;

//延迟量

while(delay<

max_delay)

{

if(_kbhit())//用if避免按住键使方块卡住

{

intdraw=0;

intkey=_getch();

switch(key)

{

caseup:

clearsquare(&

a[0][0],4,4,x,y);

turn(a,4,4,&

x,y);

draw=1;

break;

casedown:

delay=max_delay;

caseleft:

if(isavailable(&

a[0][0],x-1,y,4,4))

{

clearsquare(&

x--;

draw=1;

}

caseright:

a[0][0],x+1,y,4,4))

x++;

}

caseesc:

end();

}

if(draw)

HANDLEhandle;

handle=initiate();

WORDwColors[1]={SQUARE_COLOR};

drawblocks(&

draw=0;

}

_sleep(8);

delay++;

}

if(isavailable(&

a[0][0],x,y+1,4,4))//判断是否能下移

clearsquare(&

y++;

HANDLEhandle;

handle=initiate();

WORDwColors[1]={SQUARE_COLOR};

drawblocks(&

else

sign=0;

//标记,使跳出while(sign)循环,产生新方块

if(y<

=1)gameover();

//是否结束

for(inti=0;

i++)//放下方块

for(intj=0;

if(a[i][j]&

&

((i+y)<

MAPH-1)&

((j+x)<

MAPW-1))

map[i+y][j+x]=a[i][j];

intfull,k=0;

for(i=y;

min(y+4,MAPH-1);

i++)

full=1;

for(intj=1;

11;

if(!

map[i][j])full=0;

if(full)//消掉一行

deletemap(map,i,MAPW,MAPH);

k++;

q++;

score=score+k;

level=min(q/30,9);

}

}

returnEXIT_SUCCESS;

}

BOOLisavailable(inta[],intx,inty,intw,inth)

for(inti=max(y,1);

y+h;

for(intj=x;

x+w;

if(map[i][j]&

a[w*(i-y)+j-x])

return0;

return1;

int*create()

int*a=NULL;

intc=rand()%7;

switch(c)

case0:

a=&

a1[0][0];

break;

case1:

a2[0][0];

case2:

a3[0][0];

case3:

a4[0][0];

case4:

a5[0][0];

case5:

a6[0][0];

case6:

a7[0][0];

returna;

voidinit() //初始化工作

for(inti=0;

20;

map[i][0]=-2;

map[i][11]=-2;

for(i=0;

12;

map[0][i]=-1;

map[19][i]=-1;

map[0][0]=-3;

map[0][11]=-3;

map[19][0]=-3;

map[19][11]=-3;

HANDLEhandle;

handle=initiate();

WORDwColors[1]={FOREGROUND_GREEN|FOREGROUND_INTENSITY};

textout(handle,26+dx,3+dy,wColors,1,"

分数"

);

textout(handle,26+dx,7+dy,wColors,1,"

等级"

textout(handle,26+dx,11+dy,wColors,1,"

下一个方块提示"

wColors[1]=FOREGROUND_RED|FOREGROUND_INTENSITY;

drawblocks(&

map[0][0],12,20,0,0,wColors,1);

textout(handle,dx,dy,wColors,1,"

◇══════════◇"

wColors[0]=FOREGROUND_GREEN|FOREGROUND_INTENSITY;

textout(handle,dx-16,dy,wColors,1,"

按任意键开始"

wColors[0]=FOREGROUND_RED|FOREGROUND_INTENSITY;

textout(handle,dx-15,dy+3,wColors,1,"

制作者"

wColors[0]=FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY;

textout(handle,dx-15,dy+5,wColors,1,"

赵强"

intx=_getch();

srand(x);

"

voiddrawblocks(inta[],intw,inth,intx,inty,WORDwColors[],intnColors)

handle=initiate();

inttemp;

h;

for(intj=0;

w;

if((temp=a[i*w+j])&

y+i>

0)

if(temp==-3)

textout(handle,2*(x+j)+dx,y+i+dy,wColors,nColors,"

◆"

elseif(temp==-2)

║"

elseif(temp==-1)

═"

elseif(temp==1)

■"

voidclearcache()

while(_kbhit())

_getch();

voidend()

exit(EXIT_SUCCESS);

voidturn(inta[][4],intw,inth,int*x,inty)

intb[4][4]={{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};

intsign=0,line=0;

for(inti=h-1;

i>

=0;

i--)

if(a[i][j])

b[j][line]=a[i][j];

sign=1;

if(sign)

line++;

sign=0;

if(isavailable(&

b[0][0],*x-i,y,w,h))

*x-=i;

for(intk=0;

k<

k++)

for(intj=0;

a[k][j]=b[k][j];

break;

voidclearsquare(int*a,intw,inth,intx,inty)

WORDwColors[1]={SQUARE_COLOR};

if(a[i*w+j]&

i+y>

textout(handle,2*(x+j)+dx,y+i+dy,wColors,1,"

"

voidgameover()

WORDwColors[1]={FOREGROUND_RED|FOREGROUND_GREEN};

textout(handle,7+dx,10+dy,wColors,1,"

游戏结束"

clearcache();

_getch();

voiddeletemap(intm[][MAPW],introw,intw,inth)

textout(handle,2+dx,row+dy,wColors,1,"

﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌"

_sleep(100);

for(inti=row;

1;

m[i][1],MAPW-2,1,1,i);

for(intj=1;

MAPW-1;

m[i][j]=m[i-1][j];

m[i][1],MAPW-2,1,1,i,wColors,1);

for(i=1;

m[1][i]=0;

HANDLEinitiate()

HANDLEhOutput;

hOutput=GetStdHandle(STD_OUTPUT_HANDLE);

returnhOutput;

BOOLtextout(HANDLEhOutput,intx,inty,WORDwColors[],intnColors,LPTSTRlpszString)

DWORDcWritten;

BOOLfSuccess;

COORDcoord;

coord.X=x;

//startatfirstcell

coord.Y=y;

//offirstrow

fSuccess=WriteConsoleOutputCharacter(

hOutput,//screenbufferhandle

lpszString,//pointertosourcestring

lstrlen(lpszString),//lengthofstring

coord,//firstcelltowriteto

&

cWritten);

//actualnumberwritten

if(!

fSuccess)

cout<

<

"

error:

WriteConsoleOutputCharacter"

endl;

for(;

fSuccess&

coord.X<

lstrlen(lpszString)+x;

coord.X+=nColors)

{

fSuccess=WriteConsoleOutputAttribute(

hOutput,//屏幕缓存处理

wColors,//pointertosourcestring

nColors,//lengthofstring

coord,//firstcelltowriteto

&

//actualnumberwritten

}

cout<

WriteConsoleOutputAttribute"

return0;

}4、程序运行结果截图:

按任意键游戏开始

方块左移

方块右移

下一个方块开始下落

方块变形

消一行,增加1分

成功消多行

消多行后分数增加更多

消完30行后,提升一个等级

方块叠到顶端后游戏结束

5、程序使用说明:

(1)按任意键开始游戏

(2)控制方块下落位置进行消行处理

(3)成功消行后加分,当消30行之后等级升一级,最高达到10等级

(4)当产生的新方块不能再下落时,游戏结束。

(5)过程中可以按ESC直接退出游戏

6、本实验的心得体会

上个学期学习C++的时候,主要是局限于读课本,记住课本上的一些知识和概念,但很少自己亲自动手去编写代码,总是眼高手低,当真正的去编写这个俄罗斯游戏的时候就体会到编写代码真的好难,尤其是刚开始的想的时候,根本不知道如何下手。

后来通过上网查询和请教一些编程比较好的同学后才有了一个基本的思路,自己又重新翻阅了一下课本,将课本上的知识又重新细致的复习了一遍,最终借助于网络和同学的帮助完成了这个实验。

通过这个实验发现自己在编程方面还有很大的欠缺,编程能力很差劲,不过通过这个实验,也让我对上学期学习的C++知识有了一个很好很全面的复习,这是这个实验带给我最大的收获。

必须要亲自动手多写,多看代码才能真正的学好C++。

第18页共18页

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2