Skip to content
Codewilds

Lesson 29 of 34 · Inheritance & Interfaces

Boss: Morwen the Mirror Witch

Boss battlehard100 XP1 min read

Morwen the Mirror Witch blocks the way. Every test you pass deals damage — pass them all to defeat it and claim a loot chest.

The final hall of the west wing is lined with mirrors, and in every one of them stands Morwen the Mirror Witch. Each reflection fights in a different style — one hides behind steel, one strikes from afar, one mends the others' wounds. Only a commander who understands every kind of fighter through one common language can shatter the glass.

Battle plan

Unit is the abstract base class of every fighter. It is complete — read it carefully:

  • Health can only be changed through TakeDamage (virtual) and Restore (heals the living, never above MaxHealth);
  • Power is abstract: every kind of unit decides how hard it hits;
  • Attack(target) deals Power damage to the target through the target's own TakeDamage — so a knight's armour works no matter who attacks it.

Two interfaces describe extra capabilities: IArmored (has an Armor value) and IHealer (can Heal another unit). The Arena helpers must work with any mix of units, using only Unit and the interfaces — never by checking for concrete classes.

Assignment

  1. Knight (120 max health, power 15) is IArmored with armor 4. It overrides TakeDamage: every hit is reduced by the armor, but always does at least 1 damage.
  2. Archer (70 max health) has power 18 and no special rules.
  3. Cleric (80 max health, power 5) is an IHealer: Heal(target) restores 20 health to the target. Its Describe() adds " (healer)" to the base description.
  4. Arena.TotalPower(units) adds up the power of the living units.
  5. Arena.Volley(attackers, target) lets every living attacker attack the target once.
  6. Arena.HealParty(party) — every living healer heals the living unit with the lowest health (the first one on a tie). Return how many heals were cast.
  7. Arena.Survivors(units) returns the names of the living units, in order.

Premium lesson

Unlock the full Learn C# course

  • All 34 lessons, bosses and quizzes — lifetime access
  • One payment of $35, no subscription
  • Finish within 30 days and claim $10.50 (30%) back
Play the 8 free lessons

Want more than one course?

The All-Access Pass unlocks all 8 courses and every new one we release, for $120 once.

Keep learning

Need a quick reminder? The C# cheat sheet has every topic of Learn C# on one page.

Lesson last updated on .

Write code ↓
C#+100 XP

Lesson 29 is part of the full course. The first 8 lessons are free.

Premium lesson

Unlock the full Learn C# course

  • All 34 lessons, bosses and quizzes — lifetime access
  • One payment of $35, no subscription
  • Finish within 30 days and claim $10.50 (30%) back
Play the 8 free lessons

Want more than one course?

The All-Access Pass unlocks all 8 courses and every new one we release, for $120 once.