Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0
// backward.js
(function () {
  /*global adventurejs A*/

  /**
   * @augments {adventurejs.Verb}
   * @class backward
   * @ajsnode game.dictionary.verbs.backward
   * @ajsconstruct MyGame.createVerb({ "name": "backward", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading DirectionVerbs
   * @summary Verb meaning to move backward.
   * @tutorial Scripting_VerbSubscriptions
   * @tutorial Verbs_VerbAnatomy
   * @tutorial Verbs_VerbProcess
   * @tutorial Verbs_ModifyVerbs
   * @tutorial Verbs_WriteVerbs
   * @classdesc
   * <pre class="display border outline">
   * <span class="input">&gt; backward</span>
   * You back a step away. And then another. And another.
   * Slowly you turn. And run!
   * </pre>
   * <p>
   * Direction verb: go <strong>backward</strong>. Because backward is a relative
   * direction, it's assumed that there probably won't be a backward exit, though
   * it does support one. The verb logic looks for an aft exit first,
   * which would be backward in nautical terms, then looks for a backward exit,
   * then defaults to telling the player they move backward. Useful if you want
   * to let a player navigate a dungeon using relative directions.
   * To learn about {@link adventurejs.Exit|Exits},
   * see <a href="/doc/GetStarted_CreateAnExit.html">Create an Exit</a>.
   * </p>
   * @ajsverbreactions doRemoveThisFromThat, doRemoveThatFromThis, doMoveThisToThat, doMoveThatToThis
   * @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
   */
  A.Preverbs.backward = {
    name: "backward",
    is_direction: true,
    is_relative_direction: true,
    synonyms: ["backward", "backwards", "back"],
    type: { direction: true },
    adjective: "backward",
    article: "",

    /**
     * @ajsverbstructures
     * @memberof backward
     */
    accepts_structures: ["verb"],

    doTry: function () {
      var results;
      if (this.game.getCurrentRoom().exits.fore) {
        results = this.game.tryTravel("fore");
        if (!results) {
          this.handleFailure();
        }
      } else if (this.game.getCurrentRoom().exits.backward) {
        results = this.game.tryTravel("backward");
        if (!results) {
          this.handleFailure();
        }
        return results;
      }
      return true;
    },

    doSuccess: function () {
      // compose output
      var msg = `$(We) move ${this.name} a bit. `;

      // print output
      return this.handleSuccess(msg);
    },
  };
})();