If you're doing nice grid-based movements I'd suggest using a 2d array. Everytime the object is dragged and let go, find the new mouse position relative to the old mouse position to find out which direction it was dragged. Then check those new positions in the matrix to see if it is empty, update and redraw. For example:
{ {0, 0, 2, 2}
{1, 1, 1, 2}
{1, 0, 2, 2}
{1, 0, 0, 0} }
0 = empty, 1 = shape 1, 2 = shape 2
If you try to move shape 1 to the right, first check that the array is big enough each time and if so check the item to the right of each 1. If any of the checks return something other than 0 or 1 then change some variable to mean that it is impossible (a boolean is suitable). Otherwise, set all the 1's to 0's and all the 0's in the new position to 1's.
{ {0, 0, 2, 2}
{1, 1, 1, 2}
{1, 0, 2, 2}
{1, 0, 0, 0} }
0 = empty, 1 = shape 1, 2 = shape 2
If you try to move shape 1 to the right, first check that the array is big enough each time and if so check the item to the right of each 1. If any of the checks return something other than 0 or 1 then change some variable to mean that it is impossible (a boolean is suitable). Otherwise, set all the 1's to 0's and all the 0's in the new position to 1's.