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

›Trucs et Astuces

Jeu

  • Aperçu
  • Objectif
  • Gameplay
  • Perspective
  • Score
  • Mode Épique
  • Towers

Concepts

  • Unités
  • Guerrier
  • Aptitudes
  • Espaces

API joueur

  • API de l'espace
  • API des unités
  • API des tours

Trucs et Astuces

  • Général
  • JavaScript
  • Intelligence artificielle
  • CLI

CLI

  • Install
  • Options
Translate

Conseils JavaScript

  • Il ne faut pas remplir la méthode playTurn de lignes de code, mais organiser votre code selon des méthodes et classes. Par exemple :
class Player {
  playTurn(warrior) {
    if (this.isInjured(warrior)) {
      warrior.rest();
    }
  }

  isInjured(warrior) {
    return warrior.health() < 20;
  }
}
  • Si vous voulez exécuter un code au début de chaque niveau, définissez un constructeur dans la classe Player, de cette façon :
class Player {
  constructor() {
    // This code will be executed only once, at the beginning of the level.
    this.health = 20;
  }

  // ...
}
  • You can call methods of the Space API directly after a sense. 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();
  }
}
← Conseils GénérauxAstuces d'IA →
WarriorJS Docs
Docs
PlayerMaker
Community
SpectrumTwitterFollow WarriorJS on Twitter
More
DonateGitHubStar