Class: Goby::Tile
- Inherits:
-
Object
- Object
- Goby::Tile
- Defined in:
- lib/goby/map/tile.rb
Overview
Describes a single location on a Map. Can have Events and Monsters. Provides variables that control its graphical representation on the Map.
Constant Summary collapse
- DEFAULT_PASSABLE =
Default graphic for passable tiles.
"·"
- DEFAULT_IMPASSABLE =
Default graphic for impassable tiles.
"■"
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#events ⇒ Object
Returns the value of attribute events.
-
#graphic ⇒ Object
Returns the value of attribute graphic.
-
#monsters ⇒ Object
Returns the value of attribute monsters.
-
#passable ⇒ Object
Returns the value of attribute passable.
-
#seen ⇒ Object
Returns the value of attribute seen.
Instance Method Summary collapse
-
#clone ⇒ Object
Create deep copy of Tile.
-
#initialize(passable: true, seen: false, description: "", events: [], monsters: [], graphic: nil) ⇒ Tile
constructor
A new instance of Tile.
-
#to_s ⇒ String
Convenient conversion to String.
Constructor Details
#initialize(passable: true, seen: false, description: "", events: [], monsters: [], graphic: nil) ⇒ Tile
Returns a new instance of Tile.
18 19 20 21 22 23 24 25 |
# File 'lib/goby/map/tile.rb', line 18 def initialize(passable: true, seen: false, description: "", events: [], monsters: [], graphic: nil) @passable = passable @seen = seen @description = description @events = events @monsters = monsters @graphic = graphic.nil? ? default_graphic : graphic end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
44 45 46 |
# File 'lib/goby/map/tile.rb', line 44 def description @description end |
#events ⇒ Object
Returns the value of attribute events.
44 45 46 |
# File 'lib/goby/map/tile.rb', line 44 def events @events end |
#graphic ⇒ Object
Returns the value of attribute graphic.
44 45 46 |
# File 'lib/goby/map/tile.rb', line 44 def graphic @graphic end |
#monsters ⇒ Object
Returns the value of attribute monsters.
44 45 46 |
# File 'lib/goby/map/tile.rb', line 44 def monsters @monsters end |
#passable ⇒ Object
Returns the value of attribute passable.
44 45 46 |
# File 'lib/goby/map/tile.rb', line 44 def passable @passable end |
#seen ⇒ Object
Returns the value of attribute seen.
44 45 46 |
# File 'lib/goby/map/tile.rb', line 44 def seen @seen end |
Instance Method Details
#clone ⇒ Object
Create deep copy of Tile.
30 31 32 33 34 35 |
# File 'lib/goby/map/tile.rb', line 30 def clone # First serialize the object, and then deserialize that into a new ruby object serialized_tile = Marshal.dump(self) new_tile = Marshal.load(serialized_tile) return new_tile end |
#to_s ⇒ String
Convenient conversion to String.
40 41 42 |
# File 'lib/goby/map/tile.rb', line 40 def to_s return @seen ? @graphic + " " : " " end |