Skip to content

Instantly share code, notes, and snippets.

@tarynsauer
Last active January 1, 2016 18:19
Show Gist options
  • Save tarynsauer/8183067 to your computer and use it in GitHub Desktop.
Save tarynsauer/8183067 to your computer and use it in GitHub Desktop.
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