There are probably other ways to do it. One would be to use raycasting by calculating the intersection of two lines. The example here just does it by steps. The 16 is the distance the laser moves per step. It works only with horizontal or vertical walls though.
The problem is basically:
Thinking of the end of a laser as a moving object,
move it till it hits a wall,
using the angle of the wall calculate the new angle of the object and repeat.
If you use raycasting math it can be 100% precise. I did the math for it a while ago and made a quick example here:https://dl.dropboxusercontent.com/u/542 ... _math.capx