Thanks, Pah. I might have some suggestions depending on how you want to do this. Is this going to be a Widows Forms application or a web-based app?

If Windows Forms, you could just use a bunch of pictureboxes in a grid, and then rotate the image onclick(). Web-based probably javascript to place images and rotate.

For rotation, why not use an array with four positions, representing "top", "right", "down", "left." Then fill the array with 0 if no line and 1 if line, so a line from top to boottom would be [1,0,1,0]. You could use multi-dimensional arrays with the first dimension representing the x,y grid coordinate of the square, and the second dimension representing which side the line went to. By comparing cell[0,1] to cell[1,1], you can tell if the lines are touching.

Just some ideas. I could maybe help mre if I knew how/what platform you wanted to build this on. Good luck!