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

›Tipy a triky

Hra

  • Přehled
  • Object
  • Hra
  • Perspektiva
  • Bodování
  • Epic mode
  • Věže

Koncepty

  • Unites
  • Válečník
  • Abilities
  • Spaces

API hráče

  • API pole
  • API jednotky
  • API tahu

Tipy a triky

  • Obecné
  • JavaScript
  • Umělá inteligence
  • CLI

CLI

  • Install
  • Options
Translate

JavaScript tipy

  • Nevyplň svou playTurn metodu množstvím kódu, organizuj svůj kód metodami a classami. Například:
class Player {
  playTurn(warrior) {
    if (this.isInjured(warrior)) {
      warrior.rest();
    }
  }

  isInjured(warrior) {
    return warrior.health() < 20;
  }
}
  • Pokd chceš spustit nějaký kód na začátku každého patra, definuj constructor v Player classe, třeba takto:
class Player {
  constructor() {
    // This code will be executed only once, at the beginning of the level.
    this.health = 20;
  }

  // ...
}
  • Můžeš volat metody Space API ihned po 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();
  }
}
← Obecné tipyAI tipy →
WarriorJS Docs
Docs
PlayerMaker
Community
SpectrumTwitterFollow WarriorJS on Twitter
More
DonateGitHubStar