Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0

Don't Panic

We assume that you already know what a text adventure game is and how to play one. (If you don't, here's a basic primer).

 
 

Your index file will look like this.

If you downloaded the sample index, it looks exactly like this.

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My Game</title>
    <meta charset="utf-8">
    <link href="css/adventurejs.css" rel="stylesheet" type="text/css">
  </head>
  <body class="ajs night">
    <div id="MyGameDisplay" class="ajs-display"></div>
    <script src="js/adventure.min.js"></script>
    <script src="js/MyGame.js"></script>
    <!-- You may want to break your game into multiple files. -->
    <!-- Just load them all here! -->
    <script>
      window.addEventListener('DOMContentLoaded', (event) => {
      MyGame.play();
    });
    </script>
  </body>
</html>
 

Your game code will look like this.

But probably longer. Much, much, longer.
You may find it useful to organize it into multiple files.

First, set up the game.

// MyGame.js
var MyGame = new adventurejs.Game( "MyGame", "MyGameDisplay" ).set({
  title: "Dungeon Drifter",
  author: "Dungeon Master Dan",
  description: "Welcome to the dungeon, baby!",
  version: "0.0.1",
});

Next, create a room.

MyGame.createAsset({
  class: "Room",
  name: "Dungeon Antechamber",
  description: "You're in a dingy dungeon antechamber. The air here is dank and oppressive, leavened only by a slight draft of fresh air at your back. A dark path descending to the north is bound by a massive wood planked door. Every surface of the dungeon seems to be made of pitted cobblestones. The cobblestones around the door frame appear to be particularly irregular. ",
  exits: 
  {
    south: "You feel the lure of the tiny patch of sky that's still visible through the entrance... but you don't want to leave without the treasure! ",
  },
});

Add a player character.

MyGame.createAsset({
  class: "Player",
  name: "Mighty Hero",
  is: { active: true, },
  doMoveThisToThat: 
  {
    "Central Chamber": function() 
    {
      MyGame.scorecard.completeEvent('enter central chamber');
    }
  },
});

And now, add some objects.

(Only a few example objects are shown here. The example game file contains more.)

MyGame.createAsset({
  class: "Exit",
  direction: "north",
  place: { in:  "Dungeon Antechamber" },
  destination: "Central Chamber",
  aperture: "wood planked door",
});
MyGame.createAsset({
  class: "Door",
  name: "wood planked door",
  adjectives: ["massive"],
  place: { in:  "Dungeon Antechamber" },
  is: { 
    closed: true, 
    locked: true, 
  },
  linked_asset: "iron bound door",
  direction: "north",
  description: "The imposing door is made of thick wooden planks, bound solidly together with corroded, but still quite strong, iron straps. ",
});
MyGame.createAsset({
  class: "Key",
  name: "beaten iron key",
  dov: { 
    take: { 
      on_first_success: function(){
        MyGame.scorecard.completeEvent('take iron key');
      },
    }, 
  },
  iov: { 
    unlock: { 
      with_assets: ['wood planked door'], 
      on_first_success: function(){
        MyGame.scorecard.completeEvent('unlock door');
      },
    }, 
  },
  description: "It's a thick, heavy key made of beaten iron. ",
  article: "a",
  adjectives: [ "thick", "heavy" ],
  place: { in: "pitted cobblestone" },
});
MyGame.createAsset({
  class: "Chest",
  name: "battered chest",
  place: { in: "Inner Sanctum" },
  is: { closed: true, locked: true },
  dov: { 
    lock: with_assets:[ "melted brass key" ],
    unlock: with_assets:[ "melted brass key" ],
    open:
    {
      doAfterSuccess: function()
      {
        if( MyGame.$("glowing chalice").isIn("battered chest") )
        {
          MyGame.print( "The chalice glows warmly inside the chest, drawing you to it. If half of the legends are true..." );
        }
      },
    },
  }, 
  description: "The battered chest appears to be made of fire hardened teak or walnut bound with straps of dark, tarnished brass. ",
  adjectives: [ "treasure", "wood", "brass", "dark", "tarnished", "teak", "walnut" ],
  synonyms: [ "lock" ],
});
 

And that's it!

Ok, there are a few more things to know.
But this basic setup is all you need to get started.


Where to dig in next? We recommend jumping into How to Create a Game of course. It will step you through creating the complete game shown above. If you're already Javascript conversant, you might jump straight to Start Scripting. You might also browse through the asset reference and verb reference to get a sense of the built-in features that are available for you to use in authoring your game. Adventure.js has many pre-defined asset classes and over 130 pre-written verbs with complete logic for handling any kind of assets.