samples/05_mouse/01_mouse_click/app/main.rb
# Handles user input for placing pieces on the board.
Handles user input for placing pieces on the board.
Handles user input for placing pieces on the board .
def input_place_piece
    return if state.game_over
    __, __, space = all_spaces.find do |__, __, space|
      inputs.mouse.click.point.inside_rect?(space.border) && !space.piece
    end
    return unless space
    space.piece = state.current_turn
    state.current_turn = state.current_turn == :x ? :o : :x
  end
def input_place_piece return if state . game_over __ , __ , space = all_spaces . find do | __ , __ , space | inputs . mouse . click . point . inside_rect? ( space . border ) && ! space . piece end return unless space space . piece = state . current_turn state . current_turn = state . current_turn == :x ? :o : :x end
Handles user input for placing pieces on the board.
Handles user input for placing pieces on the board .
# Checks to find the space that the mouse was clicked inside of, and makes sure the space does not already # have a piece in it. # The piece that goes into the space belongs to the player whose turn it currently is. # This ternary operator statement allows us to change the current player's turn. # If it is currently x's turn, it becomes o's turn. If it is not x's turn, it become's x's turn.