C++写的俄罗斯方块源代码+开发文档.docx

上传人:b****4 文档编号:4350829 上传时间:2023-05-07 格式:DOCX 页数:17 大小:24.70KB
下载 相关 举报
C++写的俄罗斯方块源代码+开发文档.docx_第1页
第1页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第2页
第2页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第3页
第3页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第4页
第4页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第5页
第5页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第6页
第6页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第7页
第7页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第8页
第8页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第9页
第9页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第10页
第10页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第11页
第11页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第12页
第12页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第13页
第13页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第14页
第14页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第15页
第15页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第16页
第16页 / 共17页
C++写的俄罗斯方块源代码+开发文档.docx_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

C++写的俄罗斯方块源代码+开发文档.docx

《C++写的俄罗斯方块源代码+开发文档.docx》由会员分享,可在线阅读,更多相关《C++写的俄罗斯方块源代码+开发文档.docx(17页珍藏版)》请在冰点文库上搜索。

C++写的俄罗斯方块源代码+开发文档.docx

C++写的俄罗斯方块源代码+开发文档

0204060

□□□□

20

□□□□

40

□□□□

60

□□□□

每一点取的是左上角坐标

□□□□□□□□□□□□□□□□

□■□□□□□□□■■□□□□□

□■□□□□■□□□■□■■■□

□■■□■■■□□□■□■□□□

{20,60,20,40,20,20,40,60,RED,1},

{0,60,20,60,40,40,40,60,RED,2},

{20,20,40,20,40,40,40,60,RED,3},

{0,60,0,40,20,40,40,40,RED,0},

□□□□□□□□□□□□□□□□

□■■□□□□□□□■□□□□□

□■□□■□□□□□■□■■■□

□■□□■■■□□■■□□□■□

{20,60,20,40,20,20,40,20,YELLOW,1},

{0,40,0,60,20,60,40,60,YELLOW,2},

{20,60,40,60,40,40,40,20,YELLOW,3},

{0,40,20,40,40,40,40,60,YELLOW,0},

□□□□□□□□□□□□□□□□

□□□□□■□□□□□□□■□□

□■□□■■□□■■■□□■■□

■■■□□■□□□■□□□■□□

{0,60,20,60,20,40,40,60,GREEN,1},

{0,40,20,60,20,40,20,20,GREEN,2},

{0,40,20,40,20,60,40,40,GREEN,3},

{20,20,20,40,20,60,40,40,GREEN,0},

□□□□□□□□

□□□□■□□□

□■■□■■□□

■■□□□■□□

{0,60,20,60,20,40,40,40,WHITE,1},

{0,40,0,20,20,40,20,60,WHITE,0},

□□□□□□□□

□□□□□■□□

■■□□■■□□

□■■□■□□□

{20,0,20,20,20,40,20,60,LIGHTGRAY,1},

{0,40,20,40,40,40,60,40,LIGHTGRAY,0},

□■□□□□□□

□■□□□□□□

□■□□■■■■

□■□□□□□□

{20,20,20,40,20,60,20,80,LIGHTGRAY,1},

{0,60,20,60,40,60,60,60,LIGHTGRAY,0},

□□□□

□□□□

□■■□

□■■□

{20,40,20,60,40,40,40,60,LIGHTGREEN,1}

以下是源代码:

Game.h文件

#include

#include

#include

#include

#defineUP'w'

#defineDOWN's'

#defineLEFT'a'

#defineRIGHT'd'

#defineEsc27

intkey=NULL;

inta=0;

structShape

{

intxy[8];

intcolor;

};

structfull//记?

录?

每?

个?

方¤?

块¨¦的Ì?

信?

息¡é

{

boolisfull;

intcolor;

};

Shapeshape[7][4]=//7种?

基¨´本À?

形?

状Á¡ä四?

种?

变À?

形?

(ꡧ不?

够?

四?

种?

变À?

化¡¥的Ì?

用®?

相¨¤同ª?

的Ì?

来¤¡ä填¬?

充?

)ê?

{

{

{20,60,20,40,20,20,40,60,RED},

{0,60,20,60,40,40,40,60,RED},

{20,20,40,20,40,40,40,60,RED},

{0,60,0,40,20,40,40,40,RED},

},

{

{20,60,20,40,20,20,40,20,YELLOW},

{0,40,0,60,20,60,40,60,YELLOW},

{20,60,40,60,40,40,40,20,YELLOW},

{0,40,20,40,40,40,40,60,YELLOW},

},

{

{0,60,20,60,20,40,40,60,GREEN},

{0,40,20,60,20,40,20,20,GREEN},

{0,40,20,40,20,60,40,40,GREEN},

{20,20,20,40,20,60,40,40,GREEN},

},

{

{0,60,20,60,20,40,40,40,WHITE},

{0,40,0,20,20,40,20,60,WHITE},

{0,60,20,60,20,40,40,40,WHITE},

{0,40,0,20,20,40,20,60,WHITE}

},

{

{0,40,20,40,20,60,40,60,BLUE},

{0,40,0,60,20,40,20,20,BLUE},

{0,40,20,40,20,60,40,60,BLUE},

{0,40,0,60,20,40,20,20,BLUE},

},

{

{20,0,20,20,20,40,20,60,LIGHTGRAY},

{0,40,20,40,40,40,60,40,LIGHTGRAY},

{20,0,20,20,20,40,20,60,LIGHTGRAY},

{0,40,20,40,40,40,60,40,LIGHTGRAY},

},

{

{20,40,20,60,40,40,40,60,LIGHTGREEN},

{20,40,20,60,40,40,40,60,LIGHTGREEN},

{20,40,20,60,40,40,40,60,LIGHTGREEN},

{20,40,20,60,40,40,40,60,LIGHTGREEN},

}

};

classGame

{

intx,y;//xy表À¨ª示º?

方¤?

块¨¦的Ì?

相¨¤对?

坐Á?

标À¨º

intdir;//方¤?

块¨¦移°?

动¡¥方¤?

向¨°

int_shape;//七?

种?

形?

状Á¡ä

intchange_shape;//四?

种?

变À?

换?

intold_shape;//记?

录?

未¡ä变À?

形?

方¤?

块¨¦的Ì?

形?

状Á¡ä

intold_change_shape;

boolis_fullline[20];//标À¨º记?

是º?

否¤?

满¨²行D

fullisfull[20][10];//标À¨º记?

是º?

否¤?

有®D方¤?

块¨¦20行D10列¢D

public:

Game();

intshapeX(inti){return(shape[_shape][change_shape].xy[i]+x);};//返¤¦Ì回?

shape形?

状Á¡ä第̨²i个?

方¤?

块¨¦的Ì?

的Ì?

实º¦Ì际¨ºX坐Á?

标À¨º

intshapeY(inti){return(shape[_shape][change_shape].xy[i+1]+y);};//返¤¦Ì回?

shape形?

状Á¡ä第̨²i个?

方¤?

块¨¦的Ì?

的Ì?

实º¦Ì际¨ºY坐Á?

标À¨º

introwX(inti){returni*20+100;};//返¤¦Ì回?

第̨²i列¢D的Ì?

X坐Á?

标À¨º

intcolumnY(inti){returni*20+50;};//返¤¦Ì回?

第̨²i行D的Ì?

Y坐Á?

标À¨º

voiddrawinterface();//画-界?

面?

voiddrawshape();//画-方¤?

块¨¦

voidclearshape();//清?

除y方¤?

块¨¦

voiddrawshowshape();//画-在¨²预¡è览¤¨¤框¨°中D的Ì?

方¤?

块¨¦

voidclearshowshape();//清?

除y在¨²预¡è览¤¨¤框¨°中D的Ì?

方¤?

块¨¦

voidgetdir();//取¨?

得Ì?

方¤?

块¨¦移°?

动¡¥方¤?

向¨°

boolis_move_leftX();//方¤?

块¨¦是º?

否¤?

能¨¹向¨°左Á¨®移°?

boolis_move_rightX();//方¤?

块¨¦是º?

否¤?

能¨¹向¨°右®¨°移°?

boolis_moveY();//方¤?

块¨¦是º?

否¤?

能¨¹在¨²Y轴¨¢方¤?

向¨°移°?

动¡¥

boolis_change();//是º?

否¤?

能¨¹变À?

形?

(ꡧ近¨¹边À?

界?

时º¡À变À?

形?

后¨®不?

能¨¹出?

界?

)ê?

voidshapemove();//方¤?

块¨¦移°?

动¡¥

voidnewshape();//出?

新?

的Ì?

方¤?

块¨¦

voidfullline();//扫¦¡§描¨¨满¨²行D

voidclearfullline();//清?

除y满¨²行D

voidrepaint();//重?

画-(ꡧ实º¦Ì现?

消?

行D下?

移°?

)ê?

boolisgameover();//游®?

戏¡¤是º?

否¤?

结¨¢束º?

};

Game:

:

Game()

{

x=180;

y=50;

srand((unsigned)time(NULL));

_shape=rand()%7;

change_shape=rand()%4;

for(inti=0;i<20;i++)

for(intj=0;j<10;j++)

{

isfull[i][j].isfull=false;

isfull[i][j].color=BLACK;

}

for(inti=0;i<20;i++)

is_fullline[i]=false;

drawinterface();

}

voidGame:

:

drawinterface()

{

initgraph(640,480);

rectangle(345,45,435,135);

rectangle(95,45,305,455);

}

voidGame:

:

drawshape()

{

setfillstyle(shape[_shape][change_shape].color);

for(inti=0;i<=6;i+=2)

bar(shapeX(i),shapeY(i),shapeX(i)+20,shapeY(i)+20);

}

voidGame:

:

clearshape()

{

setfillstyle(BLACK);

for(inti=0;i<=6;i+=2)

bar(shapeX(i),shapeY(i),shapeX(i)+20,shapeY(i)+20);

}

voidGame:

:

drawshowshape()

{

setfillstyle(shape[old_shape][old_change_shape].color);

for(inti=0;i<=6;i+=2)

bar(shape[old_shape][old_change_shape].xy[i]+350,shape[old_shape][old_change_shape].xy[i+1]+50,shape[old_shape][old_change_shape].xy[i]+350+20,shape[old_shape][old_change_shape].xy[i+1]+50+20);

}

voidGame:

:

clearshowshape()

{

setfillstyle(BLACK);

for(inti=0;i<=6;i+=2)

bar(shape[old_shape][old_change_shape].xy[i]+350,shape[old_shape][old_change_shape].xy[i+1]+50,shape[old_shape][old_change_shape].xy[i]+350+20,shape[old_shape][old_change_shape].xy[i+1]+50+20);

}

voidGame:

:

getdir()

{

if(kbhit())

dir=getch();

if(dir==27)

key=dir;

}

boolGame:

:

is_move_leftX()

{

for(inti=0;i<=6;i+=2)

if(shapeX(i)<=100||isfull[(shapeY(i)-50)/20][(shapeX(i)-100)/20-1].isfull==true)////////////////////////////////////

returnfalse;

returntrue;

}

boolGame:

:

is_move_rightX()

{

for(inti=0;i<=6;i+=2)

if(shapeX(i)+20>=300||isfull[(shapeY(i)-50)/20][(shapeX(i)-100)/20+1].isfull==true)/////////////////////////////////

returnfalse;

returntrue;

}

boolGame:

:

is_moveY()

{

for(inti=0;i<=6;i+=2)

if(shapeY(i)>=430||isfull[(shapeY(i)-50)/20+1][(shapeX(i)-100)/20].isfull==true)

{

//setcolor(RED);

//rectangle(((shapeX(i)-100)/20-1)*20+100,((shapeY(i)-50)/20+1)*20+50,((shapeX(i)-100)/20-1)*20+100+20,((shapeY(i)-50)/20+1)*20+50+20);

returnfalse;

}

returntrue;

}

boolGame:

:

is_change()

{

for(inti=0;i<=6;i++)

{

if(change_shape<3)

{

if(shape[_shape][change_shape+1].xy[i]+x<100||shape[_shape][change_shape+1].xy[i]+x>300)//变À?

形?

后¨®超?

出?

边À?

界?

不?

能¨¹变À?

returnfalse;

if(isfull[(shape[_shape][change_shape+1].xy[i+1]+y-50)/20-1][(shape[_shape][change_shape+1].xy[i]+x-100)/20-1].isfull==true)//变À?

形?

后¨®碰?

到Ì?

方¤?

块¨¦

returnfalse;

}

elseif(change_shape==3)

{

if(shape[_shape][0].xy[i]+x<100||shape[_shape][0].xy[i]+x>300)

returnfalse;

if(isfull[(shape[_shape][0].xy[i+1]+y-50)/20-1][(shape[_shape][0].xy[i]+x-100)/20-1].isfull==true)

returnfalse;

}

}

returntrue;

}

voidGame:

:

shapemove()

{

if(a==0)

{

old_shape=_shape;

old_change_shape=change_shape;

drawshowshape();

a=1;

}

for(inti=0;i<20;i++)//把ã?

一°?

秒?

钟¨®分¤?

成¨¦20份¤Y(ꡧ加¨®快¨¬左Á¨®右®¨°移°?

动¡¥的Ì?

速¨´度¨¨)ê?

{

drawshape();

getdir();

Sleep(50);

clearshape();

switch(dir)

{

caseLEFT:

if(is_move_leftX())

x-=20;

break;

caseRIGHT:

if(is_move_rightX())

x+=20;

break;

caseDOWN:

if(is_moveY())

y+=20;

break;

caseUP:

if(is_change())

{

change_shape++;

if(change_shape==4)

change_shape=0;

}

break;

}

dir=NULL;

}

if(is_moveY())

y+=20;

}

voidGame:

:

newshape()

{

srand((unsigned)time(NULL));

if(!

is_moveY())

{

clearshowshape();

a=0;

drawshape();

for(inti=0;i<=6;i+=2)

{

isfull[(shapeY(i)-50)/20][(shapeX(i)-100)/20].isfull=true;

isfull[(shapeY(i)-50)/20][(shapeX(i)-100)/20].color=shape[_shape][change_shape].color;

}

clearfullline();

do

{

x=rand()%100+140;

}while(x%20!

=0);

y=50;

_shape=rand()%7;

change_shape=rand()%4;

}

}

voidGame:

:

fullline()

{

intcount=0;

for(inti=19;i>=0;i--)

{

for(intj=0;j<10;j++)

{

if(isfull[i][j].isfull==true)

count++;

if(count==10)

is_fullline[i]=true;

else

is_fullline[i]=false;

}

count=0;

}

}

voidGame:

:

clearfullline()

{

for(inta=0;a<4;a++)//最Á?

多¨¤一°?

次ä?

能¨¹消?

去¨£¤四?

行D

{

fullline();

for(intk=19;k>=0;k--)

{

if(is_fullline[k]==true)

{

for(inti=k;i>0;i--)

{

for(intj=0;j<10;j++)

{

isfull[i][j].isfull=isfull[i-1][j].isfull;

isfull[i][j].color=isfull[i-1][j].color;

}

}

repaint();

break;//消?

去¨£¤一°?

行D后¨®退ª?

出?

循-环¡¤防¤¨¤止1多¨¤消?

多¨¤

}

}

}

}

voidGame:

:

repaint()

{

for(inti=19;i>=0;i--)

{

for(intj=0;j<10;j++)

{

setfillstyle(isfull[i][j].color);

bar(j*20+100,i*20+50,j*20+120,i*20+70);

}

}

}

boolGame:

:

isgameover()

{

for(inti=0;i<=6;i++)

if(shapeY(i)<=50)

returntrue;

returnfalse;

}

Main.cpp文件

#include"Game.h"

externintkey;

Gamegame;

intmain()

{

setwritemode(R2_XORPEN);

while(key!

=Esc)

{

game.newshape();

game.shapemove();

if(game.isgameover())

break;

//game.repaint();

}

outtextxy(320,240,L"GameOver");

getch();

exit(0);

closegraph();

return0;

}

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

当前位置:首页 > 解决方案 > 学习计划

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

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