Sha256: 5379313e76d4f07f525c34336c187ce7d1826877262f38097969524c5e85a164
Contents?: true
Size: 1.32 KB
Versions: 1
Compression:
Stored size: 1.32 KB
Contents
require_relative 'squares' require_relative 'square' module TTT class SquaresFactory def self.build_custom_squares(config, squares_class = Squares) rows_and_cols = config.length #create multi-dimensional array squares = Array.new(rows_and_cols) do Array.new(rows_and_cols) end squares.each_with_index do |element, row| element.each_index do |col| squares[row][col] = create_custom_square(config[row][col][0],config[row][col][1]) end end squares_class.new(collection_of_squares: squares) end def self.create_custom_square(display_value, value, square_class = Square) square_class.new(display_value: display_value, value: value) end def self.build_empty_squares(rows_and_cols, squares_class = Squares) squares = Array.new(rows_and_cols) do Array.new(rows_and_cols) end i = 1 squares.each_with_index do |element, row| element.each_index do |col| squares[row][col] = create_empty_square(i) i += 1 end end squares_class.new(collection_of_squares: squares) end def self.create_empty_square(display_value, square_class = Square) square_class.new(display_value: display_value, value: nil) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
games_bfox-0.4.0 | lib/games/tictactoe/squares_factory.rb |