Class: MapDungeon::Dungeon
- Inherits:
-
Object
- Object
- MapDungeon::Dungeon
- Defined in:
- lib/map/dungeon.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Attributes access.
-
#name ⇒ Object
Attributes access.
Instance Method Summary collapse
-
#add_entity(entity, type) ⇒ Object
Add entities to the hash.
-
#each_entity ⇒ Object
Entity iterator.
-
#each_type_entity(type) ⇒ Object
Concrete entity iterator.
-
#has_entity?(entity, type) ⇒ Boolean
Returns true if the entity exists.
-
#initialize(name = "", description = "") ⇒ Dungeon
constructor
A new instance of Dungeon.
-
#remove_entity(entity, type) ⇒ Object
Remove the entity from the array.
-
#to_s ⇒ Object
To string.
Constructor Details
#initialize(name = "", description = "") ⇒ Dungeon
Returns a new instance of Dungeon.
8 9 10 11 |
# File 'lib/map/dungeon.rb', line 8 def initialize(name = "", description = "") @name, @description = name, description @entities = Hash.new() end |
Instance Attribute Details
#description ⇒ Object
Attributes access
14 15 16 |
# File 'lib/map/dungeon.rb', line 14 def description @description end |
#name ⇒ Object
Attributes access
14 15 16 |
# File 'lib/map/dungeon.rb', line 14 def name @name end |
Instance Method Details
#add_entity(entity, type) ⇒ Object
Add entities to the hash
17 18 19 20 21 22 23 |
# File 'lib/map/dungeon.rb', line 17 def add_entity(entity, type) if(@entities[type] == nil) @entities[type] = [entity] else @entities[type] << entity end end |
#each_entity ⇒ Object
Entity iterator
36 37 38 39 40 |
# File 'lib/map/dungeon.rb', line 36 def each_entity() @entities.each { |key, value| value.each { |entity| yield entity } } end |
#each_type_entity(type) ⇒ Object
Concrete entity iterator
43 44 45 |
# File 'lib/map/dungeon.rb', line 43 def each_type_entity(type) @entities[type].each { |entity| yield entity } end |
#has_entity?(entity, type) ⇒ Boolean
Returns true if the entity exists
31 32 33 |
# File 'lib/map/dungeon.rb', line 31 def has_entity?(entity, type) @entities[type].find { |e| entity.eql?(e) } end |
#remove_entity(entity, type) ⇒ Object
Remove the entity from the array
26 27 28 |
# File 'lib/map/dungeon.rb', line 26 def remove_entity(entity, type) @entities[type].delete(entity) end |
#to_s ⇒ Object
To string
48 49 50 |
# File 'lib/map/dungeon.rb', line 48 def to_s() "#{@name}: #{@description}" end |