Created
June 30, 2016 14:58
-
-
Save pawel2105/fa6c10a285890ce90b2215274fdc4a09 to your computer and use it in GitHub Desktop.
attempt for level 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Be careful, the variable
_health
belongs to thePlayer
class, not to the warrior instance. So you access its value by callingthis._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:
Good luck!