Class: Tile
- Inherits:
-
Object
- Object
- Tile
- Defined in:
- lib/tile.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#col ⇒ Object
readonly
Returns the value of attribute col.
-
#cols ⇒ Object
readonly
Returns the value of attribute cols.
-
#mosaic ⇒ Object
readonly
Returns the value of attribute mosaic.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #area ⇒ Object
-
#initialize(rows, cols) ⇒ Tile
constructor
A new instance of Tile.
- #place!(mosaic, row, col) ⇒ Object
- #shatter ⇒ Object
Constructor Details
#initialize(rows, cols) ⇒ Tile
Returns a new instance of Tile.
47 48 49 |
# File 'lib/tile.rb', line 47 def initialize(rows, cols) @rows, @cols = rows, cols end |
Instance Attribute Details
#col ⇒ Object (readonly)
Returns the value of attribute col.
3 4 5 |
# File 'lib/tile.rb', line 3 def col @col end |
#cols ⇒ Object (readonly)
Returns the value of attribute cols.
4 5 6 |
# File 'lib/tile.rb', line 4 def cols @cols end |
#mosaic ⇒ Object (readonly)
Returns the value of attribute mosaic.
2 3 4 |
# File 'lib/tile.rb', line 2 def mosaic @mosaic end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
3 4 5 |
# File 'lib/tile.rb', line 3 def row @row end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
4 5 6 |
# File 'lib/tile.rb', line 4 def rows @rows end |
Class Method Details
.area(tiles) ⇒ Object
43 44 45 |
# File 'lib/tile.rb', line 43 def self.area(tiles) tiles.inject(0) {|sum, tile| sum + tile.area} end |
Instance Method Details
#==(other) ⇒ Object
51 52 53 54 |
# File 'lib/tile.rb', line 51 def ==(other) return false unless other.is_a?(Tile) self.rows == other.rows && self.cols == other.cols end |
#area ⇒ Object
56 57 58 |
# File 'lib/tile.rb', line 56 def area @rows * @cols end |
#place!(mosaic, row, col) ⇒ Object
60 61 62 |
# File 'lib/tile.rb', line 60 def place!(mosaic, row, col) @mosaic, @row, @col = mosaic, row, col end |
#shatter ⇒ Object
64 65 66 |
# File 'lib/tile.rb', line 64 def shatter Tile.rand_covering(area) end |