| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace D21._1
- {
- public class SpellSequence : IEnumerable<Spell>
- {
- 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<Spell> 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;
- }
- }
|