class TicTacToeRZ::GamePlay::MatchTypeManager
Attributes
matches[R]
Public Class Methods
new()
click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/gameplay/match_type_manager.rb, line 11 def initialize # define player types player_type_human = Players::PlayerType.new(:Human) player_type_computer = Players::PlayerType.new(:Computer) # define match types match1_human_vs_human = GamePlay::MatchType.new(player_type_human, player_type_human) match2_human_vs_computer = GamePlay::MatchType.new(player_type_human, player_type_computer) match3_computer_vs_computer = GamePlay::MatchType.new(player_type_computer, player_type_computer) # add match types to manager @matches = [] @matches << match1_human_vs_human @matches << match2_human_vs_computer @matches << match3_computer_vs_computer end
Public Instance Methods
get_match_numbers()
click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/gameplay/match_type_manager.rb, line 44 def get_match_numbers array = [] number = 1 total = get_total_available_matches total.times do array << number number = number + 1 end result = array end
get_match_type(match_number)
click to toggle source
match_number: The number of the match, where 1 represents the first match displayed in the game (Human vs Human).
# File lib/tic_tac_toe_rz/tictactoeruby.core/gameplay/match_type_manager.rb, line 33 def get_match_type(match_number) raise Exceptions::InvalidValueError, "match_number" if !valid?(match_number) index = match_number - 1 match_type = @matches[index] end
get_total_available_matches()
click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/gameplay/match_type_manager.rb, line 28 def get_total_available_matches total = @matches.length end
input_choices()
click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/gameplay/match_type_manager.rb, line 55 def input_choices choices = get_match_numbers.map(&:to_s) end
player_type(match_number, player_number)
click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/gameplay/match_type_manager.rb, line 59 def player_type(match_number, player_number) match_type = get_match_type(match_number) case player_number when 1 match_type.player1_type.selected_option.to_s when 2 match_type.player2_type.selected_option.to_s else raise Exceptions::InvalidValueError end end
valid?(match_number)
click to toggle source
# File lib/tic_tac_toe_rz/tictactoeruby.core/gameplay/match_type_manager.rb, line 39 def valid?(match_number) max_match_number = get_total_available_matches valid = match_number >= 1 && match_number <= max_match_number end