us.asciiroth.client.agents
Class AbstractAgent

java.lang.Object
  extended by us.asciiroth.client.core.AbstractPiece
      extended by us.asciiroth.client.agents.AbstractAgent
All Implemented Interfaces:
Agent, Piece
Direct Known Subclasses:
AbstractAnimatedAgent, Boulder, Campfire, ImmobileAgent, Pusher, RollingBoulder, Slider

public abstract class AbstractAgent
extends AbstractPiece
implements Agent

Abstract class for agents. It handles the use of health as a percentage chance to kill an agent.


Constructor Summary
AbstractAgent(java.lang.String name, int flags, Color color, int chanceToHit, Symbol symbol)
          Constructor.
 
Method Summary
 boolean canEnter(Direction direction, Cell from, Cell to)
          Can the agent enter this terrain? This method mirrors the same method in Terrain, and both most return true for the agent to be able to move.
 int changeHealth(int delta)
          For agents, "health" is the chance of destroying an agent.
 void onDie(Event event, Cell cell)
          Called when the agent dies on a given cell.
 void onHit(Event event, Cell attackerLoc, Cell agentLoc, Agent agent)
          Fired when this agent collides with the player, or if this agent is the player, when the player collides with another agent (in other words, this method will not fire if one non-player agent collides with another non-player agent).
 void onHitBy(Event event, Cell agentLoc, Agent agent, Direction dir)
          Called when this agent is hit by another agent (another agent collides with it).
 void onHitBy(Event event, Cell itemLoc, Item item, Direction dir)
          Called when this agent is hit by another item, either by being thrown, or by being wielded by the player.
 
Methods inherited from class us.asciiroth.client.core.AbstractPiece
getColor, getName, getSymbol, is, not
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface us.asciiroth.client.core.Piece
getColor, getName, getSymbol, is, not
 

Constructor Detail

AbstractAgent

public AbstractAgent(java.lang.String name,
                     int flags,
                     Color color,
                     int chanceToHit,
                     Symbol symbol)
Constructor.

Parameters:
name -
flags -
color -
chanceToHit -
symbol -
Method Detail

canEnter

public boolean canEnter(Direction direction,
                        Cell from,
                        Cell to)
Description copied from interface: Agent
Can the agent enter this terrain? This method mirrors the same method in Terrain, and both most return true for the agent to be able to move. You can put the logic for preventing agent movement in either place, depending on where it makes sense in order to centralize it. NOTE: There is currently no canExit method for agents, but it can be added if any piece ever needs it.

Specified by:
canEnter in interface Agent
Returns:
true if the agent can enter the terrain moving between the two cells using the indicated direction
See Also:
Terrain.canEnter(Agent, Cell, Direction)

changeHealth

public int changeHealth(int delta)
For agents, "health" is the chance of destroying an agent. The higher the number, the harder to kill.

Specified by:
changeHealth in interface Agent
Parameters:
delta - the damage to take or the adjustment to the percentage chance to be hit.
Returns:
returns the current health of the agent, 0 for non-player agents when they have been killed.

onDie

public void onDie(Event event,
                  Cell cell)
Description copied from interface: Agent
Called when the agent dies on a given cell.

Specified by:
onDie in interface Agent

onHit

public void onHit(Event event,
                  Cell attackerLoc,
                  Cell agentLoc,
                  Agent agent)
Description copied from interface: Agent
Fired when this agent collides with the player, or if this agent is the player, when the player collides with another agent (in other words, this method will not fire if one non-player agent collides with another non-player agent).

Specified by:
onHit in interface Agent

onHitBy

public void onHitBy(Event event,
                    Cell agentLoc,
                    Agent agent,
                    Direction dir)
Description copied from interface: Agent
Called when this agent is hit by another agent (another agent collides with it). Typically the move event will be cancelled in this method, unless this agent moves itself out of the way, such as boulders attempt to do.

Specified by:
onHitBy in interface Agent

onHitBy

public void onHitBy(Event event,
                    Cell itemLoc,
                    Item item,
                    Direction dir)
Description copied from interface: Agent
Called when this agent is hit by another item, either by being thrown, or by being wielded by the player.

Specified by:
onHitBy in interface Agent

0.7

© 2009 Alx Dark