Class: MM::BoardPresenterTerminal

Inherits:
Object
  • Object
show all
Defined in:
lib/games/mastermind/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/mastermind/board_presenter_terminal.rb', line 3

def board
  @board
end

Instance Method Details

#display_valuesObject



56
57
58
# File 'lib/games/mastermind/board_presenter_terminal.rb', line 56

def display_values
  board.display_values
end

#number_of_rowsObject



64
65
66
# File 'lib/games/mastermind/board_presenter_terminal.rb', line 64

def number_of_rows
  board.number_of_rows
end

#present_board(board) ⇒ Object



5
6
7
8
# File 'lib/games/mastermind/board_presenter_terminal.rb', line 5

def present_board(board)
  @board = board
  present_board_and_results(self.board)
end

#present_board_and_results(board) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/games/mastermind/board_presenter_terminal.rb', line 28

def present_board_and_results(board)
  @board = board

  print "     Guess" + "                    " +"Result"
  print "\n"
  puts "-" * 40
  guesses_and_results = display_values.zip(result_values)
  #board.display_values will return multidimensional array
  guesses_and_results.each do |values|
    #values is either display_values or result_values
    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
        if display_value == nil
          print "  "
        else
          printf "%2s", display_value
        end

        print " | " unless index == (row.size - 1)
      end
      print "       " unless row.equal? values.last
    end
    print "\n"
    puts "_"*(values.size * 20) unless values.equal? guesses_and_results.last
  end
end

#present_board_only(board) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/games/mastermind/board_presenter_terminal.rb', line 10

def present_board_only(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
      if display_value == nil
        print "  "
      else
        printf "%2s", display_value
      end

      print " | " unless index == (row.size - 1)
    end
    print "\n"
    puts "_"*(row.size * 5) unless row_number.equal? (number_of_rows - 1)
  end
end

#result_valuesObject



60
61
62
# File 'lib/games/mastermind/board_presenter_terminal.rb', line 60

def result_values
  board.result_values
end