Class: RubyWarrior::Abilities::Attack

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_warrior/abilities/attack.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/attack.rb', line 4

def description
  "Attack the unit in given direction (forward by default)."
end

#perform(direction = :forward) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ruby_warrior/abilities/attack.rb', line 8

def perform(direction = :forward)
  receiver = unit(direction)
  if receiver
    @unit.say "attacks #{receiver}"
    if direction == :backward
      power = (@unit.attack_power/2.0).ceil
    else
      power = @unit.attack_power
    end
    damage(receiver, power)
  else
    @unit.say "attacks and hits nothing"
  end
end