Access Modifier

Let's create another type of Invader, name it with StrongInvader class, the invader who has higher health.

Just create like FastInvader class.

class StrongInvader : Invader
{
    public override int Health { get; private set; } = 2;

    public StrongInvader(Path path) : base(path)
    { }

}

It has an error.

The error is no suitable method found to override. Unlike previous stepSize, our Health properties has private setter. It means we cann't access it from StrongInvader.

The key is protected.


We already created many types of Invader. It's unfair right? Now, let's modify our Tower class.

In tower class, we have range, power, and accuracy attributes. Like before, we have to make it virtual and set the constructor in it.

protected virtual int Range { get; } = 1;
protected virtual int Power { get; } = 1;
protected virtual double Accuracy { get; } = 0.75;

Don't forget to change other variables.

You have learn how to do it. Now, create 3 types of tower with long range, more power and higher accuracy.

results matching ""

    No results matching ""