Class: Checkers::GUI::Scene::Board
- Inherits:
-
Object
- Object
- Checkers::GUI::Scene::Board
- Includes:
- Enumerable
- Defined in:
- lib/checkers/gui/scene/board.rb
Instance Attribute Summary collapse
-
#animation_queue ⇒ Object
readonly
Returns the value of attribute animation_queue.
Instance Method Summary collapse
- #clear ⇒ Object
- #each(&block) ⇒ Object
- #find_index(&block) ⇒ Object
-
#initialize(state, game_engine) ⇒ Board
constructor
A new instance of Board.
- #piece_at(row, col) ⇒ Object
- #square_at(row, col) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(state, game_engine) ⇒ Board
Returns a new instance of Board.
11 12 13 14 15 16 17 |
# File 'lib/checkers/gui/scene/board.rb', line 11 def initialize(state, game_engine) @state = state @state.add_observer(self) @game_engine = game_engine @animation_queue = [] render_board end |
Instance Attribute Details
#animation_queue ⇒ Object (readonly)
Returns the value of attribute animation_queue.
9 10 11 |
# File 'lib/checkers/gui/scene/board.rb', line 9 def animation_queue @animation_queue end |
Instance Method Details
#clear ⇒ Object
41 42 43 |
# File 'lib/checkers/gui/scene/board.rb', line 41 def clear @board_objects.each(&:remove) if @board_objects&.any? end |
#each(&block) ⇒ Object
33 34 35 |
# File 'lib/checkers/gui/scene/board.rb', line 33 def each(&block) @board_objects.each(&block) end |
#find_index(&block) ⇒ Object
37 38 39 |
# File 'lib/checkers/gui/scene/board.rb', line 37 def find_index(&block) @board_objects.find_index(&block) end |
#piece_at(row, col) ⇒ Object
49 50 51 |
# File 'lib/checkers/gui/scene/board.rb', line 49 def piece_at(row, col) return @board_objects[row, col] if @board_objects[row, col].is_a?(Ruby2D::SquareWithPiece) end |
#square_at(row, col) ⇒ Object
45 46 47 |
# File 'lib/checkers/gui/scene/board.rb', line 45 def square_at(row, col) return @board_objects[row, col] if @board_objects[row, col].is_a?(Square) end |
#update ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/checkers/gui/scene/board.rb', line 19 def update return if @state.winner || @state.tie check_win check_tie @animation_queue.unshift( PieceAnimation.animate(self, @state.board.last_move) do render_board @game_engine.play end ) end |