Module: BloodChalice::Movable

Included in:
Chalice, Knight, Peasant, Player, Zombie
Defined in:
lib/bloodchalice/movable.rb

Constant Summary collapse

DIRECTIONS =
{north: [-1, 0], east: [0, 1], south: [1, 0], west: [0, -1] }

Instance Method Summary collapse

Instance Method Details

#hit(damage) ⇒ Object



27
28
29
30
31
32
# File 'lib/bloodchalice/movable.rb', line 27

def hit(damage)
  @life -= damage
  if @life <= 0 
    die()
  end
end

#move(direction) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/bloodchalice/movable.rb', line 5

def move(direction)
  case direction
    when :north          
      reactions sum_positions(@position, DIRECTIONS[:north])
    when :south                                              
      reactions sum_positions(@position, DIRECTIONS[:south])
    when :east                                               
      reactions sum_positions(@position, DIRECTIONS[:east])
    when :west                                               
      reactions sum_positions(@position, DIRECTIONS[:west])
  end                        
end

#move!(position) ⇒ Object



38
39
40
41
42
43
# File 'lib/bloodchalice/movable.rb', line 38

def move!(position)
  @map.set_tile(@position, Tile.new(@position, ' '))
  @position = position
  @moves -= 1          
  @map.set_tile(position, self)
end

#moves?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/bloodchalice/movable.rb', line 45

def moves?
  self.moves > 0
end

#reactions(position) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/bloodchalice/movable.rb', line 18

def reactions(position)
  case reacts_to(@map.value(position))
    when :move
      move!(position)
    when :fight
      @moves = 0
  end      
end

#reset_movesObject



34
35
36
# File 'lib/bloodchalice/movable.rb', line 34

def reset_moves
  @moves = self.speed
end