📄 map.cpp
字号:
{
return g_level+3;
}
if(m_score>=LEV3)
{
return g_level+2;
}
if(m_score>=LEV2)
{
return g_level+1;
}
return g_level+0;
}
/********************************************************************
函数名 : AddSpeed
输入参数: 无
输出参数: 无
功能描述:
速度判断
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::AddSpeed()
{
switch(m_level)
{
case 1:
m_speed=2000;
break;
case 2:
m_speed=1500;
break;
case 3:
m_speed=1000;
break;
case 4:
m_speed=800;
break;
case 5:
m_speed=600;
break;
case 6:
m_speed=500;
break;
case 7:
m_speed=400;
break;
case 8:
m_speed=300;
break;
case 9:
m_speed=200;
break;
default:
m_speed=100;
}
if(m_type==1)
{
KillTimer(m_hWnd,1);
SetTimer(m_hWnd,1,m_speed,TimerProc);
}
else
{
KillTimer(m_hWnd,2);
SetTimer(m_hWnd,2,m_speed,TimerProc);
}
}
/********************************************************************
函数名 : GoLeft
输入参数: 无
输出参数: 无
功能描述:
向左移
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::GoLeft(CELSTILE *_tile)
{
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
if(_tile->m_struct[i][j]==1)
{
if(m_x+j<=0)return ;
if(m_map[m_y+i][m_x+j-1]==1)return ;
}
}
m_x--;
if(false==IsAttack(_tile))
{
}
else
{
DoAttack(_tile);
}
}
/********************************************************************
函数名 : GoRight
输入参数: _tile 方块指指
输出参数: 无
功能描述:
向右移
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::GoRight(CELSTILE *_tile)
{
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
if(_tile->m_struct[i][j]==1)
{
if(m_x+j>=9)return ;
if(m_map[m_y+i][m_x+j+1]==1)return ;
}
}
m_x++;
if(false==IsAttack(_tile))
{
}
else
{
DoAttack(_tile);
}
}
/********************************************************************
函数名 : DoAttack
输入参数: _tile 方块指指
输出参数: 无
功能描述:
处理碰撞
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::DoAttack(CELSTILE *_tile)
{
if(m_type==1)
{
SetTimer(m_hWnd,7,50,TimerProc);
}
else
{
SetTimer(m_hWnd,8,50,TimerProc);
}
m_cancon=false;
m_sound->Play();
//-----------如果碰撞了-------------
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
if(_tile->m_struct[i][j]==1)
{
m_map[m_y+i][m_x+j]=_tile->m_struct[i][j];
}
}
return;
}
/********************************************************************
函数名 : DoXiaoAni
输入参数: 无
输出参数: 无
功能描述:
消行处理
全局变量: 无
调用模块: 无
********************************************************************/
bool CMAP::DoXiaoAni()
{
//------------如果需要消行-------------
xiaorownum=0;//一次消几行
for(int i2=0;i2<4;i2++)
{
bool result=true;
for(int j=0;j<10;j++)
{
if(m_map[m_y+i2][j]!=1)
{
result=false;
break;
}
}
//------------消行处理------------------
if(result==true)
{
xiaorownum++;
//--------------落行处理---------------
m_sound2->Play();
for(int i3=m_y+i2;i3>0;i3--)
{
for(int j=0;j<10;j++)
{
m_map[i3][j]=m_map[i3-1][j];
}
}
}
}
//-------------得分判断------------------
switch(xiaorownum)
{
case 1:
m_score+=100;
break;
case 2:
m_score+=250;
break;
case 3:
m_score+=400;
break;
case 4:
m_score+=600;
break;
}
if(xiaorownum>1)
{
m_addrow=true;
}
//-----------等级判断------------------
m_level=AddLevel();
//-----------速度判断------------------
AddSpeed();
//-----------回到顶端------------------
m_Isdown=false;
//--------------------------------------
for(int i5=19;i5>=0;i5--)
for(int j=0;j<10;j++)
{
if(m_map[i5][j]==1)
{
m_nowrow=i5;
}
}
//----------如果结束了-----------------
if((m_nowrow)<=0)
{
m_finish=true;
if(m_type==1)
{g_row1=19;
for(int j=0;j<10;j++)
{
m_map[g_row1][j]=1;
}
SetTimer(m_hWnd,3,100,TimerProc);
}
else
{g_row2=19;
for(int j=0;j<10;j++)
{
m_map[g_row2][j]=1;
}
SetTimer(m_hWnd,4,100,TimerProc);
}
}
return true;
}
/********************************************************************
函数名 : RotateTile
输入参数: _tile 方块指针
输出参数: 无
功能描述:
转动方块
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::RotateTile(CELSTILE *_tile)
{
m_testtile=*_tile;
//--------防止转动后进入地图其里-------
if(m_testtile.Rotate()==true)
{
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
if(m_testtile.m_struct[i][j]==1)
{
if(m_map[m_y+i][m_x+j]==1)
return ;
}
}
}
//================
if(_tile->Rotate()==true)
{
DoGood();
if(true==IsAttack(_tile))
{
DoAttack(_tile);
}
}
}
/********************************************************************
函数名 : GoTop
输入参数: _tile 方块指针
输出参数: 无
功能描述:
回到顶端
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::GoTop(CELSTILE *_tile)
{
m_thistile=_tile;
m_x=3;
for(int i=3;i>=0;i--)
for(int j=0;j<4;j++)
{
if(m_thistile->m_struct[i][j]==1)
{
m_y=0-i;
}
}
}
/********************************************************************
函数名 : GoFinish1
输入参数: 无
输出参数: 无
功能描述:
结束动画
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::GoFinish1()
{
if(Go12==false)
{
for(int j=0;j<10;j++)
{
m_map[g_row1][j]=1;
}
if(g_row1==0)
{
Go12=true;
for(int j1=0;j1<10;j1++)
{
m_map[0][j1]=0;
}
}
}
else
{
for(int j=0;j<10;j++)
{
m_map[g_row1][j]=0;
}
if(g_row1==18)
{
KillTimer(m_hWnd,3);
for(int j1=0;j1<10;j1++)
{
m_map[19][j1]=0;
}
g_row1=19;
}
}
}
/********************************************************************
函数名 : GoFinish2
输入参数: 无
输出参数: 无
功能描述:
结束动画
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::GoFinish2()
{
if(Go22==false)
{
for(int j=0;j<10;j++)
{
m_map[g_row2][j]=1;
}
if(g_row2==0)
{
Go22=true;
for(int j1=0;j1<10;j1++)
{
m_map[0][j1]=0;
}
}
}
else
{
for(int j=0;j<10;j++)
{
m_map[g_row2][j]=0;
}
if(g_row2==18)
{
KillTimer(m_hWnd,4);
for(int j1=0;j1<10;j1++)
{
m_map[19][j1]=0;
}
g_row2=19;
}
}
}
/********************************************************************
函数名 : DoGood
输入参数: 无
输出参数: 无
功能描述:
进行修正
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::DoGood()
{
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
if(m_thistile->m_struct[i][j]==1)
{
if(m_x+j<0)m_x+=0-m_x-j;
if(m_x+j>9)m_x-=m_x+j-9;
if(m_y+i<0)m_y+=0-m_y-i;
}
}
}
/********************************************************************
函数名 : SetNext
输入参数: _tile 方块指针
输出参数: 无
功能描述:
设置下一个方块组合
全局变量: 无
调用模块: 无
********************************************************************/
void CMAP::SetNext(CELSTILE *_tile)
{
m_lasttile=_tile;
}
/********************************************************************
函数名 : TimerProc
输入参数: hWnd:窗口
nMsg:信息ID
nTimerid:TIMERID
dwTime:时间
输出参数: 无
功能描述:
定时器
全局变量: 无
调用模块: 无
********************************************************************/
void CALLBACK TimerProc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime)
{
switch(nTimerid)
{
case 1:
Go1=true;
break;
case 2:
Go2=true;
break;
case 3:
if(Go12==false)
{
if(g_row1>0)
{
g_row1--;
}
}
else
{
if(g_row1<=18)
{
g_row1++;
}
if(g_row1==19)
{
Go12=false;
}
}
break;
case 4:
if(Go22==false)
{
if(g_row2>0)
{
g_row2--;
}
}
else
{
if(g_row2<=18)
{
g_row2++;
}
if(g_row2==19)
{
Go22=false;
}
}
break;
case 7:
Isshow=!Isshow;
if(g_count==5)
{
Go3=true;
}
g_count--;
if(g_count==0)
{
Isshow=true;
KillTimer(hWnd,7);
g_count=5;
}
break;
case 8:
Isshow2=!Isshow2;
if(g_count2==5)
{
Go4=true;
}
g_count2--;
if(g_count2==0)
{
Isshow2=true;
KillTimer(hWnd,8);
g_count2=5;
}
break;
case 11:
g_bToButtom=true;
break;
case 12:
g_bToButtom2=true;
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -