//package BallGame;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.TiledLayer;
/**
* <strong>FileName</strong>: Block.java
* <HR>
* <strong>Description</strong>: Block object attribute description.
* <P><HR>
* @author
* <em>
* This Game is developed by <B>Fansy</B>.<BR>
* F.S.Studio 1999~2005
* </em>
* @version 0.3.2
*/
public class Block
{
private Image blockimage; //砖块图像
private int blockx,blocky; //砖块的Index
public TiledLayer blocktd; //砖块图层
public byte[][][] blockmap={ //砖块描述
{{1,2,1,2,1,2,1,2},
{2,1,2,1,2,1,2,1},
{1,2,1,2,1,2,1,2},
{2,1,2,1,2,1,2,1},
{1,2,1,2,1,2,1,2},
{2,1,2,1,2,1,2,1},
{1,2,1,2,1,2,1,2},
{2,1,2,1,2,1,2,1}},
{{1,2,1,2,1,2,1,2},
{2,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,2},
{2,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,2},
{2,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,2},
{2,1,2,1,2,1,2,1}},
{{1,0,0,0,0,0,0,0},
{2,1,0,0,0,0,0,0},
{1,2,1,0,0,0,0,0},
{2,1,2,1,0,0,0,0},
{1,2,1,2,1,0,0,0},
{2,1,2,1,2,1,0,0},
{1,2,1,2,1,2,1,0},
{2,1,2,1,2,1,2,1}},
{{0,0,0,0,0,0,0,0},
{2,1,2,1,2,1,2,1},
{0,0,0,0,0,0,0,0},
{2,1,2,1,2,1,2,1},
{0,0,0,0,0,0,0,0},
{2,1,2,1,2,1,2,1},
{0,0,0,0,0,0,0,0},
{2,1,2,1,2,1,2,1}},
{{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,1},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0}},
{{0,2,0,2,0,2,0,2},
{2,0,2,0,2,0,2,0},
{0,2,0,2,0,2,0,2},
{2,0,2,0,2,0,2,0},
{0,2,0,2,0,2,0,2},
{2,0,2,0,2,0,2,0},
{0,2,0,2,0,2,0,2},
{2,0,2,0,2,0,2,0}}
};
public Block()
{
try{blockimage=Image.createImage("/blockimage.png");} //装载砖块图像
catch(Exception e){}
blocktd=new TiledLayer(8,8,blockimage,20,10); //建立砖块图层,共有8行,8列
blocktd.setPosition(40,30); //设置砖块图层的偏移位置
}
public void InitLevel(int level) //初始化关卡
{
for(int i=0;i<8;i++) //初始化砖块图层
for(int j=0;j<8;j++)
blocktd.setCell(j,i,blockmap[level][i][j]);
}
public void ClearBlock() //清除碰撞到的砖块
{
blocktd.setCell(blockx,blocky,0);
}
public void setBlock(int x,int y)
{
blockx=x;
blocky=y;
}
public int getBlockX()
{
return blockx;
}
public int getBlockY()
{
return blocky;
}
public boolean isAllClear()
{
int flag=0;
for(int i=0;i<8;i++) //判断砖块是否全部清除
for(int j=0;j<8;j++)
flag+=blocktd.getCell(i,j);
if(flag!=0) return false;
else return true;
}
}