📄 scene.java
字号:
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.TiledLayer;
public class Scene
{
public TiledLayer m_LyCanPass; //坦克和子弹都可以通过的场景
public TiledLayer m_LyBulletPass; //坦克可以通过,子弹不能通过的场景
public TiledLayer m_LyCanHit; //坦克不能通过,但可被子弹摧毁
public TiledLayer m_LyNotPass; //坦克和子弹都不能通过,也不能被摧毁的场景
public TiledLayer m_LyHQ; //我方的司令部
//构造方法
Scene(){
//读取各种场景的tile图像
try{
Image image = Image.createImage("/demo/bg.png");
m_LyCanPass = new TiledLayer( 13, 12, image, 15, 15 );
m_LyBulletPass = new TiledLayer( 13, 12, image, 15, 15 );
m_LyCanHit = new TiledLayer( 13, 12, image, 15, 15 );
m_LyNotPass = new TiledLayer( 13, 12, image, 15, 15 );
m_LyHQ = new TiledLayer( 13, 12, image, 15, 15 );
}
catch(IOException ioe){}
catch(Exception e){}
}
//读取地图文件
public void LoadMap(){
try{
//读取地图文件
InputStream is = getClass().getResourceAsStream("/demo/map.txt");
int ch = -1;
for( int nRow = 0; nRow < 12; nRow ++ )
{
for( int nCol = 0; nCol < 13; nCol ++ )
{
ch = -1;
while( ( ch < 0 || ch > 6 ) ){
ch = is.read();
if( ch == -1 )
return;
ch = ch - '0';
}
m_LyCanPass.setCell( nCol, nRow, 0 );
m_LyBulletPass.setCell( nCol, nRow, 0 );
m_LyCanHit.setCell( nCol, nRow, 0 );
m_LyNotPass.setCell( nCol, nRow, 0 );
m_LyHQ.setCell( nCol, nRow, 0 );
if( ch == 1 )
m_LyCanPass.setCell( nCol, nRow, ch );
else if( ch == 2 )
m_LyBulletPass.setCell( nCol, nRow, ch );
else if( ch == 3 )
m_LyNotPass.setCell( nCol, nRow, ch );
else if( ch == 4 )
m_LyCanHit.setCell( nCol, nRow, ch );
else
m_LyHQ.setCell( nCol, nRow, ch );
}
}
}
catch(IOException ioe){}
catch(Exception e){}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -