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# Intermediate C# Abstraction Wrap Up

evanpavan
evanpavan
5,025 Points

Can someone help me understand why this method is not being called?

I've added this method to the Resurrecting Invader to print the message to the console. When I run the application the message is never printed even when all the invaders die.

Can someone help me understand why the method may not be being called?

        public void Resurrect()
        {
            if(_incarnation1.IsNeutralized)
            {
                System.Console.WriteLine("The invader came back to life, even stronger!");
            }
        }

The rest of the Resurrecting Invader code is per the same as the lesson

namespace TreehouseDefense
{
    class ResurrectingInvader : IInvader
    {
        private BasicInvader _incarnation1;
        private StrongInvader _incarnation2;

        public MapLocation Location => _incarnation1.IsNeutralized ? _incarnation2.Location : _incarnation1.Location;

        public int Health => _incarnation1.IsNeutralized ? _incarnation2.Health : _incarnation1.Health;

        public bool HasScored => _incarnation1.HasScored || _incarnation2.HasScored;

        public bool IsNeutralized => _incarnation1.IsNeutralized && _incarnation2.IsNeutralized;

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

        public ResurrectingInvader(Path path)
        {
            _incarnation1 = new BasicInvader(path);
            _incarnation2 = new StrongInvader(path);
        }

        public void DecreaseHealth(int factor)
        {
            if(!_incarnation1.IsNeutralized)
            {
                _incarnation1.DecreaseHealth(factor);         
            }
            else
            {
                _incarnation2.DecreaseHealth(factor);
            }
        }
        public void Move()
        {
            _incarnation1.Move();
            _incarnation2.Move();
        }

        public void Resurrect()
        {
            if(_incarnation1.IsNeutralized)
            {
                System.Console.WriteLine("The invader came back to life, even stronger!");
            }
        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,248 Points

You've created a new method, but it doesn't look like you have any code yet to actually call this method.

I'd guess you probably want to call it from inside the "DecreaseHealth" method, after the health level of first incarnation has been changed.