class Creature

If you want to make a new enemy, you have two ways to do it:

  1. Directly initialize it

    _enemy_ = Creature _health_
    _enemy_ = Creature _health_, _armour_
    _enemy_ = Creature _health_, _armour_, _weapon_
    
  2. Create a new class

    class Goblin
            def initialize; @health, @armour, @weapon = _5_, _Armour()_, _Weapon()_; end
    end

You can change weapons and armour after initialization as well. Common ancestor of any battle-able objects

end

Attributes

armour[RW]
health[R]
weapon[RW]

Public Class Methods

new(health, armour, weapon) click to toggle source

Initializes a Creature. Parameter health sets the Creature’s health. Parameter armour sets the Creature’s armour, which reduces damage taken and should be a kind of Armour. Parameter weapon sets the Creature’s weapon, which increases the damage taken on others and should be a kind of Weapon.

# File lib/battlefield.rb, line 60
def initialize(health, armour, weapon); @health, @armour, @weapon = health, armour, weapon; end

Public Instance Methods

attack(enemy, amt) click to toggle source

Attacking function. Takes into account @weapon.

# File lib/battlefield.rb, line 72
def attack(enemy, amt); enemy.damage amt + weapon.power; end
damage(amt) click to toggle source

Damage function. Takes into account armour.

# File lib/battlefield.rb, line 62
def damage(amt); @health -= (amt - armour.protection); end
droll() click to toggle source

Roll twice

# File lib/battlefield.rb, line 66
def droll; self.roll + self.roll; end
heal(c1, c2) click to toggle source

The 1st argument is your attack power. The other is the enemy’s. self heals c1 - c2 health.

# File lib/battlefield.rb, line 68
def heal(c1, c2) 
        @health += c1 - c2
end
roll() click to toggle source

Rolling function - higher # = more power.

# File lib/battlefield.rb, line 64
def roll; (1..6).to_a.sample; end