Class: Goby::Map
- Inherits:
-
Object
- Object
- Goby::Map
- Defined in:
- lib/goby/map/map.rb
Overview
A 2D arrangement of Tiles. The Player can move around on it.
Instance Attribute Summary collapse
-
#music ⇒ Object
Returns the value of attribute music.
-
#name ⇒ Object
Returns the value of attribute name.
-
#tiles ⇒ Object
Returns the value of attribute tiles.
Instance Method Summary collapse
- #==(rhs) ⇒ Object
-
#in_bounds(y, x) ⇒ Boolean
Returns true when @tiles[x] is an existing index of @tiles.
-
#initialize(name: "Map", tiles: [[Tile.new]], music: nil) ⇒ Map
constructor
A new instance of Map.
-
#to_s ⇒ Object
Prints the map in a nice format.
Constructor Details
#initialize(name: "Map", tiles: [[Tile.new]], music: nil) ⇒ Map
Returns a new instance of Map.
8 9 10 11 12 |
# File 'lib/goby/map/map.rb', line 8 def initialize(name: "Map", tiles: [[Tile.new]], music: nil) @name = name @tiles = tiles @music = music end |
Instance Attribute Details
#music ⇒ Object
Returns the value of attribute music.
41 42 43 |
# File 'lib/goby/map/map.rb', line 41 def music @music end |
#name ⇒ Object
Returns the value of attribute name.
41 42 43 |
# File 'lib/goby/map/map.rb', line 41 def name @name end |
#tiles ⇒ Object
Returns the value of attribute tiles.
41 42 43 |
# File 'lib/goby/map/map.rb', line 41 def tiles @tiles end |
Instance Method Details
#==(rhs) ⇒ Object
37 38 39 |
# File 'lib/goby/map/map.rb', line 37 def ==(rhs) return @name == rhs.name end |
#in_bounds(y, x) ⇒ Boolean
Returns true when @tiles[x] is an existing index of @tiles. Otherwise, returns false.
20 21 22 |
# File 'lib/goby/map/map.rb', line 20 def in_bounds(y, x) return (y.nonnegative? && y < @tiles.length && x.nonnegative? && x < @tiles[y].length) end |
#to_s ⇒ Object
Prints the map in a nice format.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/goby/map/map.rb', line 25 def to_s output = "" @tiles.each do |row| row.each do |tile| output += (tile.graphic + " ") end output += "\n" end return output end |