Skip to content

Instantly share code, notes, and snippets.

@pawel2105
Created June 30, 2016 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawel2105/fa6c10a285890ce90b2215274fdc4a09 to your computer and use it in GitHub Desktop.
Save pawel2105/fa6c10a285890ce90b2215274fdc4a09 to your computer and use it in GitHub Desktop.
attempt for level 4
class Player {
constructor() {
this._health = 20
}
playTurn(warrior) {
considerMovement(warrior)
}
}
function considerMovement(warrior) {
if (noTasksFor(warrior)) {
evaluateSituation(warrior)
} else {
warrior.attack()
}
}
function evaluateSituation(warrior) {
if (isHealthy(warrior)) {
warrior.walk()
} else {
takeSmallBreak(warrior)
}
}
function takeSmallBreak(warrior) {
warrior.rest()
}
function isHealthy(warrior) {
return (warrior._health > 17)
}
function noTasksFor(warrior) {
return warrior.feel().isEmpty()
}
function isInjured(warrior) {
return (warrior.health() > warrior._health)
}
@olistic
Copy link

olistic commented Jun 30, 2016

Be careful, the variable _health belongs to the Player class, not to the warrior instance. So you access its value by calling this._health anywhere in the class. And don't forget to update it with your current health (warrior.health()) at the end of the turn!

And you're missing this part:

you must be careful not to rest while taking damage

Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment