lib/games/mastermind/players_factory.rb in games_bfox-0.3.0 vs lib/games/mastermind/players_factory.rb in games_bfox-0.4.0
- old
+ new
@@ -1,15 +1,39 @@
-require_relative '../shared/player'
+require_relative 'human_player'
+require_relative 'computer_player_expert'
+require_relative 'computer_player_novice'
module MM
- class PlayersFactory
- #returns an array in case we would like to extend the game to allow for multiple players
- def generate_players(config)
- if config.code_setter == :computer
- player_1 = Shared::Player.new(name: config.player_1_name)
+ class PlayersFactory < Shared::PlayersFactory
+ def generate_players
+ player_1 = generate_player_1
+ [player_1]
+ end
+
+ def generate_player_1
+ code_guesser = io_helpers.computer_or_human_guesser_inquiry
+ if code_guesser == :human
+ generate_player_1_new
else
- player_1 = Shared::Player.new(name: config.player_1_name, type: :computer)
+ computer_knowledge_level = io_helpers.get_computer_knowledge_level
+ if computer_knowledge_level == :novice
+ generate_player_1_computer_novice
+ else
+ generate_player_1_computer_expert
+ end
end
- [player_1]
+ end
+
+ def generate_player_1_new
+ player_name = io_helpers.get_player_1_name
+ MM::HumanPlayer.new(name: player_name)
+ end
+
+ def generate_player_1_computer_novice
+ MM::ComputerPlayerNovice.new(name: "Computer")
+ end
+
+ def generate_player_1_computer_expert
+ MM::ComputerPlayerExpert.new(name: "Computer")
end
end
end
\ No newline at end of file