int test::Check(int x, int y)
{
m_delete[x][y] = true;//表示相邻对象是一类
int nLeft = 0;
if (x > 0)
{
// 检查左边
// 如果左边的颜色和自己的一样, 并且左边还没有被标记
if ((false == m_delete[x-1][y]) && (m_nValue[x-1][y] == m_nValue[x][y]))
{
m_delete[x-1][y] = true; //
nLeft = Check(x-1,y);
}
}
int nRight = 0;
if (x < __X__)
{
// 检查右边
if ((false == m_delete[x+1][y]) && (m_nValue[x+1][y] == m_nValue[x][y]))
{
m_delete[x+1][y] = true;
nRight = Check(x+1,y);
}
}
int nDown = 0;
if (y > 0)
{
// 检查下边
if ((false == m_delete[x][y-1]) && (m_nValue[x][y-1] == m_nValue[x][y]))
{
m_delete[x][y-1] = true;
nDown = Check(x,y-1);
}
}
int nUp = 0;
if (y < __Y__)
{
// 检查上面
if ((false == m_delete[x][y+1]) && (m_nValue[x][y+1] == m_nValue[x][y]))
{
m_delete[x][y+1] = true;
nUp = Check(x,y+1);
}
}
return nLeft + nRight + nDown + nUp + 1; //如果为1,表示正常模式,不用消除
}
消除游戏之消除算法
最新推荐文章于 2024-01-03 11:22:39 发布