Knights and Archers


Collapse Content

They are in front of us, behind us, and we are flanked on both sides by an enemy that outnumbers us. They can't get away from us now!

What if the board was larger and with more enemies? If your code is general enough, you shouldn't need to change much, and the lone explorer should be able to defeat all the enemies!

You can use the Space methods isKnight() and isArcher() to check if a Space contains a specific enemy.

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.
  • isKnight() - returns true if the Space contains a Knight, and false otherwise.
  • isArcher() - returns true if the Space contains an Archer, and false otherwise.
  • isWall() - returns true if the Space contains a Wall, and false otherwise.

Challenge

Defeat the Knights and Archers 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]