Dungeon
Extends:
An explorable dungeon in the game. Contains a grid of tiles and the high-level logic for advancing the game state. Optionally contains a set of victory and defeat conditions
Constructor Summary
Public Constructor | ||
public |
constructor(width: number, height: number) Initializes an empty dungeon with the specified width |
Method Summary
Public Methods | ||
public |
Tells if the dungeon's state can advance. |
|
public |
Dispatches a GameEvent to all observers |
|
public |
forEachTile(func: function) Performs an operation with each tile in the map |
|
public |
Gets the creature whose turn it is to move. |
|
public |
|
|
public |
|
|
public |
|
|
public |
|
|
public |
getRng(): Random Gets an RNG for use with random effects. |
|
public |
Gets a tile from coordinates or a creature |
|
public |
Gets a 1-D array of the tiles in the map, optionally filtered |
|
public |
|
|
public |
Tells if the game has ended through either defeat or victory |
|
public |
isConnected(isTraversable: function): * Tells whether the dungeon is traversable. |
|
public |
moveCreature(creature: Creature, x: number, y: number) Positions a creature within the Dungeon. |
|
public |
removeCreature(param1: Creature | number, param2: number) Removes a creature from the dungeon, either by using a reference to the creature, or coordinates |
|
public |
Advances the dungeon by one timestep. |
|
public |
Advances the game state until the player's next move or the game is over. This contains the game loop. |
|
public |
setGameConditions(conditions: GameConditions) Sets the conditions for victory and defeat in the Dungeon |
|
public |
Changes the tile at the specified position |
Inherited Summary
From class Observable | ||
public |
addObserver(observer: *) |
|
public |
removeObserver(observer: *) |
Public Constructors
Public Methods
public canAdvance(): boolean source
Tells if the dungeon's state can advance.
Return:
boolean |
|
public fireEvent(event: GameEvent) source
Dispatches a GameEvent to all observers
Params:
Name | Type | Attribute | Description |
event | GameEvent | An event representing something that happened in the Dungeon |
public forEachTile(func: function) source
Performs an operation with each tile in the map
Params:
Name | Type | Attribute | Description |
func | function | A function that will be called for each tile. The first param is the Tile. The second is the x-coordinate; the third, the y-coordinate |
public getActiveCreature(): Creature source
Gets the creature whose turn it is to move. This will be a creature whose speed counter has reached 0. Ties are broken with the creature's base speed.
public getPlayableCharacter(): PlayableCharacter source
public getRng(): Random source
Gets an RNG for use with random effects. All creatures behaving randomly should use this RNG.
Return:
Random | An RNG for random effects within the dungeon |
public getTile(param1: Creature | number, param2: number): * source
Gets a tile from coordinates or a creature
Return:
* |
public getTiles(filter: function): * source
Gets a 1-D array of the tiles in the map, optionally filtered
Params:
Name | Type | Attribute | Description |
filter | function | An |
Return:
* |
public isConnected(isTraversable: function): * source
Tells whether the dungeon is traversable.
Params:
Name | Type | Attribute | Description |
isTraversable | function |
|
Optional predicate for determining if a tile counts as traversable. Defaults to testing if tile has a floor and isn't solid |
Return:
* |
public moveCreature(creature: Creature, x: number, y: number) source
Positions a creature within the Dungeon. If the creature is already present, it will be removed from it's previous location first
public removeCreature(param1: Creature | number, param2: number) source
Removes a creature from the dungeon, either by using a reference to the creature, or coordinates
public resolveNextStep() source
Advances the dungeon by one timestep. During this time, multiple creatures can move (if their speed counters have reached 0).
public resolveUntilBlocked() source
Advances the game state until the player's next move or the game is over. This contains the game loop.
public setGameConditions(conditions: GameConditions) source
Sets the conditions for victory and defeat in the Dungeon
Params:
Name | Type | Attribute | Description |
conditions | GameConditions |