Class: BoardPrinterThreeDim

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

Instance Method Summary collapse

Constructor Details

#initialize(output = STDOUT) ⇒ BoardPrinterThreeDim

Returns a new instance of BoardPrinterThreeDim.



3
4
5
# File 'lib/board_printer_three_dim.rb', line 3

def initialize output= STDOUT
	@output = output
end

Instance Method Details

#get_element_symbol(board_array, index) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/board_printer_three_dim.rb', line 33

def get_element_symbol board_array, index
	case board_array[index]
	when :x then symbol = "X"
	when :o then symbol = "O"
	else symbol = index end
	symbol
end


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
# File 'lib/board_printer_three_dim.rb', line 7

def print print_results
	board = print_results[0]
	row_length = print_results[1].to_i

	start_index = 0
	row_length.times do
		index = start_index
		row_length.times do
			row_length.times do
				symbol = get_element_symbol board, index
				if symbol.to_s.size == 1
					@output.print "  #{symbol} "
				else
					@output.print " #{symbol} "
				end
				index += 1
			end
			@output.print "   "
			index += 6
		end
		@output.puts 
		start_index += row_length
	end
       @output.puts
end