WarriorJS Docs
  • Игрок
  • Разработчик
  • Сообщество
  • Русский
    • English
    • العربية
    • Català
    • Čeština
    • Deutsch
    • Ελληνικά
    • Español
    • Français
    • Italiano
    • Polskie
    • Српски језик (Ћирилица)
    • Svenska
    • Türkçe
    • 中文
    • 繁體中文
    • Помочь с переводом
  • GitHub

›Советы и Подсказки

Игра

  • Обзор
  • Объект
  • Игровой процесс
  • Перспектива
  • Система баллов
  • Эпический режим
  • Towers

Основы

  • Существа
  • Воин
  • Способности
  • Разделы

API игрока

  • API Областей
  • Unit API
  • API Хода

Советы и Подсказки

  • Основныe
  • JavaScript
  • Искусственный Интеллект
  • CLI

CLI

  • Install
  • Options
Translate

Советы по JavaScript

  • Don't simply fill up the playTurn method with a lot of code, organize your code with methods and classes. For example:
class Player {
  playTurn(warrior) {
    if (this.isInjured(warrior)) {
      warrior.rest();
    }
  }

  isInjured(warrior) {
    return warrior.health() < 20;
  }
}
  • If you want some code to be executed at the beginning of each level, define a constructor in the Player class, like this:
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();
  }
}
← Общие подсказкиСоветы по AI →
WarriorJS Docs
Docs
PlayerMaker
Community
SpectrumTwitterFollow WarriorJS on Twitter
More
DonateGitHubStar