Class: Othello::BoardView
- Inherits:
-
TclTkWidget
- Object
- TclTkObject
- TclTkCommand
- TclTkWidget
- Othello::BoardView
- Defined in:
- sample/tcltklib/sample2.rb
Overview
————————–> class Board ends here
Defined Under Namespace
Classes: Square
Constant Summary collapse
- BACK_GROUND_COLOR =
"DarkGreen"
- HILIT_BG_COLOR =
"green"
- BORDER_COLOR =
"black"
- BLACK_COLOR =
"black"
- WHITE_COLOR =
"white"
- STOP_COLOR =
"red"
Instance Attribute Summary collapse
-
#bottom ⇒ Object
readonly
Returns the value of attribute bottom.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
-
#top ⇒ Object
readonly
Returns the value of attribute top.
Instance Method Summary collapse
- #clear ⇒ Object
- #click_square(square) ⇒ Object
- #each_square ⇒ Object
-
#initialize(othello, board) ⇒ BoardView
constructor
———————–> class Square ends here.
- #tk_rect(left, top, right, bottom) ⇒ Object
- #update(row = nil, col = nil) ⇒ Object
Methods inherited from TclTkCommand
Methods inherited from TclTkObject
Constructor Details
#initialize(othello, board) ⇒ BoardView
———————–> class Square ends here
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'sample/tcltklib/sample2.rb', line 232 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 Attribute Details
#bottom ⇒ Object (readonly)
Returns the value of attribute bottom
190 191 192 |
# File 'sample/tcltklib/sample2.rb', line 190 def bottom @bottom end |
#left ⇒ Object (readonly)
Returns the value of attribute left
187 188 189 |
# File 'sample/tcltklib/sample2.rb', line 187 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right
189 190 191 |
# File 'sample/tcltklib/sample2.rb', line 189 def right @right end |
#top ⇒ Object (readonly)
Returns the value of attribute top
188 189 190 |
# File 'sample/tcltklib/sample2.rb', line 188 def top @top end |
Instance Method Details
#clear ⇒ Object
265 266 267 268 269 270 271 272 |
# File 'sample/tcltklib/sample2.rb', line 265 def clear each_square do |square| if square.oval != nil self.e("delete", square.oval) square.oval = nil end end end |
#click_square(square) ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 |
# File 'sample/tcltklib/sample2.rb', line 324 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 ⇒ Object
316 317 318 319 320 321 322 |
# File 'sample/tcltklib/sample2.rb', line 316 def each_square @squares.each do |rows| rows.each do |square| yield(square) end end end |
#tk_rect(left, top, right, bottom) ⇒ Object
260 261 262 263 |
# File 'sample/tcltklib/sample2.rb', line 260 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) ⇒ Object
304 305 306 307 308 309 310 311 312 313 314 |
# File 'sample/tcltklib/sample2.rb', line 304 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 |