Class Bomb

java.lang.Object
  extended by Obj
      extended by Bomb

public class Bomb
extends Obj

The Bomb class will explode a short time after its creation. When it explodes, it disperses Fire in the four compass directions.

Author:
Jonathan

Nested Class Summary
(package private)  class Bomb.Explode
           
 
Field Summary
private  java.awt.image.BufferedImage bombImage
           
private  long DELAY
           
private  int distance
           
 Player owner
           
private  java.util.Timer time
           
 
Constructor Summary
Bomb(Grid gr, Player p, int d)
          Constructs a Bomb.
 
Method Summary
private  void disperseFlame(int x, int y, int range)
          Puts Fire in the 4 directions originating from coordinate (x, y).
 java.awt.image.BufferedImage getImage()
          Returns the image to be drawn in the grid.
 int getRange()
          Returns the range of the bomb.
private  boolean placeFire(int x, int y, int fireType)
          Adds fire in the spot specified if the space is clear, removes the object there if it is not.
 void removeSelfFromGrid()
          Notifies the owner that it exploded, removes itself from the grid, and then adds fire to the squares in range.
 
Methods inherited from class Obj
getGrid, getX, getY, moveTo, putSelfInGrid, setX, setY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

owner

public Player owner

DELAY

private final long DELAY
See Also:
Constant Field Values

time

private java.util.Timer time

distance

private int distance

bombImage

private java.awt.image.BufferedImage bombImage
Constructor Detail

Bomb

public Bomb(Grid gr,
            Player p,
            int d)
Constructs a Bomb.

Parameters:
gr - The grid that the Bomb is in.
p - The Player that dropped this Bomb.
d - The range of the explosion.
Method Detail

removeSelfFromGrid

public void removeSelfFromGrid()
Notifies the owner that it exploded, removes itself from the grid, and then adds fire to the squares in range.

Overrides:
removeSelfFromGrid in class Obj

disperseFlame

private void disperseFlame(int x,
                           int y,
                           int range)
Puts Fire in the 4 directions originating from coordinate (x, y). Does not include the starting point itself.

Parameters:
x - x-coordinate of starting point
y - y-coordinate of starting point
range - how far the Fire will spread

placeFire

private boolean placeFire(int x,
                          int y,
                          int fireType)
Adds fire in the spot specified if the space is clear, removes the object there if it is not. If Fire was not stopped by an object already occupying the space, returns true.

Parameters:
x - x-coordinate where Fire is to go
y - y-coordinate where Fire is to go
Returns:
false if Fire hit a Wall or Box

getRange

public int getRange()
Returns the range of the bomb.

Returns:
maximum range of this Bomb's Fire.

getImage

public java.awt.image.BufferedImage getImage()
Description copied from class: Obj
Returns the image to be drawn in the grid.

Specified by:
getImage in class Obj
Returns:
the image to be drawn.