回复 11楼 czz5242199
// 消除地图上的方块
public static int[][] removeTiles()
{
int[][] a =
{
{7, 7, 3,
4,
5}, // {0, 1, 0, 0, 0}
{2, 7, 7,
7, 10}, // {0, 1, 1, 1, 0}
{7, 7, 7, 14, 15}, // {1, 1, 1, 0, 0}
{7, 7, 7, 7, 7}
// {1, 1, 1, 1, 1}
};
int[][] b = new int[MAP_HEIGHT][MAP_WIDTH];
// 判断地图的橫向
for (int i = 0; i < MAP_HEIGHT; i++)
{
for (int j = 0; j < MAP_WIDTH; )
{
int runLength = 0;
int runValue = a[i][j];
while ((j + runLength < MAP_WIDTH) && (a[i][j+runLength] == runValue))
{
runLength++;
}
if (runLength >= 3)
{
for (int k = 0; k < runLength; k++)
{
b[i][j+k] = 1;
}
}
j = j + runLength;
}
}
// 判断地图的纵向
for (int i = 0; i < MAP_WIDTH; i++)
{
for (int j = 0; j < MAP_HEIGHT; )
{
int runLength = 0;
int runValue = a[j][i];
while ((j + runLength < MAP_HEIGHT) && (a[j+runLength][i] == runValue))
{
runLength++;
}
if (runLength >= 3)
{
for (int k = 0; k < runLength; k++)
{
b[j+k][i] = 1;
}
}
j = j + runLength;
}
}
// 消除方块
for (int i = 0; i < MAP_HEIGHT; i++)
{
for (int j = 0; j < MAP_WIDTH; j++)
{
if (b[i][j] == 1)
{
if (i == 0)
{
a[i][j] = -1;
}
else
{
for (int k = i; k > 0; k--)
{
a[k][j] = a[k-1][j];
}
a[0][j] = -1;
}
}
}
}
return a;
}
[
本帖最后由 BlueGuy 于 2012-2-18 18:45 编辑 ]