olistic/warriorjs

where did constructor() come from and what is it? How does it work and what does it mean? I'm not able to learn anything here

Levi-369 opened this issue · 1 comments

          I could give you a few pointers, but not the complete solution. After all, this game is intended to learn, and you won't learn anything if I do.
class Player {
  constructor() {
    this._health = 20;
  }

  playTurn(warrior) {
    // TODO: Add missing condition
    if () {
      warrior.rest();
    } else {
      if (warrior.feel().isEnemy()) {
        warrior.attack();
      } else {
        warrior.walk();
      }
    }

    // TODO: Update this._health with warrior.health
  }

  isInjured(warrior) {
    // TODO: Return false if warrior health is less than 20
  }

  isUnderAttack(warrior) {
    // TODO: Compare this._health with warrior.health()
  }
}

You can call the newly defined methods isInjured and isUnderAttack (and any other method you create in the future) from the playTurn method like this:

this.isInjured(warrior)

Good luck!

Originally posted by @olistic in #9 (comment)

I don't know how GitHub works or how to delete this...
I just wanted to ask privately and just seen this was answered in 2015