?? ground.java
字號:
import javax.microedition.lcdui.Graphics;
public class Ground
{
private int[][] obstacles =
new int[GamePanel.WIDTH][GamePanel.HEIGHT];
public void accept(Shape shape)
{
for(int x=0; x<4; x++)
{
for(int y=0; y<4; y++)
{
if(shape.isMember(x, y, false))
{
obstacles[shape.getLeft()+x][shape.getTop()+y] = 1;
}
}
}
deleteFullLine();
}
private void deleteFullLine()
{
for(int y=GamePanel.HEIGHT-1; y>=0; y--)
{ //先從最下面一行開始
boolean isFull = true;
for(int x=0; x<GamePanel.WIDTH; x++)
{
if(obstacles[x][y] == 0){
isFull = false;
break;
}
}
if(isFull){
deleteLine( y );
y++;
}
}
}
private void deleteLine(int lineNum)
{
for(int y=lineNum; y>0; y--)
{
for(int x=0; x<GamePanel.WIDTH; x++)
{
obstacles[x][y] = obstacles[x][y-1];
}
}
for(int x=0; x<GamePanel.WIDTH; x++)
{
obstacles[x][0] = 0;
}
}
public void paint(Graphics g)
{
g.setColor(0x0000FF);
for(int x=0; x<GamePanel.WIDTH; x++)
{
for(int y=0; y<GamePanel.HEIGHT; y++)
{
if(obstacles[x][y] == 1)
{
g.fillRoundRect(x*Shape.CELL_SIZE, y*Shape.CELL_SIZE,
Shape.CELL_SIZE, Shape.CELL_SIZE, 5, 5);
}
}
}
}
public boolean isMoveable(Shape shape, int action)
{
int left = shape.getLeft();//保留下次移動之前的left
int top = shape.getTop();//保留下次移動之前的top
switch(action)//根據狀態,進行假設移動
{
case Shape.LEFT:
left--;
break;
case Shape.RIGHT:
left++;
break;
case Shape.DOWN:
top++;
break;
}
for(int x=0; x<4; x++)
{
for(int y=0; y<4; y++)
{
//需要獲取當前格是1的標志再做判斷
if(shape.isMember(x, y, action==Shape.ROTATE))
{
if ( (y+top >= GamePanel.HEIGHT) ||
(x+left >= GamePanel.WIDTH) ||
(x+left < 0) ||
(obstacles[x+left][y+top] == 1)
)
{
return false;
}
}
}
}
return true;
}
public boolean isFull()
{
for(int x=0; x<GamePanel.WIDTH; x++)
{
if(obstacles[x][0] == 1)
return true;
}
return false;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -