?? gameworld.java~1~
字號:
{
hitted = true;
nowX = preX;
nowY = preY;
hittedI = i;
hittedJ = j;
break;
}
}
return;
}
}
}
} //for(int i = 0;i < 10; i ++)
}
private boolean checkDisappear()
{
int sameColorCount = 0;
for(int i = 0;i < 10;i ++)
if(i % 2 == 0)
{
for(int j = 0 ;j < 8 ;j ++)
if(roundPara[i][j] > 8 && roundPara[i][j] < 17)
sameColorCount ++;
}
else if(i % 2 == 1)
{
for(int j = 0;j < 7;j ++)
if(roundPara[i][j] > 8 && roundPara[i][j] < 17)
sameColorCount ++;
}
if(sameColorCount >= 3)
{
score += sameColorCount;
disappearCount = 5;
/*
for(int i = 0;i < 10;i ++)
{
for(int j = 0;j < (i % 2 == 0 ? 8 : 7);j ++)
{
if(roundPara[i][j] > 8 && roundPara[i][j] < 17)
roundPara[i][j] = 0;
}
}
*/
return true;
}
for(int i = 0;i < 10;i ++)
{
for(int j = 0;j < (i % 2 == 0 ? 8 : 7);j ++)
{
if(roundPara[i][j] > 8 && roundPara[i][j] < 17)
roundPara[i][j] -= 8;
}
}
return false;
}
private void checkConnect(int x,int y,int color) //let all round have the same color disappear
{
if(x == 10 && haveNoSameRound(x,y,color))
{
overThread = true;
return;
}
if(roundPara[x][y] == color)
roundPara[x][y] += 8;
if(haveNoSameRound(x,y,color))
return;
else
{
if(x == 9)
{
if(y == 0)
{
if(roundPara[9][1] == color)
checkConnect(9,1,color);
if(roundPara[8][1] == color)
checkConnect(8,1,color);
if(roundPara[8][2] == color)
checkConnect(8,2,color);
}
else if(y == 6)
{
if(roundPara[9][7] == color)
checkConnect(10,6,color);
if(roundPara[8][6] == color)
checkConnect(8,6,color);
}
else
{
if(roundPara[8][y] == color)
checkConnect(8,y,color);
if(roundPara[8][y + 1] == color)
checkConnect(8,y + 1,color);
if(roundPara[9][y - 1] == color)
checkConnect(9,y - 1,color);
if(roundPara[9][y + 1] == color)
checkConnect(9,y + 1,color);
if(roundPara[10][y] == color)
checkConnect(10,y,color);
if(roundPara[10][y + 1] == color)
checkConnect(10,y + 1,color);
}
} //if(x == 10)
else if(x == 0) //the first row
{
if(y == 0)
{
if(roundPara[0][1] == color)
checkConnect(0,1,color);
if(roundPara[1][0] == color)
checkConnect(1,0,color);
}
else if(y == 7)
{
if(roundPara[0][6] == color)
checkConnect(0,6,color);
if(roundPara[1][6] == color)
checkConnect(1,6,color);
}
else
{
if(roundPara[x][y - 1] == color)
checkConnect(x,y - 1,color);
if(roundPara[x][y + 1] == color)
checkConnect(x,y + 1,color);
if(roundPara[x + 1][y - 1] == color)
checkConnect(x + 1,y - 1,color);
if(roundPara[x + 1][y] == color)
checkConnect(x + 1,y,color);
}
}
else if(y == 0)
{
if(x % 2 == 1)
{
if(roundPara[x - 1][y] == color)
checkConnect(x - 1,y,color);
if(roundPara[x - 1][y + 1] == color)
checkConnect(x- 1,y + 1,color);
if(roundPara[x][y + 1] == color)
checkConnect(x,y + 1,color);
if(roundPara[x + 1][y] == color)
checkConnect(x + 1,y,color);
if(roundPara[x + 1][y + 1] == color)
checkConnect(x + 1,y + 1,color);
}
else if(x % 2 == 0)
{
if(roundPara[x - 1][y] == color)
checkConnect(x - 1,y,color);
if(roundPara[x][y + 1] == color)
checkConnect(x, y + 1,color);
if(roundPara[x + 1][y] == color)
checkConnect(x + 1,y ,color);
}
}
else if(y == 6 && x % 2 == 1)
{
if(roundPara[x - 1][y] == color)
checkConnect(x - 1,y,color);
if(roundPara[x - 1][y + 1] == color)
checkConnect(x - 1,y + 1,color);
if(roundPara[x][y - 1] == color)
checkConnect(x,y - 1,color);
if(roundPara[x + 1][y] == color)
checkConnect(x + 1,y,color);
if(roundPara[x + 1][y + 1] == color)
checkConnect(x + 1,y + 1,color);
}
else if(y == 7 && x % 2 == 0)
{
if(roundPara[x - 1][y - 1] == color)
checkConnect(x - 1,y - 1,color);
if(roundPara[x][y - 1] == color)
checkConnect(x,y - 1,color);
if(roundPara[x + 1][y - 1] == color)
checkConnect(x + 1,y - 1,color);
}
else
{
if(x % 2 == 0)
{
if(roundPara[x - 1][y] == color)
checkConnect(x - 1,y,color);
if(roundPara[x - 1][y - 1] == color)
checkConnect(x - 1,y - 1,color);
if(roundPara[x][y - 1] == color)
checkConnect(x,y - 1,color);
if(roundPara[x][y + 1] == color)
checkConnect(x,y + 1,color);
if(roundPara[x + 1][y] == color)
checkConnect(x + 1,y,color);
if(roundPara[x + 1][y - 1] == color)
checkConnect(x + 1,y - 1,color);
}
else if(x % 2 == 1)
{
if(roundPara[x - 1][y] == color)
checkConnect(x - 1,y,color);
if(roundPara[x - 1][y + 1] == color)
checkConnect(x - 1,y + 1,color);
if(roundPara[x][y - 1] == color)
checkConnect(x,y - 1,color);
if(roundPara[x][y + 1] == color)
checkConnect(x,y + 1,color);
if(roundPara[x + 1][y] == color)
checkConnect(x + 1,y,color);
if(roundPara[x + 1][y + 1] == color)
checkConnect(x + 1,y + 1,color);
}
}
}
//
}
private void checkFall()
{
int color;
for(int i = 0;i < 10;i ++) //have no connectting with the top wall
{
if(i % 2 == 0)
{
for(int j = 0;j < 8 ;j ++)
{
color = roundPara[i][j];
if(roundPara[i][j] > 0 && roundPara[i][j] < 9 && !connectWithTopWall(i,j))
{
fallingNum ++;
score ++;
roundPara[i][j] = 0;
fallingPara[fallingNum - 1][0] = color;
fallingPara[fallingNum - 1][1] = 16 * j + 8;
fallingPara[fallingNum - 1][2] = 14 * i + 8;
}
for(int x = 0;x < 10;x ++)
{
for(int y = 0;y < (x % 2 == 0 ? 8 : 7);y ++)
if(roundPara[x][y] > 16 && roundPara[x][y] < 25)
roundPara[x][y] = roundPara[x][y] - 16;
}
}
}
else if(i % 2 == 1)
{
for(int j = 0;j < 7;j ++)
{
color = roundPara[i][j];
if(roundPara[i][j] > 0 && roundPara[i][j] < 9 && !connectWithTopWall(i,j))
{
fallingNum ++;
score ++;
roundPara[i][j] = 0;
fallingPara[fallingNum - 1][0] = color;
fallingPara[fallingNum - 1][1] = 16 * j + 8;
fallingPara[fallingNum - 1][2] = 14 * i + 8;
}
for(int x = 0;x < 10;x ++)
{
for(int y = 0;y < (x % 2 == 0 ? 8 : 7);y ++)
if(roundPara[x][y] > 16 && roundPara[x][y] < 25)
roundPara[x][y] = roundPara[x][y] - 16;
}
}
}
} //for(int i = 1;i < 10;i ++)
for(int m = 0;m < 10;m ++)
{
for(int n = 0;n < (m % 2 == 0 ? 8 : 7);n ++)
System.out.print(roundPara[m][n]);
}
}
private boolean connectWithTopWall(int i,int j)
{
if(i == 0 && roundPara[i][j] > 0 && roundPara[i][j] < 9)
return true;
else if(roundPara[i][j] > 0 && roundPara[i][j] < 9)
{
roundPara[i][j] += 16;
if(i == 9)
{
if(j == 0)
{
if(connectWithTopWall(8,0) || connectWithTopWall(8,1) || connectWithTopWall(9,1))
return true;
}
else if(j == 6)
{
if(connectWithTopWall(8,6) || connectWithTopWall(8,7) || connectWithTopWall(9,5))
return true;
}
else if(connectWithTopWall(9,j - 1) || connectWithTopWall(9,j + 1)
||connectWithTopWall(8,j) || connectWithTopWall(8,j + 1))
return true;
}
else if(i == 0)
{
}
else if(j == 0)
{
if(i % 2 == 1)
{
if(connectWithTopWall(i - 1,j + 1) || connectWithTopWall(i - 1,j)
||connectWithTopWall(i,j + 1)
||connectWithTopWall(i + 1,j + 1) || connectWithTopWall(i + 1,j))
return true;
}
else if(i % 2 == 0)
{
if(connectWithTopWall(i - 1,j)
|| connectWithTopWall(i,j + 1) ||
connectWithTopWall(i + 1,j))
return true;
}
}
else if(j == 6 && i % 2 == 1)
{
if(connectWithTopWall(i - 1,j) || connectWithTopWall(i - 1,j + 1)
|| connectWithTopWall(i,j - 1)
|| connectWithTopWall(i + 1,j) || connectWithTopWall(i + 1,j + 1))
return true;
}
else if(j == 7 && i % 2 == 0)
{
if(connectWithTopWall(i,j - 1)
|| connectWithTopWall(i - 1,j - 1)
|| connectWithTopWall(i + 1,j - 1))
return true;
}
else
{
if(i % 2 == 0)
{
if(connectWithTopWall(i - 1,j - 1)|| connectWithTopWall(i - 1,j)
|| connectWithTopWall(i, j - 1) || connectWithTopWall(i, j + 1)
|| connectWithTopWall(i + 1,j - 1) || connectWithTopWall(i + 1, j))
return true;
}
else if(i % 2 == 1)
{
if(connectWithTopWall(i - 1,j) || connectWithTopWall(i - 1,j + 1)
|| connectWithTopWall(i, j - 1) || connectWithTopWall(i,j + 1)
|| connectWithTopWall(i + 1,j) || connectWithTopWall(i + 1,j + 1))
return true;
}
}
return false;
}
else return false;
}
private boolean haveNoSameRound(int x,int y,int color)
{
if(x == 10)
{
if(roundPara[9][y - 1] == color || roundPara[9][y] == color)
return false;
}
else if(x == 0) //the first row
{
if(y == 0)
{
if(roundPara[0][1] == color || roundPara[1][0] == color)
return false;
}
else if(y == 7)
{
if(roundPara[0][6] == color || roundPara[1][6] == color)
return false;
}
else if(roundPara[0][y - 1] == color || roundPara[0][y + 1] == color
|| roundPara[1][y] == color || roundPara[1][y - 1] == color)
return false;
}
else if(y == 0)
{
if(x % 2 == 1)
{
if(roundPara[x - 1][y] == color || roundPara[x - 1][y + 1] == color || roundPara[x][y + 1] == color
||roundPara[x + 1][y] == color || roundPara[x + 1][y + 1] == color)
return false;
}
else if(x % 2 == 0)
{
if(roundPara[x - 1][y] == color || roundPara[x][y + 1] == color || roundPara[x + 1][y] == color)
return false;
}
}
else if(y == 6 && x % 2 == 1)
{
if(roundPara[x][y - 1] == color || roundPara[x - 1][y] == color || roundPara[x - 1][y + 1] == color
||roundPara[x + 1][y] == color || roundPara[x + 1][y + 1] == color)
return false;
}
else if(y == 7 && x % 2 == 0)
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -