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

C#

Evan Welch
Evan Welch
1,815 Points

How is the dot operator _location.InRangeOf being used here for the tower's location?

I understand that the invader's location is being called with invader.Location. What is tripping me up is that we're using _location.InRangeOf when InRangeOf is not even a method in the same class.

This is the more complete context.

namespace TreehouseDefense
{
   class Tower
   {
       private readonly MapLocation _location;

       public Tower(MapLocation location)
       {
         _location = location;
       }

       public void FireOnInvaders(Invader[] invaders)
       {
         foreach(Invader invader in invaders)
         {
            if(_location.InRangeOf(invader.Location, 1))
            {
                invader.DecreaseHealth(1);
            }
         }
       }
   }

And the InRangeOf method is written in a different file:

        public bool InRangeOf(MApLocation location, int range)
        {
            return DistanceTo(location) <+ range;
        }

Thank you!