Class Player

java.lang.Object
  extended by Obj
      extended by Player

public class Player
extends Obj

Gives you a pretty little image to call your avatar. You can move him around and tell him to lay bombs. You can even tell him to walk into fire and die. Oh the horror.

Author:
Tyler

Field Summary
private  int bombRange
           
private  int consecMoveInSameDirection
           
private  int dir
           
private  java.util.Map<java.lang.Integer,java.io.File> imageset
           
private  boolean life
           
private  int maxBombs
           
private  int numBombs
           
private  java.awt.image.BufferedImage pImage
           
private  int xOffset
           
private  int yOffset
           
 
Constructor Summary
Player(Grid gr, int direction, int color)
          Creates a new Player object.
 
Method Summary
 void addBombs(int i)
          Adds i bombs to Player's bomb fields.
 void addConsecMoveInSameDirection()
          Adds one to the amount of times that the player has moved in the same direction.
 void bombDetonated()
          Notifies the Player that a bomb has detonated.
 boolean frontBlocked()
          Returns true if the Player's front is blocked, by a wall or boundary.
 int getConsecMoveInSameDirection()
          Returns the amount of times that the player has moved in the same direction.
 int getDirection()
          returns the direction the player is facing.
 java.awt.image.BufferedImage getImage()
          Returns the image to be drawn in the grid.
 int getMaxBombs()
          Gets the max number of bombs a Player can have on the grid.
 int getNumBombs()
          Gets the number of bombs a Player has left.
 int getRange()
          Gets the current range of the Player's Bombs.
 int getXOffset()
          Returns the visual offset of the Player in the grid.
 int getYOffset()
          Returns the visual offset of the Player in the grid.
 boolean isAlive()
          Returns the boolean that determines whether or not the player is alive.
 void layBomb()
          Creates a Bomb in the Player's location.
 void move()
          Moves the Player in the direction it is facing.
 void moveTo(int x, int y)
          Moves the Player to given coordinates.
 void removeSelfFromGrid()
          Removes this player from the grid.
 void reset()
          Resets the Player's traits to base level.
 void setDirection(int d)
          sets the direction and tells the player to face that direction.
 void setMaxBombs(int i)
          Sets the maximum bombs Player can have on map
 void setRange(int i)
          Sets the range (max distance of Fire) for the Player's bombs.
 void turnAround()
          Turns the Player's image 180 degrees.
 void turnLeft()
          Turns the Player's image 90 degrees to the left.
 void turnRight()
          Turns the Player's image 90 degrees to the right.
 
Methods inherited from class Obj
getGrid, getX, getY, putSelfInGrid, setX, setY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pImage

private java.awt.image.BufferedImage pImage

imageset

private java.util.Map<java.lang.Integer,java.io.File> imageset

numBombs

private int numBombs

maxBombs

private int maxBombs

bombRange

private int bombRange

dir

private int dir

consecMoveInSameDirection

private int consecMoveInSameDirection

xOffset

private int xOffset

yOffset

private int yOffset

life

private boolean life
Constructor Detail

Player

public Player(Grid gr,
              int direction,
              int color)
Creates a new Player object.

Parameters:
gr - Grid that he lives in.
direction - Direction that he faces by default.
color - The color of his clothes.
Method Detail

layBomb

public void layBomb()
Creates a Bomb in the Player's location. Bomb and Player coexist in that square until the Player leaves.


move

public void move()
Moves the Player in the direction it is facing.


moveTo

public void moveTo(int x,
                   int y)
Moves the Player to given coordinates. If anything is there already, deals with the occupant according to its type: a Bomb, Wall, or Box - Player will not move a Fire - Player will die a PowerUp - Player will get the PowerUp, then move a Player - this Player will move there too, Players can coexist

Overrides:
moveTo in class Obj
Parameters:
x - x-coordinate to move to
y - y-coordinate to move to

turnLeft

public void turnLeft()
Turns the Player's image 90 degrees to the left.


turnRight

public void turnRight()
Turns the Player's image 90 degrees to the right.


turnAround

public void turnAround()
Turns the Player's image 180 degrees.


setDirection

public void setDirection(int d)
sets the direction and tells the player to face that direction.

Parameters:
d -

bombDetonated

public void bombDetonated()
Notifies the Player that a bomb has detonated.


reset

public void reset()
Resets the Player's traits to base level.


getNumBombs

public int getNumBombs()
Gets the number of bombs a Player has left.

Returns:
number of Bombs Player can place

getMaxBombs

public int getMaxBombs()
Gets the max number of bombs a Player can have on the grid.

Returns:
max number of Bombs Player can place

setMaxBombs

public void setMaxBombs(int i)
Sets the maximum bombs Player can have on map

Parameters:
i - maximum bombs of Player

addBombs

public void addBombs(int i)
Adds i bombs to Player's bomb fields.

Parameters:
i - number of Bombs.

getRange

public int getRange()
Gets the current range of the Player's Bombs.

Returns:
range of bombs

setRange

public void setRange(int i)
Sets the range (max distance of Fire) for the Player's bombs.

Parameters:
i - new range of bombs

getXOffset

public int getXOffset()
Returns the visual offset of the Player in the grid. Positive is towards the right side (EAST), negative to the left (WEST).

Returns:
offset in the x-direction

getYOffset

public int getYOffset()
Returns the visual offset of the Player in the grid. Positive shifts image down (SOUTH), negative up (NORTH).

Returns:
offset in the y-direction

getDirection

public int getDirection()
returns the direction the player is facing.

Returns:
the direction the player is facing.

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.

getConsecMoveInSameDirection

public int getConsecMoveInSameDirection()
Returns the amount of times that the player has moved in the same direction.

Returns:
an int with the amount of times.

addConsecMoveInSameDirection

public void addConsecMoveInSameDirection()
Adds one to the amount of times that the player has moved in the same direction.


isAlive

public boolean isAlive()
Returns the boolean that determines whether or not the player is alive.

Returns:
whether the player is alive.

removeSelfFromGrid

public void removeSelfFromGrid()
Removes this player from the grid.

Overrides:
removeSelfFromGrid in class Obj

frontBlocked

public boolean frontBlocked()
Returns true if the Player's front is blocked, by a wall or boundary.

Returns:
true if Player cannot move forwards; otherwise false