Sha256: 6001ef90dcd4139f703fb4cf11f8ec247f0c195edc58ae335f7f729ac0fcb49c

Contents?: true

Size: 781 Bytes

Versions: 1

Compression:

Stored size: 781 Bytes

Contents

module Model
  class BoardSetup
    attr_accessor :teams

    def initialize(args)
      @board_klass = args[:board_klass]
      @tile_collection_klass = args[:tile_collection_klass]
      @team_collection_klass = args[:team_collection_klass]
      @game_state = args[:game_state]
      @tile_klass = args[:tile_klass]
      @dimensions = args[:dimensions]
      @teams = []
    end

    def create_board
      tiles = create_tiles

      @board_klass.new(tile_collection: @tile_collection_klass.new(tiles, @dimensions),
                       team_collection: @team_collection_klass.new(@teams),
                       game_state: @game_state.new)
    end

    private

    def create_tiles
      cnt = @dimensions**2
      (1..cnt).map { |_i| @tile_klass.new }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sams_tic_tac_toe-0.0.1 lib/tic_tac_toe/model/board_setup.rb