Here is my work for 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.
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!
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?