Terrain

Terrain

Base class for all terrain types.

Terrain occupies one cell and controls whether agents can enter/exit, and what happens when they do. All callback methods are no-ops by default; subclasses override only what they need.

The Java Terrain interface is an event-based protocol: each callback receives a GameEvent that can be cancelled to prevent the default action.

Constructor

new Terrain()

Source:

Methods

canEnter(agent, cell, direction) → {boolean}

Description:
  • Can an agent (or player) enter this terrain from the given direction? Enforces flag-based traversability:

    • TRAVERSABLE → any agent can enter
    • AQUATIC → only AQUATIC agents or those with WATER_RESISTANT
    • LAVITIC → only LAVITIC agents or those with FIRE_RESISTANT
    • ETHEREAL → only FLIER agents
    • (none) → impassable (Wall, Waterfall, etc.) Return false to unconditionally block movement — no side effects.
Source:
Parameters:
Name Type Description
agent Agent
cell Cell

destination cell

direction Direction
Returns:
Type
boolean

canExit(agent, cell, direction) → {boolean}

Description:
  • Can a non-player agent exit this terrain in the given direction?

Source:
Parameters:
Name Type Description
agent Agent
cell Cell

current cell

direction Direction
Returns:
Type
boolean

onAdjacentTo(event, cell)

Description:
  • This terrain is now adjacent to the player. Called after each move. Use this to reveal secret passages, trigger proximity effects, etc.

Source:
Parameters:
Name Type Description
event GameEvent
cell Cell

onAgentEnter()

Description:
  • A non-player agent is entering this terrain. Cancel event to prevent the move.

Source:

onAgentExit()

Description:
  • A non-player agent is exiting this terrain.

Source:

onColorEvent(event, color, cell)

Description:
  • A color event is being broadcast on this board. Implementations compare this.color to the event color parameter and react only when they match.

Source:
Parameters:
Name Type Description
event GameEvent
color string

CSS color string of the event

cell Cell

the cell holding this terrain

onDrop()

Description:
  • An item is being dropped onto this terrain. Cancel event to make the item disappear (e.g., dropping into lava).

Source:

onEnter(event, player, cell, dir)

Description:
  • The player is entering this terrain. Cancel event to prevent the move.

Source:
Parameters:
Name Type Description
event GameEvent
player Player
cell Cell

destination cell

dir Direction

onExit()

Description:
  • The player is exiting this terrain. Cancel event to prevent the move.

Source:

onFlyOver(event, cell, flier)

Description:
  • An in-flight item is passing over this terrain. Cancel event to make the item land here instead of continuing.

Source:
Parameters:
Name Type Description
event GameEvent
cell Cell
flier InFlightItem

onNotAdjacentTo()

Description:
  • This terrain is no longer adjacent to the player.

Source:

onPickup()

Description:
  • An agent is picking up an item from this terrain. Cancel event to prevent the pickup.

Source: