Created
February 21, 2011 13:53
-
-
Save ashbb/837078 to your computer and use it in GitHub Desktop.
Assignment 2 for Ruby Metaprogramming course at RubyLearning.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# creatures.rb | |
class IndustrialRaverMonkey < Creature | |
life 46 | |
strength 5 | |
end | |
class DwarvenAngel < Creature | |
life 54 | |
strength 8 | |
end | |
class Rabbit < Creature | |
life 20 | |
strength 2 | |
def ^(enemy) | |
show_msg enemy do |e| | |
fight e, 5 * [strength, strength/2, 0].sample | |
end | |
end | |
def /(enemy) | |
show_msg enemy do |e| | |
fight e, 10 * [strength, strength/2, 0].sample | |
end | |
end | |
def %(enemy) | |
show_msg enemy do | |
self.life += rand(10) | |
end | |
end | |
def fight enemy, damage | |
enemy.life -= damage | |
self.life -= enemy.strength | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment