Class: Tile
- Inherits:
-
Object
- Object
- Tile
- Defined in:
- lib/terminal_hero/classes/tile.rb
Overview
Represents a terrain or entity tile on the map
Instance Attribute Summary collapse
-
#blocking ⇒ Object
Returns the value of attribute blocking.
-
#entity ⇒ Object
Returns the value of attribute entity.
-
#event ⇒ Object
Returns the value of attribute event.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
-
#export ⇒ Object
Export all values required for initialization to a hash, to be stored in a JSON save file.
-
#initialize(symbol: "?", color: :default, blocking: false, event: nil, entity: nil) ⇒ Tile
constructor
A new instance of Tile.
-
#to_s ⇒ Object
If the tile is unoccupied, return its display icon.
Constructor Details
#initialize(symbol: "?", color: :default, blocking: false, event: nil, entity: nil) ⇒ Tile
Returns a new instance of Tile.
6 7 8 9 10 11 12 |
# File 'lib/terminal_hero/classes/tile.rb', line 6 def initialize(symbol: "?", color: :default, blocking: false, event: nil, entity: nil) @symbol = symbol.colorize(color) @color = color @blocking = blocking @event = event @entity = entity end |
Instance Attribute Details
#blocking ⇒ Object
Returns the value of attribute blocking.
3 4 5 |
# File 'lib/terminal_hero/classes/tile.rb', line 3 def blocking @blocking end |
#entity ⇒ Object
Returns the value of attribute entity.
4 5 6 |
# File 'lib/terminal_hero/classes/tile.rb', line 4 def entity @entity end |
#event ⇒ Object
Returns the value of attribute event.
3 4 5 |
# File 'lib/terminal_hero/classes/tile.rb', line 3 def event @event end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
4 5 6 |
# File 'lib/terminal_hero/classes/tile.rb', line 4 def symbol @symbol end |
Instance Method Details
#export ⇒ Object
Export all values required for initialization to a hash, to be stored in a JSON save file
36 37 38 39 40 41 42 43 44 |
# File 'lib/terminal_hero/classes/tile.rb', line 36 def export return { symbol: @symbol, color: @color, blocking: @blocking, event: @event, entity: @entity.nil? || @entity.instance_of?(Player) ? nil : @entity.export } end |
#to_s ⇒ Object
If the tile is unoccupied, return its display icon. Otherwise, return the occupant’s icon.
15 16 17 18 19 |
# File 'lib/terminal_hero/classes/tile.rb', line 15 def to_s return @symbol if @entity.nil? return @entity.avatar end |