Skip to content

Instantly share code, notes, and snippets.

@msarit
Created May 23, 2018 20:24
Show Gist options
  • Select an option

  • Save msarit/cb2cab3c6b6931ab3ef2712015bfe56f to your computer and use it in GitHub Desktop.

Select an option

Save msarit/cb2cab3c6b6931ab3ef2712015bfe56f to your computer and use it in GitHub Desktop.
def move_to!(x,y)
destination = game.pieces.find_by(location_x: x, location_y: y)
if destination.nil?
self.update_attributes(location_x: x, location_y: y)
elsif self.white != destination.white
destination.update_attributes(location_x: nil, location_y: nil, notcaptured: false)
self.update_attributes(location_x: x, location_y: y)
else
flash[:alert] = "Cannot move there; occupied by friendly"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment