Ruby Warrior Level 8

Here is my work for Ruby Warrior Level 8.

Ruby Warrior Level 8
Ruby Warrior Level 8

Level 8 introduces wizards!! If we run our level 7 code, we’ll see that the wizards’s attacks are really strong. Each attack takes away 11 health points! The good thing is, the wizards can only attack when we are close to them. We now have a new weapon, a bow. We can use the bow to attack the wizards from a safe distance. The flow chart is simple.

Level 8 flow chart
Level 8 flow chart

We don’t need any instance variables for this one. I created a function that would look ahead 3 squares. If a captive was in any of those squares, it would return “captive”. If no captive is present, it would check if any enemy is present. If yes, it would return “enemy”. It is important to first check if there are any captives because we don’t want to kill the captive with our arrows!

Level 8 code
Level 8 code

If we look ahead and see a captive, we check to see if the captive is in front of the warrior. If so, we rescue the captive. If not, we walk forward. If there are no captives ahead, we check to see if there are enemies ahead. If so, we shoot! If not, we just walk forward.
I’m a little sad that I’m nearing the end of Ruby Warrior! It has been a really fun learning experience. How awesome are these 8-bit wizards?

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