GithubHelp home page GithubHelp logo

textadventurejs's Introduction

TextAdventureJS

A text based adventure engine written in Javascript.

Here's a very basic example, that is included in this Repositroy: https://dak0r.github.io/TextAdventureJS/example.html

A different project, that uses TextAdventureJS can be foundon my website: https://www.danielkorgel.com

Usage

See example.html for a working minimal example.

   // Defines where to write output
   function witeLine(outputLine){                
      $("#outputArea").append(outputLine);       
   }
   // Clears output area
   function clearArea(){
      $("#outputArea").val("");         
   }

   // Init engine and load a game
   var textAdv = new textAdventureEngine(witeLine, clearArea);
   textAdv.loadDatabaseFromFile("game.TADB.json");

   // Send Input to game
   textAdv.input("look at cookie");

Game Database

A Text Adventure Database (TADB) is JSON file which describes games that can run in the TextAdventureJS Engine.

.tadb.json files can be validated using the JSON schema in this repo: textAdventureDatabase.schema.json. The schema contains also includes descriptions for the properties. I recommend using the JSON Schema Validator for this task.

Concept

Each game exists of objects which are either in the players inventory or in locations. The player can interact with object using verbs.

Locations

Locations are basically groups of objects.

The description text of a location soley exists of the objects which can be found in it. This means an empty location has no description. Thus a location should always have at least one object, at any given moment.

Verbs

Verbs are commands that the user can type.
Each verb has a...

  • a name
  • list of synonyms (words)
  • a text that is shown, in case the verb can't be used with the object the user mentioned (failure)
    E.G. if the user tries to 'open' an object, that can't be opened.

Objects

Everything that player can see or interact with is an object.

Each object has...

  • a unique name
  • a list of words that the player can type to refer to this object
  • an optional text that is added to the location description if the object is in the players current location or in his inventory (locationDescription)
  • a list of actions which describes the verbs that can be used with this object.
    each of these actions has...
    • a text that will be shown if the verb is used with this object
    • zero, one or more functions listed under action, which can be used to change the current location and its objects (see Functions)
    • a list of 'usableObjects' which is currently unused.
      It is designed to implement usage of object with other objects.

Changing Objects

In almost every game there are scenarios where objects have to change their description texts or behaviors during gameplay. For example if you need a chest which the player can open only once, after that it will be open.

In this case you have to create a second object chest_opened, which has it's own description and verbs it can handle. Now you can use the objectReplaceInLocation function in chests open action to replace chest in the current location with chest_opened.

To close the chest again, you can use objectReplaceInLocation again in chest_openeds close action.

Functions

Functions can be used in actions to modify the current location or the plazers inventory.

objectRemoveFromLocation

objectRemoveFromLocation {objectId}

Removes the given object from the current location

objectAddToLocation

objectAddToLocation {objectId}

Adds a given object to the current location

objectReplaceInLocation

objectReplaceInLocation {objectIdToRemove} {objectIdToAdd}

Removes {objectIdToRemove} and adds {objectIdToAdd}. Shorthand for sequentially calling objectRemoveFromLocation and objectAddToLocation.

Useful if an object transitions into a different one like chest_closed to chest_opened.

gotoLocation

gotoLocation {locationId}

Changes the current location to a different one

showLocationDescription

showLocationDescription

Automatically shows the current location description, as if the user typed 'look'

inventoryAdd

inventoryAdd {objectId}

Adds the item to users inventory. The user can have multiple items in his inventory, the location descriptions will be listed below each other.

inventoryRemove

inventoryRemove {objectId}

Removes the item from users inventory

textadventurejs's People

Contributors

dak0r avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.