lib/games/tictactoe/players_factory.rb in games_bfox-0.3.0 vs lib/games/tictactoe/players_factory.rb in games_bfox-0.4.0

- old
+ new

@@ -1,11 +1,55 @@ -require_relative 'player' +require_relative 'human_player' +require_relative 'computer_player_expert' +require_relative 'computer_player_novice' module TTT - class PlayersFactory - def generate_players(config) - player_1 = TTT::Player.new(value: config.player_1_value, name: config.player_1_name, type: :human) - player_2 = TTT::Player.new(value: config.player_2_value, name: config.player_2_name, type: config.player_2_type, difficulty_level: config.computer_difficulty_level) + 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 \ No newline at end of file