Class: RubyWarrior::Space
- Inherits:
-
Object
- Object
- RubyWarrior::Space
- Defined in:
- lib/ruby_warrior/space.rb
Instance Method Summary collapse
- #captive? ⇒ Boolean
- #character ⇒ Object
- #empty? ⇒ Boolean
- #enemy? ⇒ Boolean
- #golem? ⇒ Boolean
-
#initialize(floor, x, y) ⇒ Space
constructor
A new instance of Space.
- #location ⇒ Object
- #player? ⇒ Boolean
- #stairs? ⇒ Boolean
- #ticking? ⇒ Boolean
- #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
27 28 29 |
# File 'lib/ruby_warrior/space.rb', line 27 def captive? unit && unit.bound? end |
#character ⇒ Object
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
31 32 33 |
# File 'lib/ruby_warrior/space.rb', line 31 def empty? unit.nil? && !wall? end |
#enemy? ⇒ Boolean
23 24 25 |
# File 'lib/ruby_warrior/space.rb', line 23 def enemy? unit && !player? && !captive? end |
#golem? ⇒ Boolean
15 16 17 |
# File 'lib/ruby_warrior/space.rb', line 15 def golem? unit.kind_of? Units::Golem end |
#location ⇒ Object
47 48 49 |
# File 'lib/ruby_warrior/space.rb', line 47 def location [@x, @y] end |
#player? ⇒ Boolean
19 20 21 |
# File 'lib/ruby_warrior/space.rb', line 19 def player? warrior? || golem? end |
#stairs? ⇒ Boolean
35 36 37 |
# File 'lib/ruby_warrior/space.rb', line 35 def stairs? @floor.stairs_location == location end |
#ticking? ⇒ Boolean
39 40 41 |
# File 'lib/ruby_warrior/space.rb', line 39 def ticking? unit && unit.abilities.include?(:explode!) end |
#to_s ⇒ Object
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? R18n.t.wall else R18n.t.nothing end end |
#unit ⇒ Object
43 44 45 |
# File 'lib/ruby_warrior/space.rb', line 43 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 |