Sha256: 222ece6b406cbab0da1cb71434ad4e592492b20ce6e7b0fab4ef301260dbf204

Contents?: true

Size: 939 Bytes

Versions: 1

Compression:

Stored size: 939 Bytes

Contents

module Model
  class TeamsSetup
    HUMAN_TYPE = 1
    COMPUTER_TYPE = 2
    TEAM_TYPES = [HUMAN_TYPE, COMPUTER_TYPE].freeze

    attr_reader :team_types

    def initialize(args)
      @team_klass = args[:team_klass]
      @piece_klass = args[:piece_klass]
      @move_klass = args[:move_klass]
      @move_strategy_klass = args[:move_strategy_klass]
      @team_types = { "Player": HUMAN_TYPE, "Computer": COMPUTER_TYPE }
    end

    def create_teams(teams_args)
      teams_args.map { |args| create_team(args) }
    end

    def valid_team_type?(type)
      TEAM_TYPES.include?(type)
    end

    private

    def create_team(args)
      name = args[:name]
      piece = @piece_klass.new(name, @move_klass)
      move_strategy = args[:type] == COMPUTER_TYPE ? @move_strategy_klass.new : nil

      @team_klass.new(name: name,
                      move_strategy: move_strategy,
                      pieces: [piece])
    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/teams_setup.rb