warriorjs-engine
The bowels of WarriorJS
Last updated 4 years ago by olistic .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install warriorjs-engine 
SYNC missed versions from official npm registry.

banner

Travis npm

WarriorJS Engine

There's a small chance that you have played the game WarriorJS before, and an even smaller chance that you have come here intentionally, so you may be wondering what's this all about...

This is the rules engine behind WarriorJS, distributed as a standalone npm package.

Installation

$ npm install --save warriorjs-engine

API Reference

The WarriorJS Engine API exposes a single yet important function:

playLevel(levelConfig, playerCode, [maxTurns])

Plays a WarriorJS level using the player's code.

Arguments

  1. levelConfig (Object): The configuration of the level, with the following members:
  • timeBonus (Number): Amount of turns the player has to complete the level obtaining bonus points.
  • floor (Object): The floor of the level, with the following members:
    • size (Object): The size of the floor.
    • stairs (Object): The position of the stairs.
    • warrior (Object): The player's warrior.
    • units (Array): The other units in the level.
  1. playerCode (String): The code written by the player.
  2. [maxTurns] (Number): The maximum number of turns that will be played.

Returns

(Object) An object containing the play result with the following members:

  • passed (Boolean): Whether the level was passed or not.
  • score (Object):
    • warrior (Number): The points earned by the warrior by killing units and rescuing captives.
    • timeBonus (Number): A bonus for completing the level in less than a specified amount of turns.
    • clearBonus (Number): A bonus for defeating all enemies and rescuing all captives.
  • events (Array): The sequence of events that took place during the play.

Example

import playLevel from 'warriorjs-engine';

const levelConfig = {
  timeBonus: 15,
  floor: {
    size: {
      width: 8,
      height: 1
    },
    stairs: {
      x: 7,
      y: 0
    },
    warrior: {
      name: 'Spartacus',
      x: 0,
      y: 0,
      facing: 'east',
      abilities: [
        {
          name: 'walk',
          args: []
        },
        {
          name: 'attack',
          args: []
        },
        {
          name: 'feel',
          args: []
        }
      ]
    },
    units: [
      {
        type: 'sludge',
        x: 4,
        y: 0,
        facing: 'west'
      }
    ]
  }
};

const playerCode = `
  class Player {
    playTurn(warrior) {
      if (warrior.feel().isEnemy()) {
        warrior.attack();
      } else {
        warrior.walk();
      }
    }
  }
`;

const { passed, score, events } = playLevel(levelConfig, playerCode);

Current Tags

  • 1.0.0                                ...           latest (4 years ago)
  • 2.0.0-alpha.4                                ...           next (4 years ago)

22 Versions

  • 2.0.0-alpha.4                                ...           4 years ago
  • 2.0.0-alpha.3                                ...           4 years ago
  • 2.0.0-alpha.2                                ...           4 years ago
  • 2.0.0-alpha.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
  • 0.11.0                                ...           4 years ago
  • 0.10.2                                ...           4 years ago
  • 0.10.1                                ...           4 years ago
  • 0.10.0                                ...           5 years ago
  • 0.9.0                                ...           5 years ago
  • 0.8.1                                ...           5 years ago
  • 0.8.0                                ...           5 years ago
  • 0.7.0                                ...           5 years ago
  • 0.6.0                                ...           5 years ago
  • 0.5.0                                ...           5 years ago
  • 0.4.2                                ...           5 years ago
  • 0.4.1                                ...           5 years ago
  • 0.4.0                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.1                                ...           5 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (9)
Dev Dependencies (11)

Copyright 2014 - 2016 © taobao.org |