Class: Creature
- Inherits:
-
Object
- Object
- Creature
- Defined in:
- lib/battlefield.rb
Overview
If you want to make a new enemy, you have two ways to do it:
-
Directly initialize it
enemy = Creature.new health
-
Create a new class
class Goblin def initialize; @health = 5; end end
Common ancestor of any battle-able objects
Direct Known Subclasses
Instance Attribute Summary collapse
-
#health ⇒ Object
readonly
Returns the value of attribute health.
Instance Method Summary collapse
-
#damage(amt) ⇒ Object
Damage function.
-
#droll ⇒ Object
Roll twice.
-
#heal(amt) ⇒ Object
The 1st argument is your attack power.
-
#initialize(health) ⇒ Creature
constructor
Initializes a Creature.
-
#roll ⇒ Object
Rolling function - higher # = more power.
Constructor Details
#initialize(health) ⇒ Creature
Initializes a Creature. Parameter health sets the Creature’s health.
17 |
# File 'lib/battlefield.rb', line 17 def initialize(health); @health = health; end |
Instance Attribute Details
#health ⇒ Object (readonly)
Returns the value of attribute health.
15 16 17 |
# File 'lib/battlefield.rb', line 15 def health @health end |
Instance Method Details
#damage(amt) ⇒ Object
Damage function
19 |
# File 'lib/battlefield.rb', line 19 def damage(amt); @health -= amt; end |
#droll ⇒ Object
Roll twice
23 |
# File 'lib/battlefield.rb', line 23 def droll; self.roll + self.roll; end |
#heal(amt) ⇒ Object
The 1st argument is your attack power. The other is the enemy’s. self heals c1 - c2 health.
25 26 27 |
# File 'lib/battlefield.rb', line 25 def heal(amt) @health += c1 - c2 end |
#roll ⇒ Object
Rolling function - higher # = more power.
21 |
# File 'lib/battlefield.rb', line 21 def roll; (1..6).to_a.sample; end |