class RubyTictactoe::PlayerFactory

Attributes

player_one[RW]
player_two[RW]

Public Class Methods

new(type_one, type_two) click to toggle source
# File lib/player_factory.rb, line 8
def initialize(type_one, type_two)
  @player_one = create_player(type_one, MARKER_X)
  @player_two = create_player(type_two, MARKER_O)
  set_opponents
end

Public Instance Methods

create_player(type, marker) click to toggle source
# File lib/player_factory.rb, line 14
def create_player(type, marker)
  case type
  when COMPUTER_PLAYER
    ComputerPlayer.new(marker)
  when HUMAN_PLAYER
    HumanPlayer.new(marker)
  when AI_PLAYER
    AIPlayer.new(marker)
  else
    raise "#{type} is an invalid player type"
  end
end
player_goes_first() click to toggle source
# File lib/player_factory.rb, line 27
def player_goes_first
  rand(0..1) == 1 ? player_one : player_two
end
set_opponents() click to toggle source
# File lib/player_factory.rb, line 31
def set_opponents
  player_one.opponent = player_two
  player_two.opponent = player_one
end