📄 grids.java
字号:
package demo;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.TiledLayer;
public class Grids {
private TiledLayer m_BuidingTL; //不能通过的格子
private TiledLayer m_BeanTL; //可通过的格子,上面有豆
//构造方法,参数scrWidth、scrHeight分别是屏幕的宽和高
public Grids( int scrWidth, int scrHeight ){
try{
//读取Tile图片
Image img = Image.createImage("/demo/grid.png");
m_BuidingTL = new TiledLayer( 9, 9, img, 15, 15 );
m_BeanTL = new TiledLayer( 9, 9, img, 15, 15 );
int x = scrWidth/2 - m_BeanTL.getWidth()/2;
int y = scrHeight/2 - m_BeanTL.getHeight()/2;
m_BuidingTL.setPosition(x, y);
m_BeanTL.setPosition(x, y);
}
catch(Exception exception){}
}
//重新设置背景格子
public void Reset(){
int a[][] =
{ { 1, 1, 1, 1, 0, 1, 1, 1, 1 },
{ 1, 0, 2, 2, 2, 2, 2, 0, 1 },
{ 1, 2, 4, 1, 2, 1, 4, 2, 1 },
{ 1, 2, 1, 1, 2, 1, 1, 2, 1 },
{ 0, 3, 2, 2, 0, 2, 2, 3, 0 },
{ 1, 2, 1, 1, 2, 1, 1, 2, 1 },
{ 1, 2, 4, 1, 2, 1, 4, 2, 1 },
{ 1, 0, 2, 2, 2, 2, 2, 0, 1 },
{ 1, 1, 1, 1, 0, 1, 1, 1, 1 } };
for( int col = 0; col < a[0].length; col ++ ){
for( int row = 0; row < a.length; row ++ ){
if( a[row][col] == 1 ){
m_BuidingTL.setCell(col, row, a[row][col] );
m_BeanTL.setCell(col, row, 0 );
}
else{
m_BuidingTL.setCell(col, row, 0 );
m_BeanTL.setCell(col, row, a[row][col] );
}
}
}
}
//获取不能通过的格子对象
public TiledLayer getBuiding(){
return m_BuidingTL;
}
//获取有豆的格子对象
public TiledLayer getBeanTL(){
return m_BeanTL;
}
//获取背景左上角的X坐标
public int getX(){
return m_BeanTL.getX();
}
//获取背景左上角的Y坐标
public int getY(){
return m_BeanTL.getY();
}
//获取背景宽度
public int getWidth(){
return m_BeanTL.getWidth();
}
//获取背景高度
public int getHeight(){
return m_BeanTL.getHeight();
}
//获取单元格子的宽度
public int getCellWidth(){
return m_BeanTL.getCellWidth();
}
//获取单元格子的高度
public int getCellHeight(){
return m_BeanTL.getCellHeight();
}
//显示背景格子
public void Paint(Graphics g){
m_BeanTL.paint(g);
m_BuidingTL.paint(g);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -