Advertisement
Guest User

Untitled

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