Class: Board

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cols, rows) ⇒ Board

Returns a new instance of Board.



6
7
8
9
10
11
# File 'lib/board.rb', line 6

def initialize(cols, rows)
  @cols = cols
  @rows = rows
  setMatriz()
  printBoard()
end

Instance Attribute Details

#colsObject (readonly)

Returns the value of attribute cols.



5
6
7
# File 'lib/board.rb', line 5

def cols
  @cols
end

#matrizObject (readonly)

Returns the value of attribute matriz.



5
6
7
# File 'lib/board.rb', line 5

def matriz
  @matriz
end

#rowsObject (readonly)

Returns the value of attribute rows.



5
6
7
# File 'lib/board.rb', line 5

def rows
  @rows
end

Instance Method Details

#getMatrizObject



63
64
65
# File 'lib/board.rb', line 63

def getMatriz
  return $matriz
end

#printBoardObject



39
40
41
42
43
# File 'lib/board.rb', line 39

def printBoard
  printRows()
  printMatriz()
  puts ''
end

#setPoint(x, sym) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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