Hello Again


Collapse Content
Now this is not the end. It is not even the beginning of the end. But it is, perhaps, the end of the beginning. Winston Churchill, 1942

Note: In each level, the Java Explorer cannot take more than 130 moves to reach the goal.

The Java Explorer passed through many dangerous lands and finally nears the end of his journey. See the previous challenges to understand the Explorer's powers and enemies.

Explorer Review

The explorer can invoke one action method (mutator) each turn and any number of accessor methods. The 3 main actions are walk to move, poke to attack an enemy, and recharge to restore health. walk and poke can take in a Direction enum as a parameter to apply the action in that direction. The explorer can invoke any number of accessor methods each turn, such as getHealth to check health levels or look to see a neighboring Space.

The board that the Explorer is on consists of different Spaces. Most Spaces are empty but some contain Walls (▥) or Enemies. This challenge has 2 different enemies: Pawns (♟), which can only attack within one square, and Archers (↢), which can attack up to 3 straight squares away.

Example Game

Here's some code for this challenge where the Explorer almost wins, but unfortunately dies first:

public void play(Explorer explorer){
    if(explorer.getSpace(Direction.DOWN).isEnemy()){
        explorer.poke(Direction.DOWN);  
    }
    else if(explorer.getSpace(Direction.RIGHT).isWall()){
        explorer.walk(Direction.DOWN);
    }
    else{
        explorer.walk(Direction.RIGHT);
    }
}

See if you can fix it to reach the goal!

Explorer API

Click below to see the methods of Explorer and Space. This is also available on the sidebar of each challenge.

Explorer methods

Space methods

Challenge

This is a simpler challenge to warm up for the hard ones. Navigate around a couple Walls, Pawns and Archers to reach the goal!

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.

Comments

  • I got the question right, and it registered as correct, but after refreshing my answer is no longer the answer I had written before. I am still registered as "correct", but I lost my actual answer :(

  • @Nima, you should be able to see all your previous answers by clicking on "Submissions" above the code editor.

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