using System; using System.Collections; using System.Collections.Generic; namespace D21._1 { public class SpellSequence : IEnumerable { public Spell Spell; public SpellSequence NextEntry; public int Count() => (NextEntry?.Count() ?? 0) + 1; public override int GetHashCode() => HashCode.Combine(Spell, NextEntry); public bool Contains(Spell i) { var cur = this; while (cur != null) { if (i.Equals(cur.Spell)) return true; cur = cur.NextEntry; } return false; } public int Position(Spell i) { var cur = this; int pos = 0; while (cur != null) { if (i.Equals(cur.Spell)) return pos; cur = cur.NextEntry; pos++; } return -1; } public IEnumerator GetEnumerator() { var cur = this; while (cur != null) { yield return cur.Spell; cur = cur.NextEntry; } } IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException(); } public abstract class Spell { public int Cost { get; protected set; } public string Name { get; protected set; } public int? EffectDuration { get; protected set; } public override bool Equals(object obj) => obj is Spell item && Name.Equals(item.Name, StringComparison.OrdinalIgnoreCase); public override int GetHashCode() => HashCode.Combine(Name); public virtual void ActiveEffect(Heroe h, MonsterBoss b) { } public virtual void ApplyEffect(Heroe h, MonsterBoss b) { } public virtual void WornOutEffect(Heroe h, MonsterBoss b) { } } public class MagicMissile : Spell { public MagicMissile() { Name = "Magic Missile"; Cost = 53; } public override void ActiveEffect(Heroe h, MonsterBoss b) => b.HitPoints -= 4; } public class Drain : Spell { public Drain() { Name = "Drain"; Cost = 73; } public override void ActiveEffect(Heroe h, MonsterBoss b) { b.HitPoints -= 2; h.HitPoints += 2; } } public class Shield : Spell { public Shield() { Name = "Shield"; EffectDuration = 6; Cost = 113; } public override void ActiveEffect(Heroe h, MonsterBoss b) => h.Armor += 7; public override void WornOutEffect(Heroe h, MonsterBoss b) => h.Armor -= 7; } public class Poison : Spell { public Poison() { Name = "Poison"; EffectDuration = 6; Cost = 173; } public override void ApplyEffect(Heroe h, MonsterBoss b) => b.HitPoints -= 3; } public class Recharge : Spell { public Recharge() { Name = "Recharge"; EffectDuration = 5; Cost = 229; } public override void ApplyEffect(Heroe h, MonsterBoss b) => h.Mana += 101; } }