class MapDungeon::Dungeon
Attributes
description[RW]
Attributes access
name[RW]
Attributes access
Public Class Methods
new(name = "", description = "")
click to toggle source
# File lib/map/dungeon.rb, line 8 def initialize(name = "", description = "") @name, @description = name, description @entities = Hash.new() end
Public Instance Methods
add_entity(entity, type)
click to toggle source
Add entities to the hash
# 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() { |entity| ... }
click to toggle source
Entity iterator
# File lib/map/dungeon.rb, line 36 def each_entity() @entities.each { |key, value| value.each { |entity| yield entity } } end
each_type_entity(type) { |entity| ... }
click to toggle source
Concrete entity iterator
# File lib/map/dungeon.rb, line 43 def each_type_entity(type) @entities[type].each { |entity| yield entity } end
has_entity?(entity, type)
click to toggle source
Returns true if the entity exists
# File lib/map/dungeon.rb, line 31 def has_entity?(entity, type) @entities[type].find { |e| entity.eql?(e) } end
remove_entity(entity, type)
click to toggle source
Remove the entity from the array
# File lib/map/dungeon.rb, line 26 def remove_entity(entity, type) @entities[type].delete(entity) end
to_s()
click to toggle source
To string
# File lib/map/dungeon.rb, line 48 def to_s() "#{@name}: #{@description}" end