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)


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

def captive?
  unit && unit.bound?
end

#empty?Boolean

Returns:

  • (Boolean)


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

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

#enemy?Boolean

Returns:

  • (Boolean)


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

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

#locationObject



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

def location
  [@x, @y]
end

#stairs?Boolean

Returns:

  • (Boolean)


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

def stairs?
  @floor.stairs_location == location
end

#ticking?Boolean

Returns:

  • (Boolean)


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

def ticking?
  unit.respond_to?(:bomb_time) && unit.bomb_time
end

#to_mapObject



43
44
45
46
47
48
49
50
51
# File 'lib/ruby_warrior/space.rb', line 43

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

#to_sObject



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

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

#unitObject



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

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