Acabo de empezar https://warriorjs.com/ . Estoy en el nivel 5 ahora, puedo hacer esto haciendo un millón de sentencias if else, pero vi a personas hacer funciones separadas, para que sea más fácil trabajar y leer más adelante.
class Player { /** * Plays a warrior turn. * * @param {Warrior} warrior The warrior. */ playTurn(warrior) { // Cool code goes here if (this.health > warrior.health()) { if (warrior.feel().isEmpty()) { warrior.walk(); } else { isCaptive(warrior); } } else { if ((warrior.health() !== warrior.maxHealth()) && warrior.feel().isEmpty()) { warrior.rest(); } else if (warrior.feel().isEmpty()) { warrior.walk(); } else { warrior.attack(); } } this.health = warrior.health(); } isCaptive(warrior) { if (warrior.feel().getUnit().isEnemy()) { warrior.attack(); } else if (warrior.feel().getUnit().isBound()) { warrior.rescue(); } } }