Archer


Collapse 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 of health.

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

  • I'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.

    cont...
  • You can create the health variable outside the play method. Then you can update it's value as needed inside the method.

Contact Us
Sign in or email us at [email protected]