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# C# Objects Loops and Final Touches Putting It All Together

getting several runtime errors when i try to run

when i try to run its give me error:

Level.cs(32,26): error CS1061: Type `TreehouseDefense.Invader' does not contain a definition for `IsActive' and no extension method `IsActive' of type `TreehouseDefense.Invader' could be found. Are you missing an assembly reference?       
Invader.cs(3,9): (Location of the symbol related to previous error)                                                                                                                                                                            
MapLocation.cs(15,18): error CS1501: No overload for method `DistanceTo' takes `1' arguments                                                                                                                                                   
Point.cs(16,19): (Location of the symbol related to previous error)                                                                                                                                                                            
Tower.cs(18,29): error CS1061: Type `TreehouseDefense.Invader' does not contain a definition for `IsActive' and no extension method `IsActive' of type `TreehouseDefense.Invader' could be found. Are you missing an assembly reference?       
Invader.cs(3,9): (Location of the symbol related to previous error)                                                                                                                                                                            
Compilation failed: 4 error(s), 1 warnings  

i dont fine IsActive? what is mean:"No overload for method DistanceTo' takes1' arguments "??

this is for the Level:

Level.cs
namespace TreehouseDefense
{
   class Level
   {
     private readonly Invader[] _invaders;
     public Tower[] Towers{get;set;}

     public Level(Invader[] invaders)
     {
       _invaders = invaders;
     }
     // return true if the player wins, false otherwise.
     public bool Play()
     {
       // run untill all invaders are neutralized or an invader reaches the end of the path.

         int remainingInvaders = _invaders.Length;

         while (remainingInvaders > 0)
         {
         // each tower has opportunity to fire on invaders.
           foreach(Tower tower in Towers)
           {
            tower.FireOnInvaders(_invaders);
           }

         // count and move the invaders that are still active.
           remainingInvaders = 0;

           foreach(Invader invader in _invaders)
           {
             if (invader.IsActive)
             {
               invader.Move();
               if (invader.HasScored)
               {
                 return false;
               }
               remainingInvaders++;
             }
           }

this is for Maplocation:

MapLocation.cs
namespace TreehouseDefense
{
    class MapLocation : Point
    {
        public MapLocation(int x, int y,Map map) : base (x,y)
        {
            if (!map.OnMap(this))
            {
              throw new OutOfBoundsException(X + "," + Y + "is outside the boundaries of the map." );
            }
        }

        public bool InRangeOf(MapLocation location, int range)
        {
          return DistanceTo(location) <= range;
        }
    }
}

this is for tower:

Tower.cs
namespace TreehouseDefense
{
  class Tower
  {
        private  const int _range = 1; 
        private  const int _power = 1;  

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

        public void FireOnInvaders(Invader[] invaders)
        { 
              foreach (Invader  invader in invaders)
              {
                if (invader.IsActive && _location.InRangeOf(invader.Location, _range))
                {
                  invader.DecreaseHealth(_power);
                  break;
                }
              }
        }
  }
}

fixed code formatting

There is no DistanceTo(value) method in your code... Either it is missing or you did not post it

Steven Parker
Steven Parker
231,269 Points

Tobias makes a good point, and more importantly there is also no definition for IsActive.

To be sure you are sharing all the project code, you can use the snapshot function in the workspace and provide the link to that.

It looks like you're missing the definition of IsActive from the Invader class and you're missing the 1 argument version of the DistanceTo() method from the Point class.

You can either post a snapshot of your workspace as Steven has suggested or post Invader.cs and Point.cs

Your problems seem to be in those 2 files.

1 Answer

Jason Anello is correct you are missing the method IsActive() from Invader class

public bool IsActive => !(IsNeutralized || HasScored);