Archer
Collapse Content
Show Content
Watch out for Archers, who can shoot from far..
Archers can attack explorer
from far without being detected. Store an instance variable for health to see if your current health value (from getHealth()
) is less than before. Don't waste time recharging while being attacked!
Don't take more than 35 moves to reach the goal.
As your code gets more complicated, it will help to create additional methods instead of keeping everything in nested if-then blocks.
Explorer Methods
Accessors
getSpace()
- Returns the next Space on the board.getHealth()
- returns the value ofhealth
.
Mutators
walk()
- Moves the explorer forward (to the right) one Space.poke()
- Pokes the next space, causing damage to any Enemy there.recharge()
- Adds 9 to health.
Space methods
isEnemy()
- returns true if the Space contains an Enemy, and false otherwise.
Link
Instance Variables
Challenge
Attack and recharge until you reach the goal!
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.
Comments
catypus
Jul 6, 4:52 AMI've been fighting hard with this one, can't get it.
How do I use a variable (lasthealth) without clobbering it's data every time the play method is called.
I want to update lasthealth at the bottom of the play method... check it when its called again... but I can't check it without declaring it at the start... which ruins the value its holding on to
Learneroo
Jul 6, 9:37 PMYou can create the health variable outside the play method. Then you can update it's value as needed inside the method.