Class: RubyWarrior::Space
- Inherits:
-
Object
- Object
- RubyWarrior::Space
- Defined in:
- lib/ruby_warrior/space.rb
Instance Method Summary collapse
- #captive? ⇒ Boolean
- #empty? ⇒ Boolean
- #enemy? ⇒ Boolean
-
#initialize(floor, x, y) ⇒ Space
constructor
A new instance of Space.
- #location ⇒ Object
- #stairs? ⇒ Boolean
- #ticking? ⇒ Boolean
- #to_map ⇒ Object
- #to_s ⇒ Object
- #unit ⇒ Object
- #wall? ⇒ Boolean
- #warrior? ⇒ Boolean
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
19 20 21 |
# File 'lib/ruby_warrior/space.rb', line 19 def captive? unit && unit.bound? end |
#empty? ⇒ Boolean
23 24 25 |
# File 'lib/ruby_warrior/space.rb', line 23 def empty? unit.nil? && !wall? end |
#enemy? ⇒ Boolean
15 16 17 |
# File 'lib/ruby_warrior/space.rb', line 15 def enemy? unit && !warrior? && !captive? end |
#location ⇒ Object
39 40 41 |
# File 'lib/ruby_warrior/space.rb', line 39 def location [@x, @y] end |
#stairs? ⇒ Boolean
27 28 29 |
# File 'lib/ruby_warrior/space.rb', line 27 def stairs? @floor.stairs_location == location end |
#ticking? ⇒ Boolean
31 32 33 |
# File 'lib/ruby_warrior/space.rb', line 31 def ticking? unit.respond_to?(:bomb_time) && unit.bomb_time end |
#to_map ⇒ Object
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_s ⇒ Object
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 |
#unit ⇒ Object
35 36 37 |
# File 'lib/ruby_warrior/space.rb', line 35 def unit @floor.get(@x, @y) end |
#wall? ⇒ Boolean
7 8 9 |
# File 'lib/ruby_warrior/space.rb', line 7 def wall? @floor.out_of_bounds? @x, @y end |