class GameFactory
Attributes
player_one[R]
player_two[R]
Public Class Methods
new(board, display, rules, menu)
click to toggle source
# File lib/ttt_malisa/game_factory.rb, line 4 def initialize(board, display, rules, menu) @board = board @display = display @rules = rules @menu = menu end
Public Instance Methods
create_game()
click to toggle source
# File lib/ttt_malisa/game_factory.rb, line 11 def create_game player_selections player_choices game = Game.new(@display, @rules, @player_one, @player_two) game end
Private Instance Methods
check_game_mark(potential_mark, other_mark)
click to toggle source
# File lib/ttt_malisa/game_factory.rb, line 49 def check_game_mark(potential_mark, other_mark) until valid_game_piece?(potential_mark, other_mark) @display.invalid_mark_message potential_mark = @display.retrieve_user_input end potential_mark end
create_mark(other_mark = nil)
click to toggle source
# File lib/ttt_malisa/game_factory.rb, line 42 def create_mark(other_mark = nil) @display.setup_mark_message potential_mark = @display.retrieve_user_input mark = check_game_mark(potential_mark, other_mark) @mark = mark end
create_player(player_option, mark)
click to toggle source
# File lib/ttt_malisa/game_factory.rb, line 32 def create_player(player_option, mark) case player_option when '1' player = HumanPlayer.new(mark, @board, @display) when '2' player = ComputerPlayer.new(mark, @board, @display) end player end
player_choices()
click to toggle source
# File lib/ttt_malisa/game_factory.rb, line 25 def player_choices player_one_mark = create_mark player_two_mark = create_mark(player_one_mark) @player_one = create_player(@player_one_option, player_one_mark) @player_two = create_player(@player_two_option, player_two_mark) end
player_selections()
click to toggle source
# File lib/ttt_malisa/game_factory.rb, line 20 def player_selections @player_one_option = @menu.player_choice @player_two_option = @menu.player_choice end
valid_game_piece?(potential_mark, other_mark)
click to toggle source
# File lib/ttt_malisa/game_factory.rb, line 57 def valid_game_piece?(potential_mark, other_mark) potential_mark.length == 1 && potential_mark != other_mark end