us.asciiroth.client.core
Class Player

java.lang.Object
  extended by us.asciiroth.client.core.Player
All Implemented Interfaces:
Agent, Animated, Piece

public class Player
extends java.lang.Object
implements Agent, Animated

This represents both the player, and the state of the game for the player. Not to be confused with the Game object which is the primary controller component for the game.


Field Summary
static int DETECT_HIDDEN_RANGE
           
static int MAX_HEALTH
           
 
Constructor Summary
Player(InputManager im, java.lang.String name, java.lang.String scenarioURL, java.lang.String boardID, int x, int y)
           
 
Method Summary
 void add(int flag)
           
 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)
          Change health.
 void curePoison(Event event, Item healer)
          Cure the player of poisoning.
 void cureWeakness(Event event, Item healer)
          Cure the player of weakness.
 boolean enforceWeakness(Event event, Cell loc, Item item)
          After picking up an item, adjust inventory if the player is weak so that he/she still only holds one item.
 PlayerBag getBag()
           
 java.lang.String getBoardID()
           
 Color getColor()
          What is the color of this piece? While many piece types are permanently of color "None", many more can be parameterized with a color in order to tie them together through color-based events.
 int getFlags()
           
 java.lang.String getName()
          The visible name of the piece.
 java.lang.String getScenarioURL()
           
 int getStartX()
           
 int getStartY()
           
 Symbol getSymbol()
          The symbol to display for this piece.
 java.util.Map<java.lang.String,java.lang.String> getUnsavedMaps()
           
 void heal(Event event, Item healer, int amount)
          Heal the player.
 boolean is(int flag)
          Does this piece have the indicated bit flag?
 boolean matchesFlagOrItem(java.lang.String token)
           
 boolean not(int flag)
          Does this piece not have the indicated flag?
 void onDie(Event event, Cell agentLoc)
          Called when the agent dies on a given cell.
 void onFrame(Context ctx, Cell cell, int frame)
          Animation callback, executed once each frame for each piece animated on the board.
 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.
 boolean randomSeed()
          Should this animation start with a randomly seeded number as its first frame? For some animations, this can prevent all presentations of the piece on the board executing the same animation frame at the same time.
 void remove(int flag)
           
 void setBoardID(java.lang.String url)
           
 void setHealth(int health)
           
 void setName(java.lang.String name)
           
 void setScenarioURL(java.lang.String base)
           
 void setStartXY(int x, int y)
           
 void setUnsavedMaps(java.util.Map<java.lang.String,java.lang.String> unsavedMaps)
           
 void teleport(Event event, Direction dir, java.lang.String boardID, int x, int y)
           
 boolean testResistance(int resistance)
           
 void weaken(Cell cell)
          Weaken the player, which will also have the consequence that the player will drop everything except the currently equipped item.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DETECT_HIDDEN_RANGE

public static final int DETECT_HIDDEN_RANGE
See Also:
Constant Field Values

MAX_HEALTH

public static final int MAX_HEALTH
See Also:
Constant Field Values
Constructor Detail

Player

public Player(InputManager im,
              java.lang.String name,
              java.lang.String scenarioURL,
              java.lang.String boardID,
              int x,
              int y)
Method Detail

add

public void add(int flag)

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)
Description copied from interface: Agent
Change health. For the player, this method indicates an amount of change to health, and returns the current health of the player after being changed. For other agents, the value an adjustment to the percentage chance that the agent will be hit by an attack.

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.

curePoison

public void curePoison(Event event,
                       Item healer)
Cure the player of poisoning. If the player is cured of poisoning, the item is consumed.

Parameters:
event -
healer -

cureWeakness

public void cureWeakness(Event event,
                         Item healer)
Cure the player of weakness. If the player is cured of weakness, the item is consumed.

Parameters:
event -
healer -

enforceWeakness

public boolean enforceWeakness(Event event,
                               Cell loc,
                               Item item)
After picking up an item, adjust inventory if the player is weak so that he/she still only holds one item.

Parameters:
event -
loc -
item -
Returns:
true if one item inventory was enforced, false if nothing special happened

getBag

public PlayerBag getBag()

getBoardID

public java.lang.String getBoardID()

getColor

public Color getColor()
Description copied from interface: Piece
What is the color of this piece? While many piece types are permanently of color "None", many more can be parameterized with a color in order to tie them together through color-based events.

Specified by:
getColor in interface Piece
Returns:
the Color of this piece

getFlags

public int getFlags()

getName

public java.lang.String getName()
Description copied from interface: Piece
The visible name of the piece.

Specified by:
getName in interface Piece
Returns:
the name of the piece as displayed to the user.

getScenarioURL

public java.lang.String getScenarioURL()

getStartX

public int getStartX()

getStartY

public int getStartY()

getSymbol

public Symbol getSymbol()
Description copied from interface: Piece
The symbol to display for this piece.

Specified by:
getSymbol in interface Piece
Returns:
the symbol for this piece

getUnsavedMaps

public java.util.Map<java.lang.String,java.lang.String> getUnsavedMaps()

heal

public void heal(Event event,
                 Item healer,
                 int amount)
Heal the player. If healing occurs, the item doing the healing is consumed.

Parameters:
event -
healer -
amount -

is

public boolean is(int flag)
Description copied from interface: Piece
Does this piece have the indicated bit flag?

Specified by:
is in interface Piece
Returns:
true if piece has the flag
See Also:
Flags

matchesFlagOrItem

public boolean matchesFlagOrItem(java.lang.String token)

not

public boolean not(int flag)
Description copied from interface: Piece
Does this piece not have the indicated flag?

Specified by:
not in interface Piece
Returns:
true if piece does not have the flag
See Also:
Flags

onDie

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

Specified by:
onDie in interface Agent

onFrame

public void onFrame(Context ctx,
                    Cell cell,
                    int frame)
Description copied from interface: Animated
Animation callback, executed once each frame for each piece animated on the board.

Specified by:
onFrame in interface Animated

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

randomSeed

public boolean randomSeed()
Description copied from interface: Animated
Should this animation start with a randomly seeded number as its first frame? For some animations, this can prevent all presentations of the piece on the board executing the same animation frame at the same time.

Specified by:
randomSeed in interface Animated
Returns:
true if a random frame should begin the animated piece's timeline

remove

public void remove(int flag)

setBoardID

public void setBoardID(java.lang.String url)

setHealth

public void setHealth(int health)

setName

public void setName(java.lang.String name)

setScenarioURL

public void setScenarioURL(java.lang.String base)

setStartXY

public void setStartXY(int x,
                       int y)

setUnsavedMaps

public void setUnsavedMaps(java.util.Map<java.lang.String,java.lang.String> unsavedMaps)

teleport

public void teleport(Event event,
                     Direction dir,
                     java.lang.String boardID,
                     int x,
                     int y)

testResistance

public boolean testResistance(int resistance)

weaken

public void weaken(Cell cell)
Weaken the player, which will also have the consequence that the player will drop everything except the currently equipped item.

Parameters:
cell -

0.7

2009 Alx Dark