Sha256: ef60a794bed4237557f0422235be839ab6b0ae1c9844425f1c793fa2b67ae8ec

Contents?: true

Size: 966 Bytes

Versions: 1

Compression:

Stored size: 966 Bytes

Contents

module View
  class SelectMove < View::Base
    SELECT_ROW_MESSAGE = 'Please select a row'.freeze
    SELECT_COL_MESSAGE = 'Please select a col'.freeze

    def initialize(board_presenter, terminal_util)
      @board_presenter = board_presenter
      @terminal_util = terminal_util
    end

    def render
      display_msg("Go #{@board_presenter.current_team.name}")

      select_move
    end

    private

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sams_tic_tac_toe-0.0.1 lib/tic_tac_toe/view/select_move.rb