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 Magic Numbers and Constants

C# - TreehouseDefense

Can someone please clarify why this code is not working? It's saying that the MapLocation and Invader cannot be found, so if you could please guide me in the right direction, that would be greatly appreciated.

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

    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;
            }
        }
    }
}

}

1 Answer

Steven Parker
Steven Parker
231,275 Points

Did you include all source files in your build?

This project has multiple source files, so you have to name them (or use a wildcard) to include them all when you compile.

A typical build command would be: mcs -out:TreehouseDefense.exe *.cs

The "*.cs" in the command is a wildcard that will include all the source files.