?? hgameview.cpp
字號:
case 5:
NextStatus[0][0] = 1; NextStatus[0][1] = 1; NextStatus[1][0] = 2; NextStatus[1][1] = 1;
NextStatus[2][0] = 0; NextStatus[2][1] = 2; NextStatus[3][0] = 1; NextStatus[3][1] = 2;
break;
case 6:
NextStatus[0][0] = 0; NextStatus[0][1] = 1; NextStatus[1][0] = 0; NextStatus[1][1] = 2;
NextStatus[2][0] = 1; NextStatus[2][1] = 2; NextStatus[3][0] = 2; NextStatus[3][1] = 2;
break;
case 7:
NextStatus[0][0] = 0; NextStatus[0][1] = 1; NextStatus[1][0] = 1; NextStatus[1][1] = 1;
NextStatus[2][0] = 2; NextStatus[2][1] = 1; NextStatus[3][0] = 0; NextStatus[3][1] = 2;
break;
}
}
void CHGAMEView::RectDown()
{
IsBottom();
if (!m_isBottom)
{
//清除以前的方塊
int x1,x2,x3,x4,y1,y2,y3,y4;
x1 = ActiveStatus[0][0];
x2 = ActiveStatus[1][0];
x3 = ActiveStatus[2][0];
x4 = ActiveStatus[3][0];
y1 = ActiveStatus[0][1];
y2 = ActiveStatus[1][1];
y3 = ActiveStatus[2][1];
y4 = ActiveStatus[3][1];
GameStatus[x1][y1]=MAP_STATE_EMPTY;
GameStatus[x2][y2]=MAP_STATE_EMPTY;
GameStatus[x3][y3]=MAP_STATE_EMPTY;
GameStatus[x4][y4]=MAP_STATE_EMPTY;
InvalidateCurrent();
//方塊下落
ActiveStatus[0][0] += 1;
ActiveStatus[1][0] += 1;
ActiveStatus[2][0] += 1;
ActiveStatus[3][0] += 1;
GameStatus[x1+1][y1]=MAP_STATE_NOT_EMPTY;
GameStatus[x2+1][y2]=MAP_STATE_NOT_EMPTY;
GameStatus[x3+1][y3]=MAP_STATE_NOT_EMPTY;
GameStatus[x4+1][y4]=MAP_STATE_NOT_EMPTY;
InvalidateCurrent();
}
}
void CHGAMEView::RectArrow(int m_Type)
{
//獲取當前下墜物4個小方塊的位置坐標
int x1,x2,x3,x4,y1,y2,y3,y4;
x1 = ActiveStatus[0][0];
x2 = ActiveStatus[1][0];
x3 = ActiveStatus[2][0];
x4 = ActiveStatus[3][0];
y1 = ActiveStatus[0][1];
y2 = ActiveStatus[1][1];
y3 = ActiveStatus[2][1];
y4 = ActiveStatus[3][1];
//對不同的移動命令指示進行分類實現
switch(m_Type)
{
case LEFT:
//對每種不同的移動命令指示特性作相應的可移動分析
if ( (ActiveStatus[0][1]>0) && IsLeftLimit() && !m_isBottom)
{
//清原來的方塊
GameStatus[x1][y1]=MAP_STATE_EMPTY;
GameStatus[x2][y2]=MAP_STATE_EMPTY;
GameStatus[x3][y3]=MAP_STATE_EMPTY;
GameStatus[x4][y4]=MAP_STATE_EMPTY;
// InvalidateCurrent();
//添加新的移動后數據狀態
ActiveStatus[0][1] -= 1;
ActiveStatus[1][1] -= 1;
ActiveStatus[2][1] -= 1;
ActiveStatus[3][1] -= 1;
GameStatus[x1][y1-1]=MAP_STATE_NOT_EMPTY;
GameStatus[x2][y2-1]=MAP_STATE_NOT_EMPTY;
GameStatus[x3][y3-1]=MAP_STATE_NOT_EMPTY;
GameStatus[x4][y4-1]=MAP_STATE_NOT_EMPTY;
InvalidateCurrent();
}
break;
case RIGHT:
if ( (ActiveStatus[3][1]< m_iCol-1) && IsRightLitmit() && !m_isBottom)
{
//清原來的方塊
GameStatus[x1][y1]=MAP_STATE_EMPTY;
GameStatus[x2][y2]=MAP_STATE_EMPTY;
GameStatus[x3][y3]=MAP_STATE_EMPTY;
GameStatus[x4][y4]=MAP_STATE_EMPTY;
// InvalidateCurrent();
//添加新的移動后數據狀態
ActiveStatus[0][1] += 1;
ActiveStatus[1][1] += 1;
ActiveStatus[2][1] += 1;
ActiveStatus[3][1] += 1;
GameStatus[x1][y1+1]=MAP_STATE_NOT_EMPTY;
GameStatus[x2][y2+1]=MAP_STATE_NOT_EMPTY;
GameStatus[x3][y3+1]=MAP_STATE_NOT_EMPTY;
GameStatus[x4][y4+1]=MAP_STATE_NOT_EMPTY;
InvalidateCurrent();
}
break;
case DOWN:
RectDown();
break;
}
}
void CHGAMEView::IsBottom()
{
//到底有兩種概念:1是已到底部,2是下面碰到了另外的方塊
int x1,x2,x3,x4;
int x,xx,yy,i;
x1 = ActiveStatus[0][0];
x2 = ActiveStatus[1][0];
x3 = ActiveStatus[2][0];
x4 = ActiveStatus[3][0];
//是否為底部的判斷
//1。到達游戲區域的底部
//2。與接觸面正下方的小方塊區域為被占用狀態
if (x1>=m_iRow-1 || x2>=m_iRow-1 || x3>=m_iRow-1 || x4>=m_iRow-1)
m_isBottom = TRUE;
else
{
for (i=0;i<4;i++)
{
if (InterFace[m_currentRect][i] > -1)
{//取當前下墜物有接觸面的方塊
//獲取有接觸面的小方塊的編號
x=InterFace[m_currentRect][i];
//根據編號獲取ActiveStatus中該小方塊的整下方的坐標
xx=ActiveStatus[x][0]+1;
yy=ActiveStatus[x][1];
//判斷該接觸面整下方的小方塊區域是否為被占用狀態
if (GameStatus[xx][yy]==MAP_STATE_NOT_EMPTY)
m_isBottom = TRUE;
}
}
}
BOOL m_bIsSucced;
int k,j;
int m_iMuch=0; //本次銷掉的行數
//計分規則:一次銷掉一行,加100分,一次銷掉兩行,加400分,三行,900分
//例如銷掉x行,則分數為:x*(x*100)
if (m_isBottom)
{
//判斷是否已得分
for (i=0;i<m_iRow;i++)
{
m_bIsSucced = TRUE;
for (j=0;j<m_iCol;j++)
if (GameStatus[i][j]==MAP_STATE_EMPTY)
m_bIsSucced = FALSE;
//如果得分,則銷掉此行
if (m_bIsSucced)
{
for (k=i;k>0;k--)
for (j=0;j<m_iCol;j++)
GameStatus[k][j] = GameStatus[k-1][j];
//第1行清零
for (j=0;j<m_iCol;j++)
GameStatus[0][j]=MAP_STATE_EMPTY;
m_iMuch += 1;
}
}
if (m_iMuch>0)
{
m_iPerformance += m_iMuch * m_iMuch * 100;
//刷新游戲區域
CRect rect1(m_iStartY, m_iStartX, m_iStartY+300, m_iStartX+360);
//InvalidateRect(&rect1);
//刷新分數區域
CRect rect2(m_iStartY+320, m_iStartX+180, m_iStartY+440, m_iStartX+200);
//InvalidateRect(&rect2);
Invalidate(FALSE);
}
}
}
void CHGAMEView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch(nChar)
{
case VK_LEFT:
RectArrow(LEFT);
break;
case VK_RIGHT:
RectArrow(RIGHT);
break;
case VK_UP:
RectChange();
break;
case VK_DOWN:
RectArrow(DOWN);
break;
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
BOOL CHGAMEView::IsLeftLimit()
{
int x1,x2,x3,x4,y1,y2,y3,y4;
x1 = ActiveStatus[0][0];
x2 = ActiveStatus[1][0];
x3 = ActiveStatus[2][0];
x4 = ActiveStatus[3][0];
y1 = ActiveStatus[0][1];
y2 = ActiveStatus[1][1];
y3 = ActiveStatus[2][1];
y4 = ActiveStatus[3][1];
//根據當前下墜物的具體形態,分析判斷其是否有向左移動的空間
switch(m_currentRect)
{
/*
|
|
| "1"字形形態類型,判斷其四個方塊的正左邊都沒有任何物件(空間沒有被占據)
|
*/
case 1:
if (GameStatus[x1][y1-1] || GameStatus[x2][y2-1] || GameStatus[x3][y3-1] || GameStatus[x4][y4-1])
return FALSE;
break;
case 11:
if (GameStatus[x1][y1-1])
return FALSE;
break;
case 2:
if (GameStatus[x1][y1-1] || GameStatus[x2][y2-1])
return FALSE;
break;
case 3:
if (GameStatus[x1][y1-1] || GameStatus[x2][y2-1])
return FALSE;
break;
case 31:
if (GameStatus[x1][y1-1] || GameStatus[x2][y2-1] || GameStatus[x3][y3-1])
return FALSE;
break;
case 32:
if (GameStatus[x1][y1-1] || GameStatus[x3][y3-1])
return FALSE;
break;
case 33:
if (GameStatus[x1][y1-1] || GameStatus[x2][y2-1] || GameStatus[x4][y4-1])
return FALSE;
break;
case 4:
if (GameStatus[x1][y1-1] || GameStatus[x2][y2-1] || GameStatus[x4][y4-1])
return FALSE;
break;
case 41:
if (GameStatus[x1][y1-1] || GameStatus[x2][y2-1])
return FALSE;
break;
case 5:
if (GameStatus[x1][y1-1] || GameStatus[x2][y2-1] || GameStatus[x3][y3-1])
return FALSE;
break;
case 51:
if (GameStatus[x1][y1-1] || GameStatus[x3][y3-1])
return FALSE;
break;
case 6:
if (GameStatus[x1][y1-1] || GameStatus[x3][y3-1] || GameStatus[x4][y4-1])
return FALSE;
break;
case 61:
if (GameStatus[x1][y1-1] || GameStatus[x2][y2-1])
return FALSE;
break;
case 62:
if (GameStatus[x1][y1-1] || GameStatus[x2][y2-1] || GameStatus[x3][y3-1])
return FALSE;
break;
case 63:
if (GameStatus[x1][y1-1] || GameStatus[x3][y3-1])
return FALSE;
break;
case 7:
if (GameStatus[x1][y1-1] || GameStatus[x2][y2-1] || GameStatus[x3][y3-1])
return FALSE;
break;
case 71:
if (GameStatus[x1][y1-1] || GameStatus[x2][y2-1])
return FALSE;
break;
case 72:
if (GameStatus[x1][y1-1] || GameStatus[x2][y2-1] || GameStatus[x3][y3-1])
return FALSE;
break;
case 73:
if (GameStatus[x1][y1-1] || GameStatus[x4][y4-1])
return FALSE;
break;
}
return TRUE;
}
BOOL CHGAMEView::IsRightLitmit()
{
int x1,x2,x3,x4,y1,y2,y3,y4;
x1 = ActiveStatus[0][0];
x2 = ActiveStatus[1][0];
x3 = ActiveStatus[2][0];
x4 = ActiveStatus[3][0];
y1 = ActiveStatus[0][1];
y2 = ActiveStatus[1][1];
y3 = ActiveStatus[2][1];
y4 = ActiveStatus[3][1];
switch(m_currentRect)
{
case 1:
if (GameStatus[x1][y1+1] || GameStatus[x2][y2+1] || GameStatus[x3][y3+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 11:
if (GameStatus[x4][y4+1])
return FALSE;
break;
case 2:
if (GameStatus[x3][y3+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 3:
if (GameStatus[x2][y2+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 31:
if (GameStatus[x1][y1+1] || GameStatus[x3][y3+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 32:
if (GameStatus[x3][y3+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 33:
if (GameStatus[x2][y2+1] || GameStatus[x3][y3+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 4:
if (GameStatus[x1][y1+1] || GameStatus[x3][y3+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 41:
if (GameStatus[x3][y3+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 5:
if (GameStatus[x2][y2+1] || GameStatus[x3][y3+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 51:
if (GameStatus[x2][y2+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 6:
if (GameStatus[x2][y2+1] || GameStatus[x3][y3+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 61:
if (GameStatus[x2][y2+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 62:
if (GameStatus[x1][y1+1] || GameStatus[x2][y2+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 63:
if (GameStatus[x3][y3+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 7:
if (GameStatus[x2][y2+1] || GameStatus[x3][y3+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 71:
if (GameStatus[x1][y1+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 72:
if (GameStatus[x2][y2+1] || GameStatus[x3][y3+1] || GameStatus[x4][y4+1])
return FALSE;
break;
case 73:
if (GameStatus[x3][y3+1] || GameStatus[x4][y4+1])
return FALSE;
break;
}
return TRUE;
}
void CHGAMEView::RectChange()
{
//先預先變形,然后判斷變形后的方塊是否有空間,如有足夠空間,則進行實際變形,否則不變
int xx1,xx2,xx3,xx4,yy1,yy2,yy3,yy4;
int m_lscurrentRect;
CString lsStr;
int x1,x2,x3,x4,y1,y2,y3,y4;
x1 = ActiveStatus[0][0];
x2 = ActiveStatus[1][0];
x3 = ActiveStatus[2][0];
x4 = ActiveStatus[3][0];
y1 = ActiveStatus[0][1];
y2 = ActiveStatus[1][1];
y3 = ActiveStatus[2][1];
y4 = ActiveStatus[3][1];
//變形后位置在數組中的存放順序仍需遵循先左后右,在同一列中先上后下
xx1=x1; xx2=x2; xx3=x3; xx4=x4; yy1=y1; yy2=y2; yy3=y3; yy4=y4;
switch(m_currentRect)
{
case 1:
xx1=x1+1; yy1=y1-1; xx3=x3-1; yy3=y3+1; xx4=x4-2; yy4=y4+2;
m_lscurrentRect = 11;
break;
case 11:
xx1=x1-1; yy1=y1+1; xx3=x3+1; yy3=y3-1; xx4=x4+2; yy4=y4-2;
m_lscurrentRect = 1;
break;
case 2:
m_lscurrentRect=2;
break;
case 3:
xx1=x1-2; yy1=y1+1; xx4=x4-1; yy4=y4;
m_lscurrentRect = 31;
break;
case 31:
xx1=x1+1; yy1=y1-1;
m_lscurrentRect = 32;
break;
case 32:
xx1=x1+1; yy1=y1; xx4=x4+2; yy4=y4-1;
m_lscurrentRect=33;
break;
case 33:
xx4=x4-1; yy4=y4+1;
m_lscurrentRect=3;
break;
case 4:
xx1=x1+2; yy1=y1-1; xx3=x3+1; yy3=y3-1; xx4=x4-1;
m_lscurrentRect = 41;
break;
case 41:
xx1=x1-2; yy1=y1+1; xx3=x3-1; yy3=y3+1; xx4=x4+1;
m_lscurrentRect = 4;
break;
case 5:
xx1=x1-1; xx2=x2-2; yy2=y2+1; xx3=x3+1; yy4=y4+1;
m_lscurrentRect = 51;
break;
case 51:
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -