Last active
January 1, 2016 18:19
-
-
Save tarynsauer/8183067 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'tictactoe_constants' | |
| class PlayerFactory | |
| include TictactoeConstants | |
| attr_accessor :player_one, :player_two | |
| def initialize(type_one, type_two) | |
| @player_one = create_player(type_one, TictactoeConstants::MARKER_X) | |
| @player_two = create_player(type_two, TictactoeConstants::MARKER_O) | |
| set_opponents | |
| end | |
| def create_player(type, marker) | |
| case type | |
| when TictactoeConstants::COMPUTER_PLAYER | |
| ComputerPlayer.new(marker) | |
| when TictactoeConstants::HUMAN_PLAYER | |
| HumanPlayer.new(marker) | |
| when TictactoeConstants::AI_PLAYER | |
| AIPlayer.new(marker) | |
| else | |
| raise "Invalid player type" | |
| end | |
| end | |
| ... | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment