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

  /**
   * @augments {adventurejs.Verb}
   * @class left
   * @ajsnode game.dictionary.verbs.left
   * @ajsconstruct MyGame.createVerb({ "name": "left", [...] });
   * @ajsconstructedby adventurejs.Dictionary#createVerb
   * @hideconstructor
   * @ajsinstanceof Verb
   * @ajsnavheading DirectionVerbs
   * @summary Verb meaning travel to left direction.
   * @tutorial Verbs_Subscriptions
   * @tutorial AdvancedVerbs_VerbAnatomy
   * @tutorial AdvancedVerbs_VerbProcess
   * @tutorial AdvancedVerbs_ModifyVerbs
   * @tutorial AdvancedVerbs_ModifyVerbs
   * @classdesc
   * <pre class="display border outline">
   * <span class="ajs-player-input">&gt; left</span>
   * You turn to the left. Cannons. You turn to the right. More cannons. You turn back to front. Still more cannons. You're beginning to understand why they call it "the valley of Death".
   * </pre>
   * <p>
   * Direction verb: go <strong>left</strong>. Because left is a relative
   * direction, it's assumed that there probably won't be a left exit, though
   * it does support one. The verb logic looks for a port exit first,
   * which would be left in nautical terms, then looks for a left exit,
   * then defaults to telling the player they turn in place.
   * To learn about {@link adventurejs.Exit|Exits},
   * see <a href="/doc/GettingStarted_CreateAnExit.html">Create an Exit</a>.
   * </p>
   * @ajsverbreactions doRemoveThisFromThat, doRemoveThatFromThis, doMoveThisToThat, doMoveThatToThis
   * @ajsverbphases doBeforeTry, doAfterTry, doBeforeSuccess, doAfterSuccess
   */
  A.Preverbs.left = {
    name: "left",
    is_direction: true,
    is_relative_direction: true,
    synonyms: ["left"],
    type: { direction: true },
    adjective: "leftward",
    article: "the",

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

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

    doSuccess: function () {
      // compose output
      var msg = `{We} turn to the ${this.name}. `;

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