Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def capture?(to_x:, to_y:)
- # lines 3-4 define the opponent; it's the opposite of this piece's color
- opp_col = "white" if color == "black"
- opp_col = "black" if color == "white"
- # line 6 sets a variable for the target piece, which must have an active piece with
- # the opponent's color in order to not be nil.
- piece_in_target = Piece.where(x_position: to_x, y_position: to_y, active: true, color: opp_col)
- if piece_in_target.exists? # If there is an enemy piece, do the following:
- piece_in_target.active = false # kill it (make active: false)
- # Need a way to make sure that the piece that we are moving doesn't think it's obstructed
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement