Ad
Games

Description

In this kata, you'll be working with a basic RPG (Role-Playing Game) combat engine. The system features turn-based combat between different character types, starting with Dwarves and Goblins.

Core Mechanics

  • Each character has health, defense, and specific attack abilities
  • Damage calculation includes defense reduction and random elements
  • Characters can't have negative health
  • Characters die when health reaches zero
  • Combat is turn-based, with Dwarves attacking first

Character Stats

Dwarf

  • Uses AxeAttack: Base damage (axeSkill) + Random(1-5)
  • Higher base health but slower attacks

Goblin

  • Uses ClawAttack: Base damage (clawStrength) + Random(1-3)
  • Lower base health but faster attacks

Technical Details

The engine provides:

  • Abstract Character class with base health and damage mechanics
  • Dwarf and Goblin classes with specific attack methods
  • CombatManager for handling combat rounds

Your Task

Complete the combat engine by implementing [specific task here]. Your solution should:

  1. Handle damage calculations correctly
  2. Process defense reductions
  3. Manage character death states
  4. Follow turn-based combat rules

Examples

Dwarf dwarf = new Dwarf("Thorin", health: 100, defense: 5, axeSkill: 8);
Goblin goblin = new Goblin("Grunk", health: 50, defense: 2, clawStrength: 6);

// Combat example
CombatManager combat = new CombatManager();
combat.ExecuteCombatRound(dwarf, goblin);

Would you like me to:
1. Add more technical details?
2. Include more code examples?
3. Expand the character stats section?
4. Add difficulty indicators?
5. Create specific challenges or variations?
namespace Solution 
{
    using System;

    public abstract class Character
    {
        public string Name { get; protected set; }
        protected int maxHealth;
        protected int currentHealth;
        protected int defense;
        
        public int CurrentHealth => currentHealth;

        public virtual void TakeDamage(int damage, Character attacker)
        {
            int actualDamage = Math.Max(1, damage - defense);
            currentHealth = Math.Max(0, currentHealth - actualDamage);
            
            if (currentHealth == 0)
            {
                Die();
            }
        }

        public virtual bool IsAlive()
        {
            return currentHealth > 0;
        }

        protected virtual void Die()
        {
            currentHealth = 0;
        }
    }

    public class Dwarf : Character
    {
        private readonly int axeSkill;

        public Dwarf(string name, int health, int defense, int axeSkill)
        {
            Name = name;
            maxHealth = health;
            currentHealth = health;
            this.defense = defense;
            this.axeSkill = axeSkill;
        }

        public int AxeAttack()
        {
            return axeSkill + new Random().Next(1, 6);
        }
    }

    public class Goblin : Character
    {
        private readonly int clawStrength;

        public Goblin(string name, int health, int defense, int clawStrength)
        {
            Name = name;
            maxHealth = health;
            currentHealth = health;
            this.defense = defense;
            this.clawStrength = clawStrength;
        }

        public int ClawAttack()
        {
            return clawStrength + new Random().Next(1, 4);
        }
    }

    public class CombatManager
    {
        public void ExecuteCombatRound(Dwarf dwarf, Goblin goblin)
        {
            if (dwarf.IsAlive())
            {
                int dwarfDamage = dwarf.AxeAttack();
                goblin.TakeDamage(dwarfDamage, dwarf);
            }

            if (goblin.IsAlive())
            {
                int goblinDamage = goblin.ClawAttack();
                dwarf.TakeDamage(goblinDamage, goblin);
            }
        }
    }
}