Class: TTT::BoardPresenterTerminal

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#boardObject

Returns the value of attribute board.



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

def board
  @board
end

Instance Method Details

#display_valuesObject



20
21
22
# File 'lib/games/tictactoe/board_presenter_terminal.rb', line 20

def display_values
  board.display_values
end

#number_of_rowsObject



24
25
26
# File 'lib/games/tictactoe/board_presenter_terminal.rb', line 24

def number_of_rows
  board.number_of_rows
end

#present_board(board) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/games/tictactoe/board_presenter_terminal.rb', line 5

def present_board(board)
  @board = board
  #board.display_values will return multidimensional array
  display_values.each_with_index do |row, row_number|
    row.each_with_index do |display_value, index|
      #http://www.evc-cit.info/cit020/beginning-programming/chp_04/file_printf.html
      printf "%2s", display_value
      print " | " unless index == (row.size - 1)
    end
    print "\n"
    #row_number starts at 0
    puts "_"*(row.size * 5) unless row_number.equal? (number_of_rows - 1)
  end
end