?? scene.java
字號(hào):
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; //坦克可穿過(guò)的圖層
public TiledLayer m_LyBulletPass;//子彈可穿過(guò)的圖層
public TiledLayer m_LyCanHit; //可摧毀的圖層
public TiledLayer m_LyNotPass;//坦克不可穿過(guò)的圖層
public TiledLayer m_LyHQ;
Scene(){
//創(chuàng)建各個(gè)圖層
try{
Image image = Image.createImage("/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{
//讀取預(yù)先設(shè)置的地圖文本本件
InputStream is = getClass().getResourceAsStream("/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){}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -