Class: TTT::GameConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/tictactoe/game_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_helper) ⇒ GameConfig

Returns a new instance of GameConfig.



13
14
15
16
17
# File 'lib/tictactoe/game_config.rb', line 13

def initialize(input_helper)
  @input_helper = input_helper
  setup

end

Instance Attribute Details

#computer_difficulty_levelObject

Returns the value of attribute computer_difficulty_level.



10
11
12
# File 'lib/tictactoe/game_config.rb', line 10

def computer_difficulty_level
  @computer_difficulty_level
end

#input_helperObject

Returns the value of attribute input_helper.



3
4
5
# File 'lib/tictactoe/game_config.rb', line 3

def input_helper
  @input_helper
end

#number_of_rows_colsObject

Returns the value of attribute number_of_rows_cols.



11
12
13
# File 'lib/tictactoe/game_config.rb', line 11

def number_of_rows_cols
  @number_of_rows_cols
end

#player_1_nameObject

Returns the value of attribute player_1_name.



5
6
7
# File 'lib/tictactoe/game_config.rb', line 5

def player_1_name
  @player_1_name
end

#player_1_valueObject

Returns the value of attribute player_1_value.



6
7
8
# File 'lib/tictactoe/game_config.rb', line 6

def player_1_value
  @player_1_value
end

#player_2_nameObject

Returns the value of attribute player_2_name.



8
9
10
# File 'lib/tictactoe/game_config.rb', line 8

def player_2_name
  @player_2_name
end

#player_2_typeObject

Returns the value of attribute player_2_type.



7
8
9
# File 'lib/tictactoe/game_config.rb', line 7

def player_2_type
  @player_2_type
end

#player_2_valueObject

Returns the value of attribute player_2_value.



9
10
11
# File 'lib/tictactoe/game_config.rb', line 9

def player_2_value
  @player_2_value
end

Instance Method Details

#computer_difficult?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/tictactoe/game_config.rb', line 59

def computer_difficult?
  computer_difficulty_level == :difficult
end

#get_computer_valueObject



63
64
65
66
67
68
69
# File 'lib/tictactoe/game_config.rb', line 63

def get_computer_value
  if player_2_value != "O"
    "O"
  else
    "X"
  end
end

#player_2_computer?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/tictactoe/game_config.rb', line 55

def player_2_computer?
  player_2_type == :computer
end

#player_2_human?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/tictactoe/game_config.rb', line 51

def player_2_human?
  player_2_type == :human
end

#set_board_rows_colsObject



42
43
44
45
46
47
48
49
# File 'lib/tictactoe/game_config.rb', line 42

def set_board_rows_cols
  #need this if else logic because if computer is difficult, it runs minimax, which is too slow to allow for more than 3 rows/cols
  if computer_difficult?
    self.number_of_rows_cols = input_helper.get_number_of_rows_cols_max_3
  else
    self.number_of_rows_cols = input_helper.get_number_of_rows_cols_max_9
  end
end

#set_player_1_valuesObject



25
26
27
28
# File 'lib/tictactoe/game_config.rb', line 25

def set_player_1_values
  self.player_1_name = input_helper.get_player_1_name
  self.player_1_value = input_helper.get_player_1_value(player_1_name)
end

#set_player_2_valuesObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tictactoe/game_config.rb', line 30

def set_player_2_values
  self.player_2_type = input_helper.get_player_2_type
  if player_2_human?
    self.player_2_name = input_helper.get_player_2_name
    self.player_2_value = input_helper.get_player_2_value(player_1_value)
  elsif player_2_computer?
    self.player_2_name = "Computer"
    self.player_2_value = get_computer_value
    self.computer_difficulty_level = input_helper.get_computer_difficulty_level
  end
end

#setupObject



19
20
21
22
23
# File 'lib/tictactoe/game_config.rb', line 19

def setup
  set_player_1_values
  set_player_2_values
  set_board_rows_cols
end