예제 #1
0
        private static void Main(string[] args)
        {
            const int enemyHitpoints = 58;
            const int enemyDamage = 9;
            const int wizardHitpoints = 50;
            const int wizardManaPoints = 500;

            var magicMissileSpell = new Spell("MagicMissle", 53, damage: 4);
            var drainSpell = new Spell("Drain", 73, damage: 2, heal: 2);
            var shieldSpell = new Spell("Shield", 113, 6, armor: 7);
            var poisonSpell = new Spell("Poison", 173, 6, damage: 3);
            var rechargeSpell = new Spell("Recharge", 229, 5, manaCharge: 101);

            var spells = new List<Spell> {magicMissileSpell, drainSpell, shieldSpell, poisonSpell, rechargeSpell};

            var startBattleState = new BattleState
            {
                EnemyHitpoints = enemyHitpoints,
                EnemyDamage = enemyDamage,
                WizardHitpoints = wizardHitpoints,
                WizardManaPoints = wizardManaPoints,
                IsHardMode = false,
            };

            Part1(startBattleState, spells);

            startBattleState.IsHardMode = true;
            Part2(startBattleState, spells);
        }
예제 #2
0
 private void CastSpell(Spell spell)
 {
     var spellManaCost = spell.ManaCost;
     TotalSpentMana += spellManaCost;
     WizardManaPoints -= spellManaCost;
     CastedSpells.Add(spell);
     if (spell.Duration == 0)
     {
         ApplySpell(spell);
     }
     else
     {
         ActiveSpells.Add(spell, spell.Duration);
     }
 }
예제 #3
0
 private void ApplySpell(Spell spell)
 {
     EnemyHitpoints -= spell.Damage;
     WizardHitpoints += spell.Heal;
     WizardManaPoints += spell.ManaCharge;
 }
예제 #4
0
        public Result Fight(Spell spell)
        {
            RoundsCount++;
            if (IsHardMode)
            {
                WizardHitpoints--;
            }
            // wizard's turn
            ApplyActiveSpells();
            if (EnemyHitpoints <= 0)
                return Result = Result.Victory;
            CastSpell(spell);
            if (EnemyHitpoints <= 0)
                return Result = Result.Victory;

            // enemy's turn
            ApplyActiveSpells();
            if (EnemyHitpoints <= 0)
                return Result = Result.Victory;
            WizardHitpoints -= EnemyDamage - ActiveSpells.Sum(x => x.Key.Armor);
            if (WizardHitpoints <= 0)
                return (Result = Result.Defeat);
            return Result = Result.Nothing;
        }