Sha256: 44c3401639cbcb64a3632612e0d8e95ed2e3adc0857518506cae480bc9755442

Contents?: true

Size: 847 Bytes

Versions: 4

Compression:

Stored size: 847 Bytes

Contents

module Linotype
  class Board  
  
    attr_accessor :tiles
    attr_reader :game
  
    def initialize(game, args={})
      @game = game
      @tiles = args[:tiles].collect { |row| row.collect { |tile|  Tile.new(self, tile) } }
    end
        
    def self.new_random(game)
      new(game, new_random_letters)
    end
    
    def self.new_random_letters(rows=5, columns=5)
      rows.times.collect { columns.times.collect { ('A'..'Z').to_a[rand(0..25)] } }
    end

    def row_count
      @row_count ||= tiles.count
    end

    def column_count 
      @column_count ||= tiles.first.count
    end
    
    def row(tile)
      row_number = 0
      tiles.each do |row|
        return row_number if row.include?(tile)
        row_number += 1
      end
    end
    
    def column(tile)
      tiles[row(tile)].index(tile)
    end
      
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
linotype-0.0.6 lib/linotype/board.rb
linotype-0.0.5 lib/linotype/board.rb
linotype-0.0.4 lib/linotype/board.rb
linotype-0.0.3 lib/linotype/board.rb