Class: RubyWarrior::Abilities::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_warrior/abilities/base.rb

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

#descriptionObject



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_turnObject



33
34
35
# File 'lib/ruby_warrior/abilities/base.rb', line 33

def pass_turn
  # callback which is triggered every 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 "Unknown direction #{direction.inspect}. Should be :forward, :backward, :left or :right."
  end
end