Surrounded!


Collapse Content

Archers on all sides...

It helps to be able to see more than one Space in advance. explorer can now look to get an array of up to 3 Spaces. It will default to 3 Spaces ahead, but it can can also take a Direction parameter:

Space[] back = explorer.look(Direction.LEFT);
Space[] ahead = explorer.look(Direction.RIGHT);

In fact, the methods walk, getSpace, look and poke can each take in a direction parameter (either Direction.RIGHT or Direction.LEFT). If no Direction is passed in, they will default to Direction.RIGHT.

API

Explorer methods

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.

Accessors:

  • look() - Returns an Array of up to 3 Spaces in the designated Direction.
  • getSpace() - Returns the next Space on the board.
  • getHealth() - returns the value of health.

Space methods

  • isEnemy() - returns true if the Space contains an Enemy, and false otherwise.
  • isWall() - returns true if the Space contains a Wall, and false otherwise.

Links
Arrays

Challenge

Reach the Goal while surrounded by Archers!

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.

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