Index out of Range
Because we set private to our path variable, so no class can access it. But, other classes still need to get some information about the path.
For example, as an invader comes down the path we need to know where on the map it is moved to so that we can determine if it's in range of a tower or not. Let's add the method in Path class called getLocationAt().
public MapLocation getLocationAt(int pathStep)
{
return _path[pathStep];
}
How if the path is null? we need conditional statement.
public MapLocation getLocationAt(int pathStep)
{
if (pathStep < _path.Length)
return _path[pathStep];
else
return null;
}
There is syntatic sugar for if called ternary if.
return name == "Sam" ? 100 : -1;