Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Daniel W](https://secure.gravatar.com/avatar/bde6f49ad13fde243fc23d897e3366ba?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Daniel W
1,341 PointsHow to check if Tower is on the Path?
The Tower class has a private readonly MapLocation _location;
In the constructor where we specify a location, we would like a check to see if such a location is on the path.
What is the best way to do this? Is it viable to g
My initial thought was to rework the code
namespace TreehouseDefense
{
class Path
{
private readonly MapLocation[] _path; //Needs to be a property?
into:
public MapLocation PathArray {get; private set;} //PathArray can't be named Path, can it?
and in the constructor
public Path(MapLocation[] path)
{
PathArray = path;
}
Then we could access the PathArray property from the Tower class, so that in the tower's constructor, we could loop through the PathArray to see if it's on there or not..
Is there an easier solution?
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsIf the path is guaranteed to be straight, you can check the bounds of the path without looping. But if the path could possibly wander around, then the loop is probably the best way to go.