Class: Linotype::Board
- Inherits:
-
Object
- Object
- Linotype::Board
- Defined in:
- lib/linotype/board.rb
Instance Attribute Summary collapse
-
#game ⇒ Object
readonly
Returns the value of attribute game.
-
#tiles ⇒ Object
Returns the value of attribute tiles.
Class Method Summary collapse
Instance Method Summary collapse
- #column(tile) ⇒ Object
- #column_count ⇒ Object
-
#initialize(game, args = {}) ⇒ Board
constructor
A new instance of Board.
- #row(tile) ⇒ Object
- #row_count ⇒ Object
Constructor Details
Instance Attribute Details
#game ⇒ Object (readonly)
Returns the value of attribute game.
5 6 7 |
# File 'lib/linotype/board.rb', line 5 def game @game end |
#tiles ⇒ Object
Returns the value of attribute tiles.
4 5 6 |
# File 'lib/linotype/board.rb', line 4 def tiles @tiles end |
Class Method Details
.new_random(game) ⇒ Object
12 13 14 |
# File 'lib/linotype/board.rb', line 12 def self.new_random(game) new(game, new_random_letters) end |
.new_random_letters(rows = 5, columns = 5) ⇒ Object
16 17 18 |
# File 'lib/linotype/board.rb', line 16 def self.new_random_letters(rows=5, columns=5) rows.times.collect { columns.times.collect { ('A'..'Z').to_a[rand(0..25)] } } end |
Instance Method Details
#column(tile) ⇒ Object
36 37 38 |
# File 'lib/linotype/board.rb', line 36 def column(tile) tiles[row(tile)].index(tile) end |
#column_count ⇒ Object
24 25 26 |
# File 'lib/linotype/board.rb', line 24 def column_count @column_count ||= tiles.first.count end |
#row(tile) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/linotype/board.rb', line 28 def row(tile) row_number = 0 tiles.each do |row| return row_number if row.include?(tile) row_number += 1 end end |
#row_count ⇒ Object
20 21 22 |
# File 'lib/linotype/board.rb', line 20 def row_count @row_count ||= tiles.count end |