Ruby Warrior Level 7

Here is how I worked through Ruby Warrior Level 7.

Ruby Warrior Level 7
Ruby Warrior Level 7

There is only one small change in this level, our warrior starts out facing the wall. First, we need to see if we are up against the wall, and if so, pivot around. Since there are no captives in this level, we can take out the code we wrote for captives and just first pivot, then walk forward. There is no need to walk backward in this level. We can set the @direction instance variable to :forward !

Level 7 code
Level 7 code

Another change I made is to change min_health to 10 instead of 15. I can do this because when the warrior faces the sludge, he is at full health at 20. Later, only 10 health points is needed to start walking toward the archer. The archer can only attack 3 times before being beaten (includes shooting from afar and attacking when the warrior is right in front). Each time, the archer inflicts -3 damage, so we need at least 10 health points before entering into the archer’s range.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s