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 trialDaniel W
1,341 PointsWhy have we scored if pathStep >= _path.Length? Isn't pathStep indexed from 0, while length is not?
We have the code to check if we are at the end of the path:
public bool HasScored { get { return _pathStep >= _path.Length} }
the default on _pathStep is 0. This is the first cell we are on. To win, wouldn't we have to get to the last cell? Which is _path.Length - 1? That is, the length of the array?
3 Answers
Steven Parker
231,248 PointsThe invader wins when he enters the fortress.
You're right that the last path cell index is one less than the length (_path.Length - 1), but on reaching that cell the invader is still on the path. This doesn't indicate a win.
The fortress is one step further than the last path cell. That extra step is needed to win.
Daniel W
1,341 PointsBut if we would like to find out what cell the invader is on after he exceeds the pathStep? Calling GetLocationAt would return null, would it not?
Suban Purushothmakumar
3,306 Pointsyup i also thought the same as Daniel W. Since the getLocationAt method returns null when pathStep >= _path.Length then this should bepossible i guess whilst there are no other constructors for the Path class at this point