Namespace
Methods
C
E
N
T
U
Constants
BACK_GROUND_COLOR = "DarkGreen"
 
HILIT_BG_COLOR = "green"
 
BORDER_COLOR = "black"
 
BLACK_COLOR = "black"
 
WHITE_COLOR = "white"
 
STOP_COLOR = "red"
 
Attributes
[R] bottom
[R] left
[R] right
[R] top
Class Public methods
new(othello, board)
# File ext/tk/sample/tcltklib/sample2.rb, line 231
def initialize(othello, board)
   super($ip, $root, $canvas)
   @othello = othello
   @board = board
   @board.add_observer(self)

   @squares = Array.new(8)
   for i in 0 .. 7
      @squares[i] = Array.new(8)
   end
   @left = 1
   @top = 0.5
   @right = @left + 8
   @bottom = @top + 8

   i = self.e("create rectangle", *tk_rect(@left, @top, @right, @bottom))
   self.e("itemconfigure", i,
      "-width 1m -outline #{BORDER_COLOR} -fill #{BACK_GROUND_COLOR}")

   for row in 0 .. 7
      for col in 0 .. 7
         @squares[row][col] = Square.new(self, row, col)
      end
   end

   update
end
Instance Public methods
clear()
# File ext/tk/sample/tcltklib/sample2.rb, line 264
def clear
   each_square do |square|
      if square.oval != nil
         self.e("delete", square.oval)
         square.oval = nil
      end
   end
end
click_square(square)
# File ext/tk/sample/tcltklib/sample2.rb, line 323
def click_square(square)
   if @othello.in_com_turn || @othello.game_over ||
         @board.count_point(square.row,
                            square.col,
                            @board.man_disk) == 0
      square.blink(STOP_COLOR)
      return
   end
   @board.put_disk(square.row, square.col, @board.man_disk)
   @othello.com_turn
end
each_square()
# File ext/tk/sample/tcltklib/sample2.rb, line 315
def each_square
   @squares.each do |rows|
      rows.each do |square|
         yield(square)
      end
   end
end
tk_rect(left, top, right, bottom)
# File ext/tk/sample/tcltklib/sample2.rb, line 259
def tk_rect(left, top, right, bottom)
   return left.to_s + "c", top.to_s + "c",
      right.to_s + "c", bottom.to_s + "c"
end
update(row = nil, col = nil)
# File ext/tk/sample/tcltklib/sample2.rb, line 303
def update(row = nil, col = nil)
   if row && col
      draw_disk(row, col, @board.get_disk(row, col))
   else
      each_square do |square|
         draw_disk(square.row, square.col,
                   @board.get_disk(square.row, square.col))
      end
   end
   @othello.show_point
end