Class: RubyWarrior::Units::Warrior

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_warrior/units/warrior.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#health, #position

Instance Method Summary collapse

Methods inherited from Base

#abilities, #add_abilities, #alive?, #bind, #bound?, #next_turn, #prepare_turn, #say, #take_damage, #unbind

Constructor Details

#initializeWarrior

Returns a new instance of Warrior.



7
8
9
10
# File 'lib/ruby_warrior/units/warrior.rb', line 7

def initialize
  @score = 0 # TODO make score dynamic
  @golem_abilities = []
end

Instance Attribute Details

#nameObject



37
38
39
40
41
42
43
# File 'lib/ruby_warrior/units/warrior.rb', line 37

def name
  if @name && !@name.empty?
    @name
  else
    "Warrior"
  end
end

#scoreObject (readonly)

Returns the value of attribute score.



5
6
7
# File 'lib/ruby_warrior/units/warrior.rb', line 5

def score
  @score
end

Instance Method Details

#add_golem_abilities(*abilities) ⇒ Object



58
59
60
# File 'lib/ruby_warrior/units/warrior.rb', line 58

def add_golem_abilities(*abilities)
  @golem_abilities += abilities
end

#attack_powerObject



25
26
27
# File 'lib/ruby_warrior/units/warrior.rb', line 25

def attack_power
  5
end

#base_golemObject



66
67
68
69
70
# File 'lib/ruby_warrior/units/warrior.rb', line 66

def base_golem
  golem = Golem.new
  golem.add_abilities *@golem_abilities
  golem
end

#characterObject



49
50
51
# File 'lib/ruby_warrior/units/warrior.rb', line 49

def character
  "@"
end

#earn_points(points) ⇒ Object



20
21
22
23
# File 'lib/ruby_warrior/units/warrior.rb', line 20

def earn_points(points)
  @score += points
  say "earns #{points} points"
end

#has_golem?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/ruby_warrior/units/warrior.rb', line 62

def has_golem?
  !@golem_abilities.empty?
end

#max_healthObject



33
34
35
# File 'lib/ruby_warrior/units/warrior.rb', line 33

def max_health
  20
end

#perform_turnObject



53
54
55
56
# File 'lib/ruby_warrior/units/warrior.rb', line 53

def perform_turn
  say "does nothing" if @current_turn.action.nil?
  super
end

#play_turn(turn) ⇒ Object



12
13
14
# File 'lib/ruby_warrior/units/warrior.rb', line 12

def play_turn(turn)
  player.play_turn(turn)
end

#playerObject



16
17
18
# File 'lib/ruby_warrior/units/warrior.rb', line 16

def player
  @player ||= Player.new
end

#shoot_powerObject



29
30
31
# File 'lib/ruby_warrior/units/warrior.rb', line 29

def shoot_power
  3
end

#to_sObject



45
46
47
# File 'lib/ruby_warrior/units/warrior.rb', line 45

def to_s
  name
end