class TictactoeGto::Board
Attributes
array[R]
size[R]
Public Class Methods
get_size()
click to toggle source
# File lib/tictactoe_gto.rb, line 60 def self.get_size loop do print 'Ingresa el tamaƱo del tablero: ' begin board_size = gets.chomp board_size = Integer(board_size) rescue print 'Are you sure it is a number? Please try again: ' retry end if board_size < 2 puts 'Board size must be 2X2 or higher, try again.' else puts 'Get ready!' return board_size end end end
new(size)
click to toggle source
# File lib/tictactoe_gto.rb, line 30 def initialize(size) @size = size end
Public Instance Methods
display()
click to toggle source
# File lib/tictactoe_gto.rb, line 40 def display print ' ' @size.times { |i| print ' ' + i.to_s + ' ' } puts "\n" @array.each_with_index do |row, index| print index.to_s + ' ' row.each { |box| box.display } print "\n" end end
fill()
click to toggle source
# File lib/tictactoe_gto.rb, line 34 def fill @array = Array.new(@size) do Array.new(@size) { Box.new(' ') } end end
fill_at(pos, id)
click to toggle source
# File lib/tictactoe_gto.rb, line 51 def fill_at(pos, id) box = @array[pos['x']][pos['y']] if box.is_empty? box.value = id else puts "> That spot is not available. Yo missed your chance :c" end end