Above is a live demo of a game made using text-engine. It's designed to be a little obtuse. Try typing something and hitting ENTER. Don't trust everything it tells you.
text-engine (source on Github)
What is it?
To create your own adventure, use
game-disks/unlimited-adventure.js as a template.
Include your 'game disk' (JSON data) in
index.html and load it with
The end product will be your very own text adventure game, similar to this one.
You're right. Here are some more in-depth instructions...
text-engine uses a disk metaphor for the data which represents your game, like the floppy disks of yore. Including
index.js from this repository in your
<script>s adds a single function to the global namespace:
roomId(String) - This is a reference to the room the player currently occupies. Set this to the ID of the
roomthe player should start in.
inventory(Array) - List of
items in the player's inventory.
items will be discussed in more detail below.
rooms(Array) - List of
rooms in the game.
Note that you can also add any custom properties you want anywhere on this object. You will be able to access and modify them via the
use functions on your items, which will be passed a reference to your disk. More on the
A room is an object with the following properties:
name(String) - The name of the room will be displayed each time it is entered.
id(String) - Unique identifier for this room. Can be anything.
img(String) - Graphic to be displayed each time the room is entered. (This is intended to be ASCII art.)
desc(String) - Description of the room, displayed when it is first entered, and also when the player issues the
items(Array) - List of
items in this room.
items can be interacted with by the player.
exits(Array) - List of paths from this room.
An exit is an object with the following properties:
dir(String) - The direction the player must go to leave via this exit.
id(String) - The ID of the room this exit leads to.
An item is an object with the following properties:
name(String) - How the item is referred to by the game and the player.
desc(String) - Text displayed when the player
looks at the item.
isTakeable(Boolean) - Optional - Whether the player can pick up this item (if it's in a room). Defaults to false.
use(Function) - Optional - Function to be called when the player uses the item.
Use functions accept a
disk (Object) - A reference to your game disk. Can be used to add or change properties. For instance, to make an item which previously could not be picked up takeable.
println (Function) - The function which prints output for the player to see. Accepts a string.
getRoom (Function) - Convenience function for retrieving a reference to a room on the disk. Accepts
roomId as a String.
enterRoom (Function) - The function which moves a player to a room. Accepts
roomId as a String.
That's everything! If you've made a JSON object with all these properties -- that is, a disk -- you've got a playable game!
Just pass a reference to your disk to the loadDisk function. Take a look at
index.html to see an example. I've saved my disk to a
const variable called
game-disks/unlimited-adventure.js. I've included that file and
index.js in my HTML file, and added a script tag with a single line to call
loadDisk(unlimitedAdventure). The game boots when
index.html is loaded in a browser.
You can use the included
index.html file in your own project, or you can create your own. If you make your own, note that you will need to add two elements:
output. This is where the game text will appear.
input. This is where the user will enter commands.
<code><input id="input" autofocus>
- ASCII Paint - Makes creating ASCII art super easy.
- ASCII-Code.com - Convenient for copying and pasting ASCII characters.
- INV command added!Sep 24, 2017