bomb.java

来自「这是个j2me的手机炸弹人JAVA源码好游戏」· Java 代码 · 共 77 行

JAVA
77
字号
package com.mot.j2me.midlets.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 ) {
		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 + =
减小字号Ctrl + -
显示快捷键?