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, Detonate, DirectionOf, DirectionOfStairs, DistanceOf, Explode, Feel, Form, Health, Listen, Look, Pivot, Rescue, Rest, Shoot, Walk
Instance Method Summary
collapse
Constructor Details
#initialize(unit) ⇒ Base
Returns a new instance of Base.
4
5
6
|
# File 'lib/ruby_warrior/abilities/base.rb', line 4
def initialize(unit)
@unit = unit
end
|
Instance Method Details
#damage(receiver, amount) ⇒ Object
25
26
27
28
|
# File 'lib/ruby_warrior/abilities/base.rb', line 25
def damage(receiver, amount)
receiver.take_damage(amount)
@unit.earn_points(receiver.max_health) unless receiver.alive?
end
|
#description ⇒ Object
30
31
|
# File 'lib/ruby_warrior/abilities/base.rb', line 30
def description
end
|
#offset(direction, forward = 1, right = 0) ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'lib/ruby_warrior/abilities/base.rb', line 8
def offset(direction, forward = 1, right = 0)
case direction
when :forward then [forward, -right]
when :backward then [-forward, right]
when :right then [right, forward]
when :left then [-right, -forward]
end
end
|
#pass_turn ⇒ Object
33
34
35
|
# File 'lib/ruby_warrior/abilities/base.rb', line 33
def pass_turn
end
|
#space(direction, forward = 1, right = 0) ⇒ Object
17
18
19
|
# File 'lib/ruby_warrior/abilities/base.rb', line 17
def space(direction, forward = 1, right = 0)
@unit.position.relative_space(*offset(direction, forward, right))
end
|
#unit(direction, forward = 1, right = 0) ⇒ Object
21
22
23
|
# File 'lib/ruby_warrior/abilities/base.rb', line 21
def unit(direction, forward = 1, right = 0)
space(direction, forward, right).unit
end
|
#verify_direction(direction) ⇒ Object
37
38
39
40
41
|
# File 'lib/ruby_warrior/abilities/base.rb', line 37
def verify_direction(direction)
unless Position::RELATIVE_DIRECTIONS.include? direction
raise R18n.t.direction.unknown(direction.inspect)
end
end
|