Skip to content

Instantly share code, notes, and snippets.

@Zorgatone
Last active May 19, 2018 10:12
Show Gist options
  • Save Zorgatone/755553f83f429e72e753022c8dc849ad to your computer and use it in GitHub Desktop.
Save Zorgatone/755553f83f429e72e753022c8dc849ad to your computer and use it in GitHub Desktop.
WariorJS
eyJ3YXJyaW9yTmFtZSI6IlpvcmdhdG9uZSIsInRvd2VyTmFtZSI6ImJlZ2lubmVyIiwiZGlyZWN0b3J5UGF0aCI6Ii4iLCJsZXZlbE51bWJlciI6NSwic2NvcmUiOjE3NiwiY2x1ZSI6ZmFsc2UsImVwaWMiOmZhbHNlLCJlcGljU2NvcmUiOjAsImF2ZXJhZ2VHcmFkZSI6bnVsbCwiY3VycmVudEVwaWNTY29yZSI6MCwiY3VycmVudEVwaWNHcmFkZXMiOnt9fQ==

Zorgatone - beginner - level 5

You hear cries for help. Captives must need rescuing.

TIP: Use warrior.feel().isCaptive() to see if there's a captive and warrior.rescue() to rescue him. Don't attack captives.

Floor Map

╔═══════╗
║@ CaaSC║
╚═══════╝

@ = Zorgatone (20 HP)
C = Captive (1 HP)
a = Archer (7 HP)
S = Thick Sludge (24 HP)

Abilities

Actions (only one per turn)

  • warrior.rescue(): Rescue a captive from his chains (earning a reward) in the given direction (forward by default).
  • warrior.walk(): Move one space in the given direction (forward by default).
  • warrior.attack(): Attack a unit in the given direction (forward by default) dealing 5 HP of damage.
  • warrior.rest(): Gain 10% of max health back, but do nothing more.

Senses

  • warrior.feel(): Return the adjacent space in the given direction (forward by default).
  • warrior.health(): Return an integer representing your health.

Next Steps

When you're done editing Player.js, run the warriorjs command again.

// @ts-check
/**
* @typedef {Object} Space
* @property {() => boolean} isEmpty
*/
/**
* @typedef {Object} Warrior
* @property {() => Space} feel
* @property {() => void} walk
* @property {() => void} attack
* @property {() => number} health
* @property {() => void} rest
*/
class Player {
constructor() {
this.reachedBackWall = false;
this.previousHealth = 0;
}
/** @type {(warrior: Warrior) => void} */
playTurn(/** @type {Warrior} */ warrior) {
const currentHealth = warrior.health();
if (this.previousHealth < 1) {
this.previousHealth = currentHealth;
}
const tookDamage = currentHealth < this.previousHealth;
const feel = warrior.feel();
if (feel.isEmpty()) {
if (tookDamage) {
// Engage archer
warrior.walk();
} else if (currentHealth <= 18) {
// Idle
warrior.rest();
} else {
// Explore
warrior.walk();
}
} else {
// Combat (start or continue)
warrior.attack();
}
this.previousHealth = currentHealth;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment