Class: BloodChalice::Knight

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

Constant Summary collapse

MAX_LIFE =
5
SPEED =
3
ATTACK =
1
VISION =
6
MAXBLOOD =
1

Constants included from Movable

Movable::DIRECTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ArtificialIntelligence

#bited, #die, #hit, #think

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 = {}) ⇒ Knight

Returns a new instance of Knight.



15
16
17
18
19
20
21
22
23
# File 'lib/bloodchalice/knight.rb', line 15

def initialize(options = {})
  @position = options[:position]
  @map = options[:map]
  @game = options[:game]
  @life = MAX_LIFE
  @blood = MAXBLOOD
  @value = 'K'
  @speed = SPEED
end

Instance Attribute Details

#bloodObject

Returns the value of attribute blood.



7
8
9
# File 'lib/bloodchalice/knight.rb', line 7

def blood
  @blood
end

#gameObject

Returns the value of attribute game.



7
8
9
# File 'lib/bloodchalice/knight.rb', line 7

def game
  @game
end

#lifeObject

Returns the value of attribute life.



7
8
9
# File 'lib/bloodchalice/knight.rb', line 7

def life
  @life
end

#mapObject

Returns the value of attribute map.



7
8
9
# File 'lib/bloodchalice/knight.rb', line 7

def map
  @map
end

#positionObject

Returns the value of attribute position.



7
8
9
# File 'lib/bloodchalice/knight.rb', line 7

def position
  @position
end

#speedObject

Returns the value of attribute speed.



7
8
9
# File 'lib/bloodchalice/knight.rb', line 7

def speed
  @speed
end

#valueObject

Returns the value of attribute value.



7
8
9
# File 'lib/bloodchalice/knight.rb', line 7

def value
  @value
end

Instance Method Details

#reacts_to(tile) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bloodchalice/knight.rb', line 25

def reacts_to(tile)
  if tile.wall?
    return :stop
  elsif tile.empty?
    return :move
  elsif tile.player?
    tile.hit(ATTACK)
    return :fight
  elsif tile.zombie?
    tile.hit(ATTACK)
    return :fight
  end
end

#to_sObject



39
40
41
# File 'lib/bloodchalice/knight.rb', line 39

def to_s
  @value.to_s
end