Class: RubyTerminalGames::Sudoku::Board

Inherits:
Board
  • Object
show all
Defined in:
lib/ruby_terminal_games/sudoku/board.rb

Instance Attribute Summary

Attributes inherited from Board

#cols, #height, #rows, #width

Instance Method Summary collapse

Methods inherited from Board

#clear!, #draw_border!, #initialize, #move_cursor, #write

Constructor Details

This class inherits a constructor from RubyTerminalGames::Board

Instance Method Details



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby_terminal_games/sudoku/board.rb', line 4

def print_board(game)
  clear!
  print_top_border!
  print_middle_borders!
  print_bottom_border!
  print_instructions!

  user_inputs = game.user_inputs
  user_input_index = game.user_input_index
  state = game.puzzle.state

  user_inputs.each_with_index do |input, index|
    highlight = (input == user_inputs[user_input_index])
    row, col = input
    number = (state[index] || " ").to_s

    if game.puzzle.locked_position?(index)
      if highlight
        output = number.colorize(
          background: :green,
          color: :white
        )
      else
        output = number.colorize(color: :green)
      end
    else
      output = number

      if highlight
        output = number
          .colorize(background: :light_yellow, color: :black)
      end
    end

    write(output, row: row, col: col)
  end
end