This is where you need a "path finding algorithm". On a clear playfield, you could follow a straight line to the target. However, with obstacles in the way, you need to give it the AI to decide the best way around, or if it's even possible.
A search on codeproject.com will yield several articles on path finding.