Class: RubyWarrior::Space

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_warrior/space.rb

Instance Method Summary collapse

Constructor Details

#initialize(floor, x, y) ⇒ Space

Returns a new instance of Space.



3
4
5
# File 'lib/ruby_warrior/space.rb', line 3

def initialize(floor, x, y)
  @floor, @x, @y = floor, x, y
end

Instance Method Details

#captive?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ruby_warrior/space.rb', line 27

def captive?
  unit && unit.bound?
end

#characterObject



51
52
53
54
55
56
57
58
59
# File 'lib/ruby_warrior/space.rb', line 51

def character
  if unit
    unit.character
  elsif stairs?
    ">"
  else
    " "
  end
end

#empty?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/ruby_warrior/space.rb', line 31

def empty?
  unit.nil? && !wall?
end

#enemy?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ruby_warrior/space.rb', line 23

def enemy?
  unit && !player? && !captive?
end

#golem?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/ruby_warrior/space.rb', line 15

def golem?
  unit.kind_of? Units::Golem
end

#locationObject



47
48
49
# File 'lib/ruby_warrior/space.rb', line 47

def location
  [@x, @y]
end

#player?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/ruby_warrior/space.rb', line 19

def player?
  warrior? || golem?
end

#stairs?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/ruby_warrior/space.rb', line 35

def stairs?
  @floor.stairs_location == location
end

#ticking?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/ruby_warrior/space.rb', line 39

def ticking?
  unit && unit.abilities.include?(:explode!)
end

#to_sObject



61
62
63
64
65
66
67
68
69
# File 'lib/ruby_warrior/space.rb', line 61

def to_s
  if unit
    unit.to_s
  elsif wall?
    'wall'
  else
    'nothing'
  end
end

#unitObject



43
44
45
# File 'lib/ruby_warrior/space.rb', line 43

def unit
  @floor.get(@x, @y)
end

#wall?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/ruby_warrior/space.rb', line 7

def wall?
  @floor.out_of_bounds? @x, @y
end

#warrior?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/ruby_warrior/space.rb', line 11

def warrior?
  unit.kind_of? Units::Warrior
end