Class: Game
Defined in: adventure/Game.js, line 6
Public Constructor:
var MyGame = new adventurejs.Game( "MyGame", "MyGameDisplay" )
Game is used to construct a new game instance. This instance contains the entire game and all of its methods. If you open the browser inspector window, go to the console, and type "MyGame" (or whatever game_name you have provided), you can see the properties scoped to the Game object. Every object in the game is given a reference back to the main Game object. This means that you can run multiple games in a single HTML page.
Example:
A minimal game defines at least one Room and one Player Character. If you don't provide either of these, one will be created automatically.
var MyGame = new adventurejs.Game( "MyGame", "MyGameDisplay" )
.set({
title: "Welcome Game",
author: "Ivan Cockrum",
description: "This is my great game! Thanks for playing!",
version: "0.0.1",
});
MyGame.createAsset({
class: "Room",
name: "Welcome Room",
descriptions:{ look: "You've entered the Welcome Room. " },
});
MyGame.createAsset({
class: "Player",
name: "Guest",
is: { active: true, },
place: { in: "Welcome Room" },
});
Private Constructor:
var foo = new adventurejs.Game(game_nameopt, displayElIdopt)
Parameters:
-
game_name
String <optional>
Default value: ""
A string that matches the name of the var used to store the new Game instance. Used to give the game a reference back to itself, relative to the browser window. If no name is provided, the instance name will default to "MyGame". The chief reason you might want to use a custom game_name is if you want to run multiple instance of adventure.js on a single page; give them distinct names to prevent them from colliding. You also may want to refer to your Game instance if you write any custom javascript. -
displayElId
String <optional>
Default value: ""
A string that matches the ID of an existing DOM element into which to insert the game Display. If no ID is provided, a DOM element will be created with an ID of "MyGameDisplay" and class of "ajs-display", and appended to .
- Index
- Methods
- Properties
Index
Methods:
- $directions
- $exits
- appendToOutput
- appendToOutput
- clearInput
- combineVerbs
- constructAsset
- convertTemperature
- createAsset
- createCompass
- createDeferredAssets
- createGlobalCeilings
- createGlobalExits
- createGlobalFloors
- createGlobalScenery
- createGlobalWalls
- createImageDock
- createImageLookup
- createInventoryDock
- createVerb
- createVerbDock
- debug
- diff
- disableAllVerbsBut
- disableVerbs
- enableVerbs
- findSubstanceBodyOrHeld
- findSubstanceContainers
- getAsset
- getBaselineDiff
- getCurrentRoom
- getCurrentRoomExits
- getCurrentRoomFloor
- getCustomSuccessMessage
- getExitFromDirection
- getExtendedExitName
- getGlobalAssetDescription
- getInput
- getLastTurn
- getPlayer
- getPrintableObjectList
- getStringLookup
- getVerb
- getWordCount
- initializeAssets
- isFalseOrNull
- isIdInMixedArray
- listCurrentRoomContents
- log
- mergeWorld
- patchVerb
- play
- prependToOutput
- printCurrentRoom
- printCurrentRoomContents
- printCurrentRoomExits
- printInput
- printPlayerInventory
- printRoomZoneEvents
- printWithInput
- propercase
- registerInterval
- replaceVerb
- restoreWorld
- sendToInput
- sendToParser
- set
- setGlobalDescriptions
- setPlayerRoom
- sortLookupValues
- stringToArray
- substituteHTMLTags
- tryTravel
- unregisterInterval
- unregisterInterval
- unregisterInterval
- updateDisplayCompasses
- updateDisplayInventory
- updateDisplayRoom
- updateDisplayVerbs
- validateAssetPrecursor
- validateAssets
- validateClassList
Properties:
Methods Collapse all |
$directions() → {Object}
Defined in: adventure/game/$directions.js, line 9
Returns:
Object
$exits() → {Object}
Defined in: adventure/game/$exits.js, line 9
Returns:
Object
appendToOutput(msg) → {boolean}
Defined in: adventure/Game.js, line 502
Parameters:
-
msg
String
Returns:
boolean
appendToOutput(msg) → {boolean}
Defined in: adventure/Game.js, line 516
Parameters:
-
msg
String
Returns:
boolean
clearInput()
Defined in: adventure/Game.js, line 291
combineVerbs(verbs, intoVerb) → {object}
Defined in: adventure/Game.js, line 633
Parameters:
-
verbs
object -
intoVerb
object
Returns:
object
constructAsset(source) → {Object}
Defined in: adventure/game/constructAsset.js, line 9
Parameters:
-
source
Object
A generic object containing properties to copy to a game object.
Returns:
Object
Returns an instance of whatever class was defined.
convertTemperature(temperature, parent_id) → {Boolean}
Defined in: adventure/utils/convertTemperature.js, line 4
Todos: Finish writing this.
Parameters:
-
temperature
Number | String
In Celsius. -
parent_id
String
The ID of the game object the temperature applies to.
Returns:
Boolean
createAsset(asset) → {Object}
Defined in: adventure/game/createAsset.js, line 8
Parameters:
-
asset
Object
A generic object with properties to copy into a new classed object.
MyGame.createAsset({ "class":"foo", "name":"bar", [...] })
createAsset() is a constructor function available to authors, for creating all instances of Asset and its subclasses, which includes most of the objects you'd put in a game world.
The function takes one parameter: a generic object containing properties to be passed into a class instance. For most asset classes, the only required properties are 'class' and 'name'. You'd likely also want to specify 'location', though that's not a required property. Otherwise, an author only needs to define the properties they wish to revise away from default settings.
For example, to create a simple brass key with default settings and put it in a particular location:
MyGame.createAsset({
"class":"Key",
"name":"brass key",
place: { in: "desk drawer" },
});
At runtime, createAsset() returns a new instance of the given class, uses the given name to create an id, validates the object properties, initializes the new object, and then adds it to the game world. Failure to pass any of these steps will throw an error to the console.
For more examples of how to use createAsset, see About Assets and other How To docs under Get Started.
Returns:
Object
A new Asset of the class specified in asset.class.
createCompass(properties) → {Object}
Defined in: adventure/game/createCompass.js, line 8
Parameters:
-
properties
Object
A generic object with properties used to construct a compass.
Returns:
Object
A new compass object.
createDeferredAssets()
Defined in: adventure/game/createDeferredAssets.js, line 9
Objects created here also need to be validated, since they were added to the deferred list during the initial validation pass and therefore missed validation.
createGlobalCeilings()
Defined in: adventure/game/createGlobalCeilings.js, line 9
createGlobalExits()
Defined in: adventure/game/createGlobalExits.js, line 9
createGlobalFloors()
Defined in: adventure/game/createGlobalFloors.js, line 9
createGlobalScenery()
Defined in: adventure/game/createGlobalScenery.js, line 9
createGlobalWalls()
Defined in: adventure/game/createGlobalWalls.js, line 9
createImageDock(properties) → {Object}
Defined in: adventure/game/createImageDock.js, line 8
Parameters:
-
properties
Object
A generic object with properties used to construct an image dock.
Returns:
Object
A new image dock object.
createImageLookup(asset) → {Object}
Defined in: adventure/game/createImageLookup.js, line 8
Parameters:
-
asset
Object
A generic object with properties to copy into the image library.
MyGame.createImageLookup({
images: [
{ id: "desert", image: "images/backgrounds/desert.jpg" },
{ id: "sea", image: "images/backgrounds/sea.jpg" },
{ id: "mountains", image: "images/backgrounds/mountains.jpg" },
{ id: "dungeon", image: "images/backgrounds/dungeon.jpg" },
{ id: "throneroom", image: "images/backgrounds/throneroom.jpg" },
],
});
The image library is accessible at game.image_lookup.
Returns:
Object
A reference to the image lookup.
createInventoryDock(properties) → {Object}
Defined in: adventure/game/createInventoryDock.js, line 8
Parameters:
-
properties
Object
A generic object with properties used to construct an inventory dock.
Returns:
Object
A new inventory dock object.
createVerb(verb) → {object}
Defined in: adventure/Game.js, line 607
Parameters:
-
verb
object
Returns:
object
createVerbDock(properties) → {Object}
Defined in: adventure/game/createVerbDock.js, line 8
Parameters:
-
properties
Object
A generic object with properties used to construct the verb dock.
Returns:
Object
A new verb dock object.
debug(token)
Defined in: adventure/game/debug.js, line 8
Parameters:
-
token
String
diff(baseline_object, updated_object) → {Object}
Defined in: adventure/utils/diff.js, line 5
Parameters:
-
baseline_object
Object
Old object -
updated_object
Object
New object
Returns:
Object
disableAllVerbsBut(verbs) → {object}
Defined in: adventure/Game.js, line 583
Parameters:
-
verbs
object
Returns:
object
disableVerbs(verbs) → {object}
Defined in: adventure/Game.js, line 571
Parameters:
-
verbs
object
Returns:
object
enableVerbs(verbs) → {object}
Defined in: adventure/Game.js, line 595
Parameters:
-
verbs
object
Returns:
object
findSubstanceBodyOrHeld(asset_id) → {Array}
Defined in: adventure/game/findSubstanceBodyOrHeld.js, line 9
Parameters:
-
asset_id
String
Returns:
Array
findSubstanceContainers(asset_id, selects) → {Array}
Defined in: adventure/game/findSubstanceContainers.js, line 9
Parameters:
-
asset_id
String -
selects
Array
Returns:
Array
getAsset(identifier, params) → {String}
Defined in: adventure/game/getAsset.js, line 9
Parameters:
-
identifier
String
Name or ID of a game object. -
params
Object
Used to check for 'prefer_substance' in cases of looking for substances in containers.
Returns:
String
An object ID.
getBaselineDiff(source_world) → {String}
Defined in: adventure/utils/getBaselineDiff.js, line 6
Parameters:
-
source_world
Object
Returns:
String
Returns a stringified diff.
getCurrentRoom() → {Object}
Defined in: adventure/game/getCurrentRoom.js, line 9
Returns:
Object
getCurrentRoomExits() → {String}
Defined in: adventure/game/getCurrentRoomExits.js, line 9
Returns:
String
A formatted list of exits.
getCurrentRoomFloor() → {Object}
Defined in: adventure/game/getCurrentRoomFloor.js, line 9
Returns:
Object
getCustomSuccessMessage(asset, verbName) → {Boolean}
Defined in: adventure/game/getCustomSuccessMessage.js, line 9
Parameters:
-
asset
Object
A game asset. -
verbName
String
A verb name.
Returns:
Boolean
getExitFromDirection(direction) → {Object}
Defined in: adventure/game/getExitFromDirection.js, line 9
Parameters:
-
direction
String
Returns:
Object
An exit.
getExtendedExitName(exit, destination) → {String}
Defined in: adventure/game/getExtendedExitName.js, line 9
Parameters:
-
exit
Object -
destination
Object
Returns:
String
getGlobalAssetDescription(asset) → {String}
Defined in: adventure/game/getGlobalAssetDescription.js, line 9
Parameters:
-
asset
Object | String
Global assets are a bit (perhaps overly) complicated. They exist as singular objects in the game world, and they can be enabled/disabled and have their descriptions overridden per room and per zone.
For example:
MyGame.world.global_air
is an assetMyGame.world.room.room_scenery.global_air
is a simple object that can be used to determine whether
a global asset is available in a given room. MyGame.world.zone.zone_scenery.global_air
is a simple object that can be used to determine whether
a global asset is available in a given zone. Returns:
String
A description of the specified asset id.
getInput() → {Object}
Defined in: adventure/game/getInput.js, line 9
Returns:
Object
getLastTurn() → {Object}
Defined in: adventure/game/getLastTurn.js, line 9
Returns:
Object
getPlayer() → {Object}
Defined in: adventure/game/getPlayer.js, line 9
Returns:
Object
getPrintableObjectList(objects, exclusions) → {String}
Defined in: adventure/game/getPrintableObjectList.js, line 9
Parameters:
-
objects
Object
An array of object ID strings. -
exclusions
Object
An array of of object ID strings to exclude.
Returns:
String
A formatted string.
getStringLookup(verbs) → {object}
Defined in: adventure/Game.js, line 546
Parameters:
-
verbs
object
Returns:
object
getVerb(verb) → {object}
Defined in: adventure/Game.js, line 558
Parameters:
-
verb
string
Returns:
object
getWordCount() → {Array}
Defined in: adventure/game/getWordCount.js, line 8
getWordCount() is a utility method to get a count of all the unique words the game "knows".
Returns:
Array
initializeAssets()
Defined in: adventure/game/initializeAssets.js, line 9
isFalseOrNull(value) → {Boolean}
Defined in: adventure/utils/isFalseOrNull.js, line 4
Parameters:
-
value
*
Returns:
Boolean
isIdInMixedArray(array) → {Array}
Defined in: adventure/utils/isIdInMixedArray.js, line 5
Parameters:
-
array
Array
- convert ' ' to '_'
- convert ' and ' to '&'
- convert '.' to '$'
Returns:
Array
listCurrentRoomContents(room) → {String}
log(method, level, msg)
Defined in: adventure/game/log.js, line 8
Parameters:
-
method
String | Number
0=log, 1=warn, 2=error -
level
String | Number
0=critical, 1=high, 2=medium, 3=low -
msg
*
Message for console.
mergeWorld(source, dest) → {Object}
Defined in: adventure/utils/mergeWorld.js, line 5
Parameters:
-
source
Object -
dest
Object
Returns:
Object
dest
patchVerb(patch_verb) → {object}
Defined in: adventure/Game.js, line 647
Parameters:
-
patch_verb
object
plug.phrase1
and in your game file, call patchVerb with
line visible: true
removed.
MyGame.patchVerb({
name: "plug",
phrase1:{
accepts_noun: true,
requires_noun: true,
accepts_preposition: true,
noun_must_be:
{
known: true,
tangible: true,
present: true,
visible: true,
reachable: true,
},
},
});
( game.patchVerb() actually forwards to game.dictionary.patchVerb() ).
Returns:
object
play()
Defined in: adventure/game/play.js, line 9
Returns:
adventurejs.GameprependToOutput(msg) → {boolean}
Defined in: adventure/Game.js, line 530
Parameters:
-
msg
String
Returns:
boolean
print(msg, classes)
Defined in: adventure/game/print.js, line 8
Parameters:
-
msg
String -
classes
String
printCurrentRoom(params)
Defined in: adventure/game/printCurrentRoom.js, line 9
Todos: Formalize handling for description/brief/verbose descriptions
Parameters:
-
params
Object
For example:
printCurrentRoom( { verbose: true } )
printCurrentRoomContents()
Defined in: adventure/game/printCurrentRoomContents.js, line 9
printCurrentRoomExits()
Defined in: adventure/game/printCurrentRoomExits.js, line 9
printInput(input)
Defined in: adventure/game/printInput.js, line 9
Parameters:
-
input
String
printPlayerInventory()
Defined in: adventure/game/printPlayerInventory.js, line 9
printRoomZoneEvents()
Defined in: adventure/game/printRoomZoneEvents.js, line 9
printWithInput(msg, classes)
Defined in: adventure/game/printWithInput.js, line 9
Parameters:
-
msg
String -
classes
String
propercase(string) → {String}
Defined in: adventure/utils/propercase.js, line 5
Parameters:
-
string
String
Returns:
String
registerInterval(id, callback)
Defined in: adventure/Game.js, line 683
Todos: add number of turns as a param and only call per x turn
Parameters:
-
id
string
id of Asset which owns the function. -
callback
string
The function to call on interval.
replaceVerb(oldVerb, newVerb) → {object}
Defined in: adventure/Game.js, line 619
Parameters:
-
oldVerb
object -
newVerb
object
Returns:
object
restoreWorld(source)
Defined in: adventure/utils/restoreWorld.js, line 6
Parameters:
-
source
Object
sendToInput()
Defined in: adventure/Game.js, line 282
sendToParser()
Defined in: adventure/Game.js, line 270
set(props) → {adventurejs.Game}
Defined in: adventure/game/set.js, line 9
Parameters:
-
props
Object
A generic object containing properties to copy to the Game instance.
setGlobalDescriptions(globals)
Defined in: adventure/game/setGlobalDescriptions.js, line 9
Parameters:
-
globals
Object
A list of globle Scenery Assets.
setPlayerRoom(newRoom, params)
Defined in: adventure/game/setPlayerRoom.js, line 9
Parameters:
-
newRoom
Object
A room object to which to move player. -
params
Object
sortLookupValues()
Defined in: adventure/game/sortLookupValues.js, line 9
stringToArray(string) → {Array}
Defined in: adventure/utils/stringToArray.js, line 4
Parameters:
-
string
String
Returns:
Array
substituteHTMLTags(msg) → {String}
Defined in: adventure/utils/substituteHTMLTags.js, line 5
Parameters:
-
msg
String
A string on which to perform substitutions.
For example:
MyGame.createAsset({ class: "Room", name: "Standing Room", descriptions: { brief: "The north door is
Returns:
String
tryTravel(direction, params)
Defined in: adventure/game/tryTravel.js, line 9
Parameters:
-
direction
String -
params
Object
unregisterInterval(id, callback)
Defined in: adventure/Game.js, line 702
Parameters:
-
id
string
id of Asset which owns the function. -
callback
string
The function to call on interval.
unregisterInterval()
Defined in: adventure/Game.js, line 726
unregisterInterval()
Defined in: adventure/Game.js, line 750
updateDisplayCompasses()
Defined in: adventure/Game.js, line 367
updateDisplayInventory()
Defined in: adventure/Game.js, line 392
updateDisplayRoom()
Defined in: adventure/Game.js, line 334
updateDisplayVerbs()
Defined in: adventure/Game.js, line 382
Todos: this has no logic yet
validateAssetPrecursor(child) → {Object}
Defined in: adventure/game/validateAssetPrecursor.js, line 9
Parameters:
-
child
Object
A generic object.
Returns:
Object
A classed object.
validateAssets()
Defined in: adventure/game/validateAssets.js, line 9
validateClassList(property) → {Array}
Defined in: adventure/utils/validateClassList.js, line 4
Todos: Is this unused?
Parameters:
-
property
String | Array
Returns:
Array
Properties |
author :String
baseline
Defined in: adventure/Game.js, line 165
baseline
stores a copy of the initial
game world, for comparison in save/restore and undo.
class_lookup
Defined in: adventure/Game.js, line 180
class_lookup
stores a lookup table
containing the ids of all assets by class.
currentRoom :Object
Defined in: adventure/Game.js, line 463
- Use game.getCurrentRoom() instead.
game :Object
Defined in: adventure/Game.js, line 92
Default value: {}
game_name :String
Defined in: adventure/Game.js, line 101
image_lookup
Defined in: adventure/Game.js, line 194
image_lookup
stores a lookup table
for optional images supplied by author.
input :Object
Defined in: adventure/Game.js, line 472
- Use game.getInput() instead.
inventorydocks :Object
Defined in: adventure/Game.js, line 252
inventorydocks
is an array that
stores references to any custom inventorydocks.
last_turn :Object
Defined in: adventure/Game.js, line 481
- Use game.getLastTurn() instead.
player :Object
Defined in: adventure/Game.js, line 454
- Use game.getPlayer() instead.
room_lookup
Defined in: adventure/Game.js, line 187
room_lookup
stores an array
containing the ids of all rooms.
score :String
scorecard :Object
Defined in: adventure/Game.js, line 230
scorecard
is a singleton class
that stores all the game's score events
and functions for managing score.
settings :Object
Defined in: adventure/Game.js, line 121
settings
is a singleton class
that stores all the game's global settings.
title :String
version :String
world
Defined in: adventure/Game.js, line 132
world
stores all the game asset
objects. It also stores a handful of variables
such as _player and _currentRoom which are used
for convenience. It also stores any global vars
created by the game's author. This last is done
to give authors a place to store vars that can
be written out with saved games.
world_lookup
Defined in: adventure/Game.js, line 144
world._vars
is a namespace for
authors to store any custom vars that they
would like to be written out with saved games,
so that they can be restored along with other
saved game data in order to retain game state.
world_lookup
Defined in: adventure/Game.js, line 173
world_lookup
stores a lookup table
containing indexed keywords for all game assets.