class Gobstones::CLI::Printer

Constants

TEMPLATE

Public Class Methods

new(program_result) click to toggle source
# File lib/gobstones/cli/printer.rb, line 8
def initialize(program_result)
  @program_result = program_result
  @board = TEMPLATE
end

Public Instance Methods

print() click to toggle source
print_board() click to toggle source
print_return_values() click to toggle source

Private Instance Methods

board() click to toggle source
# File lib/gobstones/cli/printer.rb, line 36
def board
  head.board
end
cell_height() click to toggle source
# File lib/gobstones/cli/printer.rb, line 94
def cell_height
  4
end
cell_top_left_corner(x, y) click to toggle source
# File lib/gobstones/cli/printer.rb, line 102
def cell_top_left_corner(x, y)
  head_lines = 1
  head_chars = 4
  y_to_go = (total_columns - 1 - y) * cell_height + head_lines
  x_to_go = x * cell_width + head_chars
  (y_to_go * line_length) + x_to_go
end
cell_width() click to toggle source
# File lib/gobstones/cli/printer.rb, line 98
def cell_width
  10
end
head() click to toggle source
# File lib/gobstones/cli/printer.rb, line 32
def head
  @program_result.head
end
highlight_column(x, y, char) click to toggle source
# File lib/gobstones/cli/printer.rb, line 83
def highlight_column(x, y, char)
  corner = cell_top_left_corner(x, y)
  (cell_height - 1).times do |index|
    @board[corner + ((index + 1) * line_length)] = char
  end
end
highlight_current_cell() click to toggle source
# File lib/gobstones/cli/printer.rb, line 40
def highlight_current_cell
  char = 'X'
  x = head.x_pos
  y = head.y_pos
  highlight_row x, y, char
  highlight_row x, y - 1, char
  highlight_column x, y, char
  highlight_column x + 1, y, char
end
highlight_row(x, y, char) click to toggle source
# File lib/gobstones/cli/printer.rb, line 76
def highlight_row(x, y, char)
  corner = cell_top_left_corner(x, y)
  (cell_width - 1).times do |index|
    @board[corner + index + 1] = char
  end
end
line_length() click to toggle source
# File lib/gobstones/cli/printer.rb, line 90
def line_length
  98
end
put_ball_value(number, char, x, y, x_offset, y_offset) click to toggle source
# File lib/gobstones/cli/printer.rb, line 61
def put_ball_value(number, char, x, y, x_offset, y_offset)
  return if number.zero?

  corner = cell_top_left_corner(x, y)
  pos = corner + (y_offset * line_length) + x_offset
  if number < 10
    @board[pos] = ' '
    @board[pos + 1] = number.to_s
  else
    @board[pos] = number.to_s[0]
    @board[pos + 1] = number.to_s[1]
  end
  @board[pos + 2] = char
end
put_ball_values() click to toggle source
# File lib/gobstones/cli/printer.rb, line 50
def put_ball_values
  total_rows.times do |x|
    total_columns.times do |y|
      put_ball_value board.number_of_balls(x, y, Lang::Negro.new), 'N', x, y, 2, 1
      put_ball_value board.number_of_balls(x, y, Lang::Azul.new), 'A', x, y, 6, 1
      put_ball_value board.number_of_balls(x, y, Lang::Verde.new), 'V', x, y, 2, 3
      put_ball_value board.number_of_balls(x, y, Lang::Rojo.new), 'R', x, y, 6, 3
    end
  end
end
total_columns() click to toggle source
# File lib/gobstones/cli/printer.rb, line 110
def total_columns
  9
end
total_rows() click to toggle source
# File lib/gobstones/cli/printer.rb, line 114
def total_rows
  9
end