Class: RubyWarrior::Abilities::Shoot

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

Constant Summary

Constants inherited from Base

Base::DIRECTIONS

Instance Method Summary collapse

Methods inherited from Base

#damage, #initialize, #offset, #space, #unit

Constructor Details

This class inherits a constructor from RubyWarrior::Abilities::Base

Instance Method Details

#descriptionObject



4
5
6
# File 'lib/ruby_warrior/abilities/shoot.rb', line 4

def description
  "Shoot your bow & arrow in given direction (forward by default)."
end

#multi_unit(direction, range) ⇒ Object



18
19
20
# File 'lib/ruby_warrior/abilities/shoot.rb', line 18

def multi_unit(direction, range)
  range.map { |n| unit(direction, n) }
end

#perform(direction = :forward) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/ruby_warrior/abilities/shoot.rb', line 8

def perform(direction = :forward)
  receiver = multi_unit(direction, 1..3).compact.first
  if receiver
    @unit.say "shoots #{receiver}"
    damage(receiver, @unit.shoot_power)
  else
    @unit.say "shoots and hits nothing"
  end
end