rogue
Class ActiveItem

java.lang.Object
  extended by rogue.DungeonItem
      extended by rogue.ActiveItem
Direct Known Subclasses:
Monster, Player

public abstract class ActiveItem
extends DungeonItem

An extension of DungeonItem, an ActiveItem is an abstract base class for all "active" things in the dungeon - i.e. the Player and the Monsters.


Field Summary
protected  int myHealth
          Current "health" rating for ActiveItem, which it prefers to keep > 0.
 
Fields inherited from class rogue.DungeonItem
myPosition, theDungeon
 
Constructor Summary
ActiveItem(int ImageNo, DungeonGame d)
          Constructor - simply passes arguments to base class constructor.
 
Method Summary
 boolean alive()
          Determines whether active inhabitant of dungeon is still "alive".
 void getHit(int damage)
          Decrements health rating when an active dungeon inhabitant is attacked.
protected  void move(int newx, int newy)
          Moves active inhabitant of dungeon to new location.
 void read(java.io.BufferedReader input)
          Invokes super.read() to get common properties of all DungeonItems read, then reads data common to all ActiveItems.
protected  Pt step(int dir)
          Utility function, finds new position after movement in specified direction.
 
Methods inherited from class rogue.DungeonItem
isAt, position, show, vanish
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myHealth

protected int myHealth
Current "health" rating for ActiveItem, which it prefers to keep > 0.

Constructor Detail

ActiveItem

public ActiveItem(int ImageNo,
                  DungeonGame d)
Constructor - simply passes arguments to base class constructor.

Parameters:
ImageNo - Integer that identifies icon used to display the item.
d - Link to DungeonGame object
Method Detail

getHit

public void getHit(int damage)
Decrements health rating when an active dungeon inhabitant is attacked.

Parameters:
damage - Amount of damage caused by an attacker.

alive

public boolean alive()
Determines whether active inhabitant of dungeon is still "alive".

Returns:
Returns "live" status (health>0).

move

protected void move(int newx,
                    int newy)
Moves active inhabitant of dungeon to new location. (It invokes DungeonItem.vanish() to remove existing record of active item in the visual map structure used to display the dungeon, then updates coordinates).

Parameters:
newx - New x coordinate
newy - New y coordinate

read

public void read(java.io.BufferedReader input)
Invokes super.read() to get common properties of all DungeonItems read, then reads data common to all ActiveItems. There is only one such data element - the "health" rating. Reads one line that should contain an integer.

Overrides:
read in class DungeonItem
Parameters:
input - BufferedReader input stream connected to dungeon definition file.

step

protected Pt step(int dir)
Utility function, finds new position after movement in specified direction.

Parameters:
dir - Integer direction of motion - usual numeric keyboard motion control,
 7 = North West, 8 = North, 9 = North East,
 4 = West, 5 = no motion, 6 = East
 1 = South West, 2 = South, 3 = South East,
 
Returns:
New Pt object representing updated position.