yea you can destroy the green pieces if they are not overlapping the grid tilebackground or are spawned outside that way u cant click them therefor u wont be able to move outside.
here you go i modified the capx a bit. remember to keep the sizes of the grid relatively to 36 pixels or something like that. the grid is based on visual placement.
but u can do it using arrays or other stuff. but this method i find it most simple then most.