Knights


Collapse Content

I used to think standing Archers were dangerous. Then I met Archers on Horseback.

Knights are like archers, but they can move. They attack an Explorer within 2 Spaces. They move towards an Explorer 3 spaces away, unless something blocks their way.

Suggestion: If you just use if/then blocks, your code will get really messy. Instead, you should create methods to help decide what to do.

API

Note: 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.

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.

Challenge

Defeat the Knights and reach the goal!

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]