Class: BloodChalice::Player

Inherits:
Object
  • Object
show all
Includes:
Movable, TileValues
Defined in:
lib/bloodchalice/player.rb

Constant Summary collapse

MAX_LIFE =
100
SPEED =
7
ATTACK =
3
VISION =
10

Constants included from Movable

Movable::DIRECTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TileValues

#chalice?, #empty?, #knight?, #peasant?, #player?, #wall?, #zombie?

Methods included from Movable

#hit, #move, #move!, #moves?, #reactions, #reset_moves

Constructor Details

#initialize(options = {}) ⇒ Player

Returns a new instance of Player.



13
14
15
16
17
18
19
20
21
22
# File 'lib/bloodchalice/player.rb', line 13

def initialize(options = {})
  @position = options[:position]
  @value = @number = options[:number]
  @map = options[:map]
  @game = options[:game]
  @life = MAX_LIFE
  @moves = SPEED
  @blood = 0
  @speed = SPEED
end

Instance Attribute Details

#bloodObject

Returns the value of attribute blood.



6
7
8
# File 'lib/bloodchalice/player.rb', line 6

def blood
  @blood
end

#gameObject

Returns the value of attribute game.



6
7
8
# File 'lib/bloodchalice/player.rb', line 6

def game
  @game
end

#lifeObject

Returns the value of attribute life.



6
7
8
# File 'lib/bloodchalice/player.rb', line 6

def life
  @life
end

#mapObject

Returns the value of attribute map.



6
7
8
# File 'lib/bloodchalice/player.rb', line 6

def map
  @map
end

#movesObject

Returns the value of attribute moves.



6
7
8
# File 'lib/bloodchalice/player.rb', line 6

def moves
  @moves
end

#numberObject

Returns the value of attribute number.



6
7
8
# File 'lib/bloodchalice/player.rb', line 6

def number
  @number
end

#positionObject

Returns the value of attribute position.



6
7
8
# File 'lib/bloodchalice/player.rb', line 6

def position
  @position
end

#speedObject

Returns the value of attribute speed.



6
7
8
# File 'lib/bloodchalice/player.rb', line 6

def speed
  @speed
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/bloodchalice/player.rb', line 6

def value
  @value
end

Instance Method Details

#bite(human) ⇒ Object



54
55
56
57
# File 'lib/bloodchalice/player.rb', line 54

def bite(human)
  human.bited
  @blood += 1
end

#dead?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/bloodchalice/player.rb', line 59

def dead?
  life < 1
end

#fight(enemy) ⇒ Object



50
51
52
# File 'lib/bloodchalice/player.rb', line 50

def fight(enemy)
  enemy.hit(ATTACK)
end

#pour_blood(chalice) ⇒ Object



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

def pour_blood(chalice)
  chalice.blood += @blood
  @blood = 0
end

#reacts_to(tile) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bloodchalice/player.rb', line 24

def reacts_to(tile)
  if tile.wall?
    return :stop
  elsif tile.player?
    return :stop
  elsif tile.peasant?
    bite(tile)
    return :fight
  elsif tile.zombie?
    fight(tile)
    return :fight
  elsif tile.knight?
    fight(tile)
    return :fight
  elsif tile.chalice?
    pour_blood(tile)
  elsif tile.empty?
    return :move
  end
end

#to_sObject



63
64
65
# File 'lib/bloodchalice/player.rb', line 63

def to_s
  @number.to_s
end