class View::SelectMove

Constants

SELECT_COL_MESSAGE
SELECT_ROW_MESSAGE

Public Class Methods

new(board_presenter, terminal_util) click to toggle source
# File lib/tic_tac_toe/view/select_move.rb, line 6
def initialize(board_presenter, terminal_util)
  @board_presenter = board_presenter
  @terminal_util = terminal_util
end

Public Instance Methods

render() click to toggle source
# File lib/tic_tac_toe/view/select_move.rb, line 11
def render
  display_msg("Go #{@board_presenter.current_team.name}")

  select_move
end

Private Instance Methods

select_move() click to toggle source
# File lib/tic_tac_toe/view/select_move.rb, line 19
def select_move
  current_team = @board_presenter.current_team

  if current_team.computer?
    @board_presenter.computer_select_move(current_team)
  else
    display_msg(SELECT_ROW_MESSAGE)

    row = @terminal_util.get_integer_input

    display_msg(SELECT_COL_MESSAGE)

    col = @terminal_util.get_integer_input

    raise InvalidSelection, 'Invalid Tile Selection :(' if @board_presenter.invalid_tile_selection?(row, col)

    @board_presenter.select_move(row, col, current_team)
  end
end