class Board

Attributes

cols[R]
matriz[R]
rows[R]

Public Class Methods

new(cols, rows) click to toggle source
# File lib/board.rb, line 6
def initialize(cols, rows)
  @cols = cols
  @rows = rows
  setMatriz()
  printBoard()
end

Public Instance Methods

getMatriz() click to toggle source
# File lib/board.rb, line 63
def getMatriz
  return $matriz
end
printBoard() click to toggle source
# File lib/board.rb, line 39
def printBoard
  printRows()
  printMatriz()
  puts ''
end
setPoint(x, sym) click to toggle source
# File lib/board.rb, line 45
def setPoint(x, sym)
  point = 0
  if x < @rows
    point = @cols+1
    x -= 1
    while $matriz[point][x] != '|' do
      point = point - 1
    end
    $matriz[point][x] = sym
    system 'clear' or system 'cls'
    printBoard()
  else
    puts "Exception: Number of selected row too big"
    raise BigNumber
  end
  return point
end

Private Instance Methods

printMatriz() click to toggle source
# File lib/board.rb, line 29
def printMatriz
  $matriz.each do |i|
    i.each do |j|
      print " #{j} "
    end
    puts ''
  end
end
printRows() click to toggle source
# File lib/board.rb, line 18
def printRows
  i = 1
  while i < (rows-1) do
    if i < 10 then print " #{i} "
    else print " #{i}"
    end
    i += 1
  end
  puts ''
end
setMatriz() click to toggle source
# File lib/board.rb, line 14
def setMatriz
  $matriz = Array.new(@rows) {Array.new(@cols, '|')}
end