us.asciiroth.client.terrain.decorators
Class DualTerrain

java.lang.Object
  extended by us.asciiroth.client.terrain.decorators.DualTerrain
All Implemented Interfaces:
ColorListener, Piece, Terrain, TerrainProxy

public class DualTerrain
extends java.lang.Object
implements TerrainProxy, Terrain, ColorListener

Dual terrain is a composite terrain that holds two other terrains, only one of which is active at any given time. It is not a decorator, insofar as it doesn't change the behavior of either terrain (except for the ColorListener interface which it implements: color events will switch the dual terrain, and if the newly activated terrain implements the ColorListener interface, it will fire that as well). The inactive terrain is simply ignored, but knowledge of its presence at the given cell continues to exist.

The DualTerrain exposes a method, switchTerrains(), that will change the current terrain, and the onTrigger() method will do this as well.

DualTerrain does implement TerrainProxy so that in the map editor, it is correctly marked as a compound-style terrain (otherwise it would be indistinguishable from its active terrain).

NOTE: If one of the included terrains transforms a cell, it will wipe out the DualTerrain.


Field Summary
static Serializer<DualTerrain> SERIALIZER
          Type serializer.
 
Method Summary
 boolean canEnter(Agent agent, Cell cell, Direction direction)
          Can the (non-player) agent enter this terrain? Without regard to side effects, this method should determine if the agent can actually move into the cell.
 boolean canExit(Agent agent, Cell cell, Direction direction)
          Can the (non-player) agent exit this terrain? Without regard to side effects, this method should determine if the agent can actually move into the cell.
 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.
 java.lang.String getName()
          The visible name of the piece.
 Terrain getProxiedTerrain()
           
 Symbol getSymbol()
          The symbol to display for this piece.
 boolean is(int flag)
          Does this piece have the indicated bit flag?
 boolean not(int flag)
          Does this piece not have the indicated flag?
 void onAdjacentTo(Context context, Cell cell)
          This terrain is adjacent to the player.
 void onAgentEnter(Event event, Agent agent, Cell cell, Direction dir)
           
 void onAgentExit(Event event, Agent agent, Cell cell, Direction dir)
           
 void onColorEvent(Context ctx, Cell cell, Cell origin)
          Terrain has received a color event, probably related to the firing of a color event on the board.
 void onDrop(Event event, Cell cell, Item item)
          Item is going to drop onto the terrain at this point.
 void onEnter(Event event, Player player, Cell cell, Direction dir)
          Agent attempting to leave the from cell, heading toward the to cell.
 void onExit(Event event, Player player, Cell cell, Direction dir)
          Agent attempting to exit the from cell, heading toward the to cell.
 void onFlyOver(Event event, Cell cell, InFlightItem flier)
          Terrain has an item flying over it.
 void onNotAdjacentTo(Context context, Cell cell)
          This terrain is no longer adjacent to the player.
 void onPickup(Event event, Cell loc, Agent agent, Item item)
          Item is going to be picked up.
 Terrain proxy(Terrain terrain)
          Will create a proxy with the terrain replacing the currently active terrain.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERIALIZER

public static final Serializer<DualTerrain> SERIALIZER
Type serializer.

Method Detail

canEnter

public boolean canEnter(Agent agent,
                        Cell cell,
                        Direction direction)
Description copied from interface: Terrain
Can the (non-player) agent enter this terrain? Without regard to side effects, this method should determine if the agent can actually move into the cell. Error on the side of caution and return false if the answer is ambiguous.

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

canExit

public boolean canExit(Agent agent,
                       Cell cell,
                       Direction direction)
Description copied from interface: Terrain
Can the (non-player) agent exit this terrain? Without regard to side effects, this method should determine if the agent can actually move into the cell. Error on the side of caution and return false if the answer is ambiguous.

Specified by:
canExit in interface Terrain
Returns:
true if the agent can leave this cell going in the indicated direction
See Also:
Cell.canEnter(Cell, Agent, Direction, boolean)

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

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.

getProxiedTerrain

public Terrain getProxiedTerrain()
Specified by:
getProxiedTerrain in interface TerrainProxy
Returns:
the proxied terrain which will be used for rendering

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

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

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

onAdjacentTo

public void onAdjacentTo(Context context,
                         Cell cell)
Description copied from interface: Terrain
This terrain is adjacent to the player. It may render differently under these circumstances.

Specified by:
onAdjacentTo in interface Terrain

onAgentEnter

public void onAgentEnter(Event event,
                         Agent agent,
                         Cell cell,
                         Direction dir)
Specified by:
onAgentEnter in interface Terrain

onAgentExit

public void onAgentExit(Event event,
                        Agent agent,
                        Cell cell,
                        Direction dir)
Specified by:
onAgentExit in interface Terrain

onColorEvent

public void onColorEvent(Context ctx,
                         Cell cell,
                         Cell origin)
Description copied from interface: ColorListener
Terrain has received a color event, probably related to the firing of a color event on the board. Different terrain behave differently when triggered, most flip between a set of states.

Specified by:
onColorEvent in interface ColorListener
Parameters:
ctx - a context object with references to game state

onDrop

public void onDrop(Event event,
                   Cell cell,
                   Item item)
Description copied from interface: Terrain
Item is going to drop onto the terrain at this point. If the event if canceled at this point, then the item will simply disappear from the board.

Specified by:
onDrop in interface Terrain

onEnter

public void onEnter(Event event,
                    Player player,
                    Cell cell,
                    Direction dir)
Description copied from interface: Terrain
Agent attempting to leave the from cell, heading toward the to cell. The terrain being used is the terrain of the to cell. The agent is still in the from
Specified by:
onEnter in interface Terrain

onExit

public void onExit(Event event,
                   Player player,
                   Cell cell,
                   Direction dir)
Description copied from interface: Terrain
Agent attempting to exit the from cell, heading toward the to cell. The terrain being used is the from cell terrain, and the agent is still in the from cell. If the event is canceled at this point, the agent will not be able leave this cell. The move will be canceled. This event is fired for the player as well as all other agents

Specified by:
onExit in interface Terrain

onFlyOver

public void onFlyOver(Event event,
                      Cell cell,
                      InFlightItem flier)
Description copied from interface: Terrain
Terrain has an item flying over it. If the event is canceled at this point, the item will fall to the ground on this cell.

Specified by:
onFlyOver in interface Terrain

onNotAdjacentTo

public void onNotAdjacentTo(Context context,
                            Cell cell)
Description copied from interface: Terrain
This terrain is no longer adjacent to the player. It may render differently under these circumstances.

Specified by:
onNotAdjacentTo in interface Terrain

onPickup

public void onPickup(Event event,
                     Cell loc,
                     Agent agent,
                     Item item)
Description copied from interface: Terrain
Item is going to be picked up. If the event is canceled at this point, the item will not be picked up and will remain on the cell.

Specified by:
onPickup in interface Terrain

proxy

public Terrain proxy(Terrain terrain)
Will create a proxy with the terrain replacing the currently active terrain.

Specified by:
proxy in interface TerrainProxy
Returns:
a new proxy, with the same behavior but wrapping a different terrain

0.7

© 2009 Alx Dark