Class: Goby::Tile

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(passable: true, seen: false, description: "", events: [], monsters: [], graphic: nil) ⇒ Tile

Returns a new instance of Tile.

Parameters:

  • passable (Boolean) (defaults to: true)

    if true, the player can move here.

  • seen (Boolean) (defaults to: false)

    if true, it will be printed on the map.

  • description (String) (defaults to: "")

    a summary/message of the contents.

  • events ([Event]) (defaults to: [])

    the events found on this tile.

  • monsters ([Monster]) (defaults to: [])

    the monsters found on this tile.

  • graphic (String) (defaults to: nil)

    the respresentation of this tile graphically.



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

#descriptionObject

Returns the value of attribute description.



44
45
46
# File 'lib/goby/map/tile.rb', line 44

def description
  @description
end

#eventsObject

Returns the value of attribute events.



44
45
46
# File 'lib/goby/map/tile.rb', line 44

def events
  @events
end

#graphicObject

Returns the value of attribute graphic.



44
45
46
# File 'lib/goby/map/tile.rb', line 44

def graphic
  @graphic
end

#monstersObject

Returns the value of attribute monsters.



44
45
46
# File 'lib/goby/map/tile.rb', line 44

def monsters
  @monsters
end

#passableObject

Returns the value of attribute passable.



44
45
46
# File 'lib/goby/map/tile.rb', line 44

def passable
  @passable
end

#seenObject

Returns the value of attribute seen.



44
45
46
# File 'lib/goby/map/tile.rb', line 44

def seen
  @seen
end

Instance Method Details

#cloneObject

Create deep copy of Tile.

Returns:

  • Tile a new Tile object



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_sString

Convenient conversion to String.

Returns:

  • (String)

    the string representation.



40
41
42
# File 'lib/goby/map/tile.rb', line 40

def to_s
  return @seen ? @graphic + " " : "  "
end