北邮 俄罗斯方块 C++程序代码文档格式.docx
《北邮 俄罗斯方块 C++程序代码文档格式.docx》由会员分享,可在线阅读,更多相关《北邮 俄罗斯方块 C++程序代码文档格式.docx(17页珍藏版)》请在冰豆网上搜索。
//挑战模式
voidBlock_Score();
//储存分数
HANDLEhandle;
WORDColors[1]={FOREGROUND_RED};
WORDBColors[1]={FOREGROUND_BLUE};
WORDGColors[1]={FOREGROUND_GREEN};
//设置颜色
intblock_cshape[4][4],block_newshape[4][4];
//设置两个临时方块矩阵
intspeed=1,delay_max=100,delay,score=0,score_high,mode;
//设置速度,最大延迟,延迟,分数,最高分,模式
intmap_shape[24][46];
//设置地图矩阵
intx_coordinate=29,y_coordinate=3;
//初始横纵坐标
intblock_shape[7][4][4]={{{0,0,0,0,
1,1,1,1,
0,0,0,0,
0,0,0,0},
{0,0,0,0,
0,0,1,0,
0,1,1,1,
{0,1,1,0,
0,1,0,0,
0,1,1,0,
{0,1,1,0,
0,0,1,0,
{0,0,0,0,
0,0,1,1,
1,1,0,0,
0,0,0,0}};
//设置种方块
voidmain()//主函数
{
handle=initiate();
//屏幕初始化
srand(time(NULL));
textout(handle,20,7,Colors,1,"
T"
);
Sleep(300);
textout(handle,22,7,Colors,1,"
E"
textout(handle,24,7,Colors,1,"
textout(handle,26,7,Colors,1,"
R"
textout(handle,28,7,Colors,1,"
I"
textout(handle,30,7,Colors,1,"
S"
textout(handle,34,7,Colors,1,"
B"
textout(handle,36,7,Colors,1,"
Y"
textout(handle,40,7,Colors,1,"
L"
textout(handle,42,7,Colors,1,"
textout(handle,44,7,Colors,1,"
J"
textout(handle,20,11,Colors,1,"
Pleaseselectgamemode:
"
textout(handle,22,12,Colors,1,"
Press\"
n\"
tochoosennormalmode"
textout(handle,22,13,Colors,1,"
c\"
tochoosenchallengemode"
intktemp=_getch();
"
switch(ktemp)
{
case110:
Start();
Begin_normal();
break;
case99:
Begin_challenge();
default:
}
PlaySound("
E:
\\BUPT\\小学期c++\\俄罗斯方块standard\\俄罗斯方块\\kaitou.wav"
0,SND_ASYNC);
while
(1)
x_coordinate=29,y_coordinate=3;
Block_Birth();
while
(1)//一个方块下落整个过程
{
delay=0;
while(delay<
delay_max)
{
if(_kbhit())
{Block_Change(block_cshape);
}
Sleep(8);
delay++;
}//判断对方块的操作
if(Block_Available(block_cshape,0,1))
Block_Clear(block_cshape);
y_coordinate++;
Block_Print(block_cshape);
}//判断是否下移
else
Block_Intomap(block_cshape);
Block_Deleteline();
break;
}//判断是否消行
}
voidStart()
{
textout(handle,50,15,BColors,1,"
Instruction:
textout(handle,50,16,BColors,1,"
Pleasecontrolby"
textout(handle,50,17,BColors,1,"
the\"
↑↓←→\"
textout(handle,50,18,BColors,1,"
Esc\"
toexit"
textout(handle,20,2,GColors,1,"
O"
textout(handle,20,23,GColors,1,"
textout(handle,45,2,GColors,1,"
textout(handle,45,23,GColors,1,"
textout(handle,50,23,BColors,1,"
ManufacturedbyLRJinBUPT"
textout(handle,50,5,BColors,1,"
Score:
textout(handle,50,3,BColors,1,"
Speed:
charoutput[10];
//临时输出矩阵
itoa(score,output,10);
textout(handle,56,5,BColors,1,output);
itoa(speed,output,10);
textout(handle,56,3,BColors,1,output);
for(intx=21;
x<
45;
x++)
textout(handle,x,2,GColors,1,"
="
textout(handle,x,23,GColors,1,"
for(inty=3;
y<
23;
y++)
textout(handle,20,y,GColors,1,"
|"
textout(handle,45,y,GColors,1,"
//打印游戏界面
voidBegin_normal()//初始游戏函数
mode=0;
textout(handle,28,1,BColors,1,"
NormalMode"
for(intx=0;
24;
for(inty=0;
46;
{map_shape[x][y]=1;
for(intx=3;
for(inty=21;
{map_shape[x][y]=0;
//初始化地图矩阵
ifstreamreadfile("
\\BUPT\\小学期c++\\俄罗斯方块standard\\俄罗斯方块\\score_normal.txt"
if(!
readfile.fail())
readfile>
>
output;
score_high;
readfile.close();
textout(handle,50,6,BColors,1,"
Best:
textout(handle,56,6,BColors,1,output);
//读取最高分
voidBegin_challenge()
mode=1;
textout(handle,26,1,BColors,1,"
ChallengeMode"
intline;
textout(handle,23,10,Colors,1,"
Pleaseinputinitial"
textout(handle,23,11,Colors,1,"
block'
slinesand"
textout(handle,23,12,Colors,1,"
thenpress\"
Enter\"
cin>
line;
textout(handle,0,0,Colors,1,"
for(intx=22;
x>
22-line;
x--)
y+=2)
intn=rand()%2;
map_shape[x][y]=n;
if(n)
{textout(handle,y,x,Colors,1,"
■"
Sleep(70);
}//初始化地图矩阵
\\BUPT\\小学期c++\\俄罗斯方块standard\\俄罗斯方块\\score_challenge.txt"
voidBlock_Print(intblock_shape[4][4])//打印方块函数
4;
{
if(block_shape[x][y]==1)
textout(handle,x_coordinate+2*y,y_coordinate+x,Colors,1,"
voidBlock_Clear(intblock_shape[4][4])//擦除方块
for(inty=0;
for(intx=0;
if(block_shape[y][x]==1)
textout(handle,x_coordinate+2*x,y_coordinate+y,Colors,1,"
voidBlock_Change(intblock_shape[4][4])//操作方块
intdirection=_getch();
switch(direction)
case72:
//up方块变形
for(intk=0;
k<
k++)
for(intj=0;
j<
j++)
block_newshape[3-j][k]=block_shape[k][j];
}
if(Block_Available(block_newshape,0,0))
Block_Clear(block_cshape);
Block_Print(block_newshape);
for(intk=0;
for(intj=0;
{block_cshape[k][j]=block_newshape[k][j];
break;
case75:
//left方块左移
if(Block_Available(block_cshape,-2,0))
x_coordinate-=2;
Block_Print(block_cshape);
case77:
//right方块右移
if(Block_Available(block_cshape,2,0))
x_coordinate+=2;
case80:
//down方块下移
delay=delay_max;
case27:
//Esc推出暂停游戏
textout(handle,50,10,Colors,1,"
Douwanttoexit"
textout(handle,50,11,Colors,1,"
thegame(y/n)"
inttemp=_getch();
switch(temp)
case121:
textout(handle,50,10,Colors,1,"
textout(handle,50,11,Colors,1,"
textout(handle,34,11,BColors,1,"
score:
charoutput[10];
itoa(score,output,10);
textout(handle,40,11,BColors,1,output);
PlaySound("
\\BUPT\\小学期c++\\俄罗斯方块standard\\俄罗斯方块\\dead.wav"
0,0);
Block_Score();
inputerror..."
ifuwanttoexit,"
textout(handle,50,12,Colors,1,"
pleasepressEscagain"
Sleep(1000);
voidBlock_Intomap(intblock_shape[4][4])//更改地图矩阵
switch(y)
{
case0:
map_shape[y_coordinate+x][x_coordinate+y]=block_shape[x][y];
break;
case1:
case2:
case3:
map_shape[y_coordinate+x][x_coordinate+2*y]=block_shape[x][y];
}
Block_Print(block_shape);
boolBlock_Available(intblock_shape[4][4],intx_move,inty_move)//判断方块能否放下
for(inty=0;
if(block_shape[x][y]==1)
switch(y)
{
case0:
if(map_shape[y_coordinate+y_move+x][x_coordinate+x_move+y]&
&
block_shape[x][y])
return0;
break;
case1:
case2:
case3:
if(map_shape[y_coordinate+y_move+x][x_coordinate+x_move+2*y]&
}
return1;
voidBlock_Birth()//方块生成
intn=rand()%7;
for(intk=0;
for(intj=0;
block_cshape[k][j]=block_shape[n][k][j];
block_newshape[k][j]=block_shape[n][k][j];
}//随机生成方块
if(!
Block_Available(block_cshape,0,0))//判断游戏是否结束
PlaySound("
textout(handle,24,10,BColors,1,"
G"
Sleep(300);
textout(handle,26,10,BColors,1,"
A"
textout(handle,28,10,BColors,1,"
M"
textout(handle,30,10,BColors,1,"
textout(handle,34,10,BColors,1,"
O"
textout(handle,36,10,BColors,1,"
V"
textout(handle,38,10,BColors,1,"
textout(handle,40,10,BColors,1,"