Class: RubyWarrior::Abilities::Base
- Inherits:
-
Object
- Object
- RubyWarrior::Abilities::Base
show all
- Defined in:
- lib/ruby_warrior/abilities/base.rb
Direct Known Subclasses
Attack, Bind, DirectionOf, DirectionOfStairs, Distance, Explode, Feel, Health, Listen, Look, Pivot, Rescue, Rest, Shoot, Walk
Constant Summary
collapse
- DIRECTIONS =
{
:forward => [1, 0],
:right => [0, 1],
:backward => [-1, 0],
:left => [0, -1]
}
Instance Method Summary
collapse
Constructor Details
#initialize(unit) ⇒ Base
Returns a new instance of Base.
11
12
13
|
# File 'lib/ruby_warrior/abilities/base.rb', line 11
def initialize(unit)
@unit = unit
end
|
Instance Method Details
#damage(receiver, amount) ⇒ Object
27
28
29
30
|
# File 'lib/ruby_warrior/abilities/base.rb', line 27
def damage(receiver, amount)
receiver.take_damage(amount)
@unit.earn_points(receiver.max_health) unless receiver.alive?
end
|
#description ⇒ Object
32
33
|
# File 'lib/ruby_warrior/abilities/base.rb', line 32
def description
end
|
#offset(direction, amount = 1) ⇒ Object
15
16
17
|
# File 'lib/ruby_warrior/abilities/base.rb', line 15
def offset(direction, amount = 1)
DIRECTIONS[direction].map { |i| i*amount }
end
|
#space(direction, amount = 1) ⇒ Object
19
20
21
|
# File 'lib/ruby_warrior/abilities/base.rb', line 19
def space(direction, amount = 1)
@unit.position.relative_space(*offset(direction, amount))
end
|
#unit(direction, amount = 1) ⇒ Object
23
24
25
|
# File 'lib/ruby_warrior/abilities/base.rb', line 23
def unit(direction, amount = 1)
space(direction, amount).unit
end
|