📄 ppgamedoc.cpp
字号:
switch (m_pGameView->m_nDiamond[nRow][nCol][0])
{
case 1:
case 2:
case 3:
case 4:
{
//计算总共有几个相同的钻石
CountSameDiamond(nRow, nCol, m_pGameView->m_nDiamond[nRow][nCol][0]);
if (m_nDiamondCount >= 3)
{
m_pGameView->m_nBrowIndex = 3;
//有三个以上的就把它清除
ClearDiamond(nRow, nCol, m_pGameView->m_nDiamond[nRow][nCol][0]);
m_pGameView->PlaySound(NORMAL_BLAST);
}
}
break;
case 5: // 红炸弹,清除钻石参数就添红钻石的类型
ClearDiamond(1);
//播放爆炸声音, todo..
m_pGameView->PlaySound(BOMB_BLAST);
m_pGameView->m_nBrowIndex = 3;
m_pGameView->m_nDiamond[nRow][nCol][0] = 10;
m_pGameView->m_nDiamond[nRow][nCol][1] = 0;
m_tGameScore.nScore++; //给用户加分
break;
case 6: // 黄炸弹,清除钻石参数就添黄钻石的类型
ClearDiamond(2);
//播放爆炸声音, todo..
m_pGameView->PlaySound(BOMB_BLAST);
m_pGameView->m_nBrowIndex = 3;
m_pGameView->m_nDiamond[nRow][nCol][0] = 10;
m_pGameView->m_nDiamond[nRow][nCol][1] = 0;
m_tGameScore.nScore++; //给用户加分
break;
case 7: // 蓝炸弹,清除钻石参数就添黄钻石的类型
ClearDiamond(3);
//播放爆炸声音, todo..
m_pGameView->PlaySound(BOMB_BLAST);
m_pGameView->m_nBrowIndex = 3;
m_pGameView->m_nDiamond[nRow][nCol][0] = 10;
m_pGameView->m_nDiamond[nRow][nCol][1] = 0;
m_tGameScore.nScore++; //给用户加分
break;
case 8: // 粉炸弹,清除钻石参数就添黄钻石的类型
ClearDiamond(4);
//播放爆炸声音, todo..
m_pGameView->PlaySound(BOMB_BLAST);
m_pGameView->m_nBrowIndex = 3;
m_pGameView->m_nDiamond[nRow][nCol][0] = 10;
m_pGameView->m_nDiamond[nRow][nCol][1] = 0;
m_tGameScore.nScore++; //给用户加分
break;
case 9: // 黑炸弹,清除四周
ClearDiamond(9);
//播放爆炸声音, todo..
m_pGameView->PlaySound(BOMB_BLAST);
m_pGameView->m_nBrowIndex = 3;
m_pGameView->m_nDiamond[nRow][nCol][0] = 10;
m_pGameView->m_nDiamond[nRow][nCol][1] = 0;
m_tGameScore.nScore++; //给用户加分
break;
default:
break;
}
}
void CPPGameDoc::CountSameDiamond(int nRow, int nCol, int nDiamondType)
{
if (nDiamondType == 0)
{
//如果钻石类型是空则不统计
return;
}
else
{
m_nDiamondCount++;
m_pGameView->m_nDiamond[nRow][nCol][2] = 1; //把自已做上已被统计过的标记
if (nRow + 1 != DIAMOND_ROW)
{
if (m_pGameView->m_nDiamond[nRow + 1][nCol][0] == nDiamondType
&& m_pGameView->m_nDiamond[nRow + 1][nCol][2] != 1)
{
CountSameDiamond(nRow + 1, nCol, nDiamondType);
}
}
if (nRow - 1 != -1)
{
if (m_pGameView->m_nDiamond[nRow - 1][nCol][0] == nDiamondType
&& m_pGameView->m_nDiamond[nRow - 1][nCol][2] != 1)
{
CountSameDiamond(nRow - 1, nCol, nDiamondType);
}
}
if (nCol + 1 != DIAMOND_COL)
{
if (m_pGameView->m_nDiamond[nRow][nCol + 1][0] == nDiamondType
&& m_pGameView->m_nDiamond[nRow][nCol + 1][2] != 1)
{
CountSameDiamond(nRow, nCol + 1, nDiamondType);
}
}
if (nCol - 1 != -1)
{
if (m_pGameView->m_nDiamond[nRow][nCol - 1][0] == nDiamondType
&& m_pGameView->m_nDiamond[nRow][nCol - 1][2] != 1)
{
CountSameDiamond(nRow, nCol - 1, nDiamondType);
}
}
// 还原原数据
m_pGameView->m_nDiamond[nRow][nCol][2] = 0;
}
}
void CPPGameDoc::ClearDiamond(int nRow, int nCol, int nDiamondType)
{
//将人物表情置为爆炸
// todo..
if (nDiamondType == 0)
{
//如果是空格则不统计
return;
}
else
{
m_pGameView->m_nDiamond[nRow][nCol][0] = 10;// 爆炸
m_pGameView->m_nDiamond[nRow][nCol][1] = 0;// 爆炸的第一张图
m_pGameView->m_nDiamond[nRow][nCol][2] = 1; //把自已做上已被统计过的标记
m_tGameScore.nScore++; //给玩家加分
if (nRow + 1 != DIAMOND_ROW)
{
if (m_pGameView->m_nDiamond[nRow + 1][nCol][0] == nDiamondType
&& m_pGameView->m_nDiamond[nRow + 1][nCol][2] != 1)
{
ClearDiamond(nRow + 1, nCol, nDiamondType);
}
}
if (nRow - 1 != -1)
{
if (m_pGameView->m_nDiamond[nRow - 1][nCol][0] == nDiamondType
&& m_pGameView->m_nDiamond[nRow - 1][nCol][2] != 1)
{
ClearDiamond(nRow - 1, nCol, nDiamondType);
}
}
if (nCol + 1 != DIAMOND_COL)
{
if (m_pGameView->m_nDiamond[nRow][nCol + 1][0] == nDiamondType
&& m_pGameView->m_nDiamond[nRow][nCol + 1][2] != 1) {
ClearDiamond(nRow, nCol + 1, nDiamondType);
}
}
if (nCol - 1 != -1)
{
if (m_pGameView->m_nDiamond[nRow][nCol - 1][0] == nDiamondType
&& m_pGameView->m_nDiamond[nRow][nCol - 1][2] != 1)
{
ClearDiamond(nRow, nCol - 1, nDiamondType);
}
}
m_pGameView->m_nDiamond[nRow][nCol][2] = 0;
}
}
void CPPGameDoc::ClearDiamond(int nDiamondType)
{
//将人物表情置为爆炸, todo..
if (nDiamondType == 9)// 处理黑炸弹
{
int nRow = m_pGameView->GetSelectXPoint();
int nCol = m_pGameView->GetSelectYPoint();
for (int i = nRow - 1; i <= nRow + 1; i++)
{
for (int j = nCol - 1; j <= nCol + 1; j++)
{
if (i < 0 || j < 0 || i > 9 || j > 8)
{
continue;
}
else
{
if (m_pGameView->m_nDiamond[i][j][0] != 10
&& m_pGameView->m_nDiamond[i][j][0] != 0)
{
m_pGameView->m_nDiamond[i][j][0] = 10;
m_pGameView->m_nDiamond[i][j][1] = 0;
m_tGameScore.nScore++; //给玩家加分
}
}
}
}
}
else
{
for (int nRow = 0; nRow < DIAMOND_ROW; nRow++)
{
for (int nCol = 0; nCol < DIAMOND_COL; nCol++)
{
if (m_pGameView->m_nDiamond[nRow][nCol][0] == nDiamondType)
{
m_pGameView->m_nDiamond[nRow][nCol][0] = 10;
m_pGameView->m_nDiamond[nRow][nCol][1] = 0;
m_tGameScore.nScore++; //给玩家加分
}
}
}
}
}
void CPPGameDoc::MoveDiamond()
{
for (int nCol = 0; nCol < DIAMOND_COL; nCol++)
{
for (int nRow = 0; nRow < DIAMOND_ROW - 1; nRow++)
{
if (m_pGameView->m_nDiamond[nRow + 1][nCol][0] == 0)
{
m_pGameView->m_nDiamond[nRow + 1][nCol][0] = m_pGameView->m_nDiamond[nRow][nCol][0];
m_pGameView->m_nDiamond[nRow + 1][nCol][1] = m_pGameView->m_nDiamond[nRow][nCol][1];
m_pGameView->m_nDiamond[nRow][nCol][0] = 0;
m_pGameView->m_nDiamond[nRow][nCol][1] = 0;
}
}
}
}
boolean CPPGameDoc::IsExitTimer()
{
return m_bExitTimer;
}
void CPPGameDoc::SetExitTimer(boolean bExit)
{
m_bExitTimer = bExit;
}
void CPPGameDoc::ReleaseView()
{
if (m_pLogoView)
{
m_pLogoView->FreeResourse();
delete m_pLogoView;
m_pLogoView = NULL;
}
if (m_pMenuView)
{
m_pMenuView->FreeResourse();
delete m_pMenuView;
m_pMenuView = NULL;
}
if (m_pAboutView)
{
m_pAboutView->FreeResourse();
delete m_pAboutView;
m_pAboutView = NULL;
}
if (m_pGameView)
{
m_pGameView->FreeResourse();
delete m_pGameView;
m_pGameView = NULL;
}
if (m_pHelpView)
{
m_pHelpView->FreeResourse();
delete m_pHelpView;
m_pHelpView = NULL;
}
if (m_pOptView)
{
m_pOptView->FreeResourse();
delete m_pOptView;
m_pOptView = NULL;
}
if (m_pOverView)
{
delete m_pOverView;
m_pOverView = NULL;
}
}
int CPPGameDoc::GetDataIndex(int nData)
{
int nIndex = 0;
switch(nData)
{
case 1:
nIndex = 156;
break;
case 2:
nIndex = 162;
break;
case 3:
nIndex = 168;
break;
case 4:
nIndex = 174;
break;
case 5:
nIndex = 180;
break;
case 6:
nIndex = 186;
break;
case 7:
nIndex = 192;
break;
case 8:
nIndex = 198;
break;
case 9:
nIndex = 204;
break;
case 0:
nIndex = 210;
break;
default:
nIndex = 0;
break;
}
return nIndex;
}
void CPPGameDoc::GetSingleData(int nData)
{
int nSrcData = nData;
int nTempData = 0;
int i = 0;
for (i = 4 ; i >= 0; i--)
{
nTempData = nSrcData % 10;
nSrcData = nSrcData / 10;
}
}
boolean CPPGameDoc::AddDemoDiamond()
{
// 如果到了300ms,就取一颗新钻石,放入底层
if (m_nDemoDiamondIndex == 64 || m_nDemoKeyIndex == 37)
{
m_pGameView->ExitView(ID_VIEW_MENU);
return false;
}
if (m_pGameView->GetTimeCount() == 8)
{
if (m_pGameView->m_nCurCol < 9)
{
//将钻石类形存入数组
m_pGameView->m_nNewLine[m_pGameView->m_nCurCol][0]
= m_pGameView->m_nDemoDiamondType[m_nDemoDiamondIndex];
switch (m_pGameView->m_nDemoDiamondType[m_nDemoDiamondIndex])
{
case 1:
case 2:
case 3:
case 4:
m_pGameView->m_nNewLine[m_pGameView->m_nCurCol][1]
= m_pGameView->m_nDemoDiamondType[m_nDemoDiamondIndex] - 1;
break;
case 5:
m_pGameView->m_nNewLine[m_pGameView->m_nCurCol][1] = 4;
break;
case 6:
m_pGameView->m_nNewLine[m_pGameView->m_nCurCol][1] = 7;
break;
case 7:
m_pGameView->m_nNewLine[m_pGameView->m_nCurCol][1] = 10;
break;
case 8:
m_pGameView->m_nNewLine[m_pGameView->m_nCurCol][1] = 13;
break;
case 9:
m_pGameView->m_nNewLine[m_pGameView->m_nCurCol][1] = 16;
break;
}
m_pGameView->m_nCurCol++;
m_nDemoDiamondIndex++;
}
else
{
int i = 0;
int j = 0;
for (i = 1; i < DIAMOND_ROW; i++)
{
for (j = 0; j < DIAMOND_COL; j++)
{
m_pGameView->m_nDiamond[i-1][j][0] = m_pGameView->m_nDiamond[i][j][0];
m_pGameView->m_nDiamond[i-1][j][1] = m_pGameView->m_nDiamond[i][j][1];
m_pGameView->m_nDiamond[i-1][j][2] = m_pGameView->m_nDiamond[i][j][2];
if (i == 9)
{
m_pGameView->m_nDiamond[9][j][0] = m_pGameView->m_nNewLine[j][0];
m_pGameView->m_nDiamond[9][j][1] = m_pGameView->m_nNewLine[j][1];
m_pGameView->m_nDiamond[9][j][2] = m_pGameView->m_nNewLine[j][2];
m_pGameView->m_nNewLine[j][0] = 0;
m_pGameView->m_nNewLine[j][1] = -1;
m_pGameView->m_nNewLine[j][2] = 0;
}
}
}
m_pGameView->m_nCurCol = 0;
m_pGameView->SetDiamondLine();
m_pGameView->SetAllRedrawStatus(true);
}
}
return true;
}
void CPPGameDoc::HandleDemoKey(EKEYCODE eKey)
{
int nCurPointY = m_pGameView->GetSelectYPoint();// 当前Y坐标
int nCurPointX = m_pGameView->GetSelectXPoint();// 当前X坐标
if (eKey == EKEY_UP)// 上
{
if (nCurPointX == 0)// 已经到最上层
{
nCurPointX = 9;
}
else
{
nCurPointX = nCurPointX - 1;// 否则向上移一
}
// 重新设置坐标
m_pGameView->SetSelectXPoint((int16)nCurPointX);
m_pGameView->SetSelectMoveSta(true);
}
if (eKey == EKEY_DOWN)//下
{
if (nCurPointX == 9)// 已经到最下层
nCurPointX = 0;
else
nCurPointX = nCurPointX + 1;// 否则向下移一
// 重新设置坐标
m_pGameView->SetSelectXPoint((int16)nCurPointX);
m_pGameView->SetSelectMoveSta(true);
}
if (eKey == EKEY_LEFT)//左
{
if (nCurPointY == 0)// 已经到最左边
nCurPointY = 8;
else
nCurPointY = nCurPointY - 1;// 否则向左移一
// 重新设置坐标
m_pGameView->SetSelectYPoint((int16)nCurPointY);
m_pGameView->SetSelectMoveSta(true);
}
if (eKey == EKEY_RIGHT)// 右
{
if (nCurPointY == 9)// 已经到最右边
nCurPointY = 0;
else
nCurPointY = nCurPointY + 1;// 否则向右移一
// 重新设置坐标
m_pGameView->SetSelectYPoint((int16)nCurPointY);
m_pGameView->SetSelectMoveSta(true);
}
// 判断选择键
if (eKey == EKEY_SELECT)
{
// 按下选择键,判断周围钻石是否可爆炸
HandleSelectDiamond();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -