class RubyGo::TextPrinter
Constants
- COLORS
Attributes
io[R]
Public Class Methods
new(io)
click to toggle source
# File lib/ruby-go/printers/text.rb, line 7 def initialize(io) @io = io end
Public Instance Methods
print_game(game)
click to toggle source
# File lib/ruby-go/printers/text.rb, line 11 def print_game(game) print_board(game.board) io.puts " " + "_"*(game.board.size * 2) io.print " Prisoners || White: #{game.captures[:black]} |" io.puts " Black: #{game.captures[:white]}" io.puts " " + "-"*(game.board.size * 2) end
Private Instance Methods
print_board(board)
click to toggle source
# File lib/ruby-go/printers/text.rb, line 21 def print_board(board) if board.size < 11 io.puts " #{(0..board.size - 1).to_a.join(' ')}" else io.puts " #{(0..10).to_a.join(' ')}#{(11..board.size - 1).to_a.join('')}" end board.rows.each_with_index do |row, i| i = " #{i}" if i < 10 io.print "#{i} " row.each { |stn| print_stone(stn) } io.puts end end
print_stone(stone)
click to toggle source
# File lib/ruby-go/printers/text.rb, line 36 def print_stone(stone) io.print "#{COLORS[stone.color]} " end