⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bomb.java

📁 J2ME的炸弹人游戏.初学J2ME的好资料.玩家可控制一个老鼠进行游戏.
💻 JAVA
字号:
package example.jbombman;

public class Bomb extends Thread {
	private Board oBoard;
	private BoardView oBoardView;
	private Player oPlayer;
	private Enemy oEnemy;
	
	private final int iExplodingTime = 4000;
	private final int iDisapearTime = 1000;
	
	private int iX, iY;
	private volatile boolean stopThread = false;
	
	public Bomb( Board board, BoardView boardview, Player player, Enemy enemy,
					int x, int y ) {
		oBoard = board;
		oBoardView = boardview;
		oPlayer = player;
		oEnemy = enemy;
		
		iX = x;
		iY = y;
		
		oBoard.chBoard[iX][iY] = 'U';
	}
	
	public void stopThread() {
		stopThread = true;
	}

	private void explode( int x, int y ) {
		System.out.println( "Bomb explode: " + x + ", " + y );
		if( oBoard.isElement( 'P', x, y )||oBoard.isElement( 'U', x, y ) )
			oPlayer.die();
		else if ( oBoard.isElement( 'E', x, y ) )
			oEnemy.die( x, y );
		
		if ( oBoard.isElement( 'N', x, y )||oBoard.isElement( 'W', x, y )
				||oBoard.isElement( 'P', x, y )||oBoard.isElement( 'E', x, y )
				||oBoard.isElement( 'U', x, y )||oBoard.isElement( 'B', x, y ) )
			oBoard.chBoard[x][y] = 'X';
	}
	
	private void clear( int x, int y ) {
		if( oBoard.isElement( 'X', x, y ) )
			oBoard.setElement( 'N', x, y );
	}

	public void run() {
        while (!stopThread) {
            try {
                sleep(iExplodingTime);
            	System.out.println( "Explode" );
				explode( iX, iY );
				explode( iX-1, iY );
				explode( iX+1, iY );
				explode( iX, iY-1 );
				explode( iX, iY+1 );
				oBoardView.repaintCells(iX-1, iY-1, 3, 3);
				
				sleep(iDisapearTime);
            	System.out.println( "Clear" );
				oBoard.chBoard[iX][iY] = 'N';
				clear( iX-1, iY );
				clear( iX+1, iY );
				clear( iX, iY-1 );
				clear( iX, iY+1 );
				oBoardView.repaintCells(iX-1, iY-1, 3, 3);
				
				stopThread = true;
				oPlayer.clearBomb();
            } 
            catch (InterruptedException ie) {
            }
        }//while
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -