Class: Configuration
- Inherits:
-
Object
- Object
- Configuration
- Defined in:
- lib/configuration.rb
Instance Attribute Summary collapse
-
#ai ⇒ Object
Returns the value of attribute ai.
-
#board_width ⇒ Object
Returns the value of attribute board_width.
-
#ui ⇒ Object
Returns the value of attribute ui.
Instance Method Summary collapse
- #configure_board(player_1, player_2) ⇒ Object
- #configure_opponent ⇒ Object
- #configure_player_1(marker) ⇒ Object
- #configure_player_2(marker) ⇒ Object
- #get_marker ⇒ Object
-
#initialize(user_interface) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(user_interface) ⇒ Configuration
Returns a new instance of Configuration.
11 12 13 14 15 |
# File 'lib/configuration.rb', line 11 def initialize(user_interface) @ui = user_interface @ai = Unbeatable_AI.new @board_width = false end |
Instance Attribute Details
#ai ⇒ Object
Returns the value of attribute ai.
9 10 11 |
# File 'lib/configuration.rb', line 9 def ai @ai end |
#board_width ⇒ Object
Returns the value of attribute board_width.
9 10 11 |
# File 'lib/configuration.rb', line 9 def board_width @board_width end |
#ui ⇒ Object
Returns the value of attribute ui.
9 10 11 |
# File 'lib/configuration.rb', line 9 def ui @ui end |
Instance Method Details
#configure_board(player_1, player_2) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/configuration.rb', line 53 def configure_board(player_1, player_2) board = Board.new(player_1, player_2) @ui.ask_for_width_of_board board_width = @ui.get_width_of_board if board_width == 3 board.width = 3 board elsif board_width == 4 board.width = 4 board.current_board = board.squares_with_integers board else configure_board(player_1, player_2) end end |
#configure_opponent ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/configuration.rb', line 17 def configure_opponent @ui.ask_for_opponent opponent_type = @ui.get_opponent if opponent_type == 1 @ai.opponent = true @ai else @ai.opponent = false @ai end end |
#configure_player_1(marker) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/configuration.rb', line 35 def configure_player_1(marker) if marker.length == 1 and marker =~ /[A-Za-z]/ player_1 = Player.new(marker) else @ui.marker_error configure_player_1(get_marker) end end |
#configure_player_2(marker) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/configuration.rb', line 44 def configure_player_2(marker) if marker.length == 1 and marker =~ /[A-Za-z]/ player_2 = Player.new(marker) else @ui.marker_error configure_player_2(get_marker) end end |
#get_marker ⇒ Object
29 30 31 32 33 |
# File 'lib/configuration.rb', line 29 def get_marker @ui.ask_for_marker_type marker = @ui.get_marker_type return marker end |