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

›Tipps & Tricks

Spiel

  • Übersicht
  • Ziel
  • Gameplay
  • Perspektive
  • Punkte erzielen
  • Epic-Mode
  • Türme

Konzepte

  • Einheiten
  • Kämpfer
  • Fähigkeiten
  • Bereiche

Player API

  • Space API
  • Unit API
  • Turn API

Tipps & Tricks

  • Allgemeines
  • JavaScript
  • Künstliche Intelligenz
  • CLI

CLI

  • Install
  • Options
Translate

JavaScript-Tipps

  • Schreibe deinen Code nicht komplett in die playTurn-Methode, sondern nutze Methoden und Klassen, um deinen Code zu organisieren. Als Beispiel:
class Player {
  playTurn(warrior) {
    if (this.isInjured(warrior)) {
      warrior.rest();
    }
  }

  isInjured(warrior) {
    return warrior.health() < 20;
  }
}
  • Falls du möchstest, dass bestimmer Code zu Beginn des Levels ausgeführt wird, erstelle einen Konstruktor in der Player-Klasse:
class Player {
  constructor() {
    // This code will be executed only once, at the beginning of the level.
    this.health = 20;
  }

  // ...
}
  • Du kannst Methoden der Space-API aufrufen sobald du einen Bereich (Space) wahrgenommen hast. 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();
  }
}
← Allgemeine TippsKI-Tipps →
WarriorJS Docs
Docs
PlayerMaker
Community
SpectrumTwitterFollow WarriorJS on Twitter
More
DonateGitHubStar