WarriorJS Docs
  • Player
  • Maker
  • Comunitat
  • Català
    • English
    • العربية
    • Čeština
    • Deutsch
    • Ελληνικά
    • Español
    • Français
    • Italiano
    • Polskie
    • Русский
    • Српски језик (Ћирилица)
    • Svenska
    • Türkçe
    • 中文
    • 繁體中文
    • Ajuda Traduir
  • GitHub

›Consells i trucs

Joc

  • Visió general
  • Objecte
  • Joc
  • Perspectiva
  • Puntuació
  • Mode épico
  • Torres

Conceptes

  • Unitats
  • Guerrer
  • Habilitats
  • Espais

API del reproductor

  • API espacial
  • API de la unitat
  • Activa l'API

Consells i trucs

  • General
  • JavaScript
  • Artificial Intelligence
  • CLI

CLI

  • Install
  • Options
Translate

Consells sobre JavaScript

  • No simplement ompli el mètode playTurn amb molt codi, ** organitzeu el vostre codi amb mètodes i classes **. Per exemple:
class Player {
  playTurn(warrior) {
    if (this.isInjured(warrior)) {
      warrior.rest();
    }
  }

  isInjured(warrior) {
    return warrior.health() < 20;
  }
}
  • Si voleu que s'executi algun codi al principi de cada nivell, definiu ** un constructor a la classe Player/strong>, així:

jugador de classe {
   constructor () {
     // Aquest codi s'executarà només una vegada, al principi del nivell.
     this.health = 20;
   }

   // ...
}
  • Podeu trucar als mètodes de l'API espacial directament després d'un sentit. For example, the "feel" sense in the "Baby Steps" tower returns one space. You can call isEmpty() on this to determine if the space is clear before walking there:
class Player {
  playTurn(warrior) {
    if (warrior.feel().isEmpty()) {
      warrior.walk();
    }
  }
}
  • Some senses (like "look" and "listen" in the "Baby Steps" tower) return an array of spaces instead, so you might find many of the Array prototype methods really useful. Here is an example of the Array.prototype.find method:
class Player {
  // ...

  isEnemyInSight(warrior) {
    const spaceWithUnit = warrior.look().find(space => space.isUnit());
    return spaceWithUnit && spaceWithUnit.getUnit().isEnemy();
  }
}
← Consells generalsConsells de IA →
WarriorJS Docs
Docs
PlayerMaker
Community
SpectrumTwitterFollow WarriorJS on Twitter
More
DonateGitHubStar