Sha256: a2989ae5c689615a3ac2c2e3adc6508a6c74738ab22798c4b6af074e6f2c25eb

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

require_relative 'human_player'
require_relative 'computer_player_expert'
require_relative 'computer_player_novice'

module TTT
  class PlayersFactory < Shared::PlayersFactory
    def generate_players
      player_1 = generate_player_1_new
      player_2 = generate_player_2(player_1.value)
      [player_1, player_2]
    end

    def generate_player_2(player_value_taken)
      player_2_type = io_helpers.get_player_2_type
      if player_2_type == :human
        generate_player_2_human(player_value_taken)
      else #second_player_computer
        computer_knowledge_level = io_helpers.get_computer_knowledge_level
        if computer_knowledge_level == :novice
          generate_player_2_computer_novice(player_value_taken)
        else
          generate_player_2_computer_expert(player_value_taken)
        end
      end
    end

    def generate_player_1_new
      player_name = io_helpers.get_player_1_name
      player_value = io_helpers.get_player_value(player_name, "")
      TTT::HumanPlayer.new(name: player_name, value: player_value)
    end

    def generate_player_2_human(player_value_taken)
      player_name = io_helpers.get_player_2_name
      player_value = io_helpers.get_player_value(player_name, player_value_taken )
      TTT::HumanPlayer.new(name: player_name, value: player_value)
    end

    def generate_player_2_computer_novice(player_value_taken)
      TTT::ComputerPlayerNovice.new(name: "Computer", value: computer_value(player_value_taken))
    end

    def generate_player_2_computer_expert(player_value_taken)
      TTT::ComputerPlayerExpert.new(name: "Computer", value: computer_value(player_value_taken))
    end

    def computer_value(taken)
      if taken != "O"
        "O"
      else
        "X"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
games_bfox-0.4.0 lib/games/tictactoe/players_factory.rb