Class: Checkers::GUI::Scene
- Inherits:
-
Object
- Object
- Checkers::GUI::Scene
- Extended by:
- Forwardable
- Defined in:
- lib/checkers/gui/scene.rb,
lib/checkers/gui/scene/board.rb,
lib/checkers/gui/scene/piece_animation.rb
Defined Under Namespace
Classes: Board, PieceAnimation
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
Instance Method Summary collapse
- #handle_click(x, y) ⇒ Object
-
#initialize(state, game_enigne) ⇒ Scene
constructor
A new instance of Scene.
Constructor Details
Instance Attribute Details
#board ⇒ Object (readonly)
Returns the value of attribute board.
8 9 10 |
# File 'lib/checkers/gui/scene.rb', line 8 def board @board end |
Instance Method Details
#handle_click(x, y) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/checkers/gui/scene.rb', line 19 def handle_click(x, y) row, col = click_board_indices(x, y) if piece_clicked?(x, y) @allowed_moves = @state.board.find_available_moves(row: row, col: col, player: :human) @allowed_squares = @allowed_moves.map { |move| @board.square_at(*move.end_square) } else return if @allowed_squares.empty? && @allowed_moves.empty? move_made = @allowed_moves.find { |move| move.end_square == [row, col] } if move_made @allowed_moves = [] @allowed_squares = [] new_board = Checkers::Board.make_move(@state.board, move_made) turn = if new_board.jumped new_board.any_jump_moves?(player: :human) ? :human : :ai else :ai end @state.set_state(board: new_board, turn: turn) end end end |