fork download
  1. abstract class Buff
  2. {
  3. public abstract void Apply(IBuffTargetable<Buff> target);
  4. public abstract void Unapply();
  5. }
  6. class PlayerBuff : Buff
  7. {
  8. public Player AffectedPlayer { get; private set; }
  9.  
  10. public override void Apply(IBuffTargetable<Buff> target)
  11. {
  12. AffectedPlayer = (Player)target;
  13. }
  14. public override void Unapply()
  15. {
  16. AffectedPlayer = null;
  17. }
  18. }
  19.  
  20. interface IBuffTargetable<T> where T : Buff
  21. {
  22. T[] AppliedBuffs { get; }
  23. void ApplyBuff(T buff);
  24. void UnapplyBuff(T buff);
  25. }
  26.  
  27. class Player : IBuffTargetable<PlayerBuff>
  28. {
  29. private List<PlayerBuff> appliedBuffs;
  30. public PlayerBuff[] AppliedBuffs
  31. {
  32. get { return appliedBuffs.ToArray(); }
  33. }
  34.  
  35. public void ApplyBuff(PlayerBuff buff)
  36. {
  37. buff.Apply((IBuffTargetable<Buff>)this);
  38. appliedBuffs.Add(buff);
  39. }
  40. public void UnapplyBuff(PlayerBuff buff)
  41. {
  42. if (appliedBuffs.Remove(buff))
  43. buff.Unapply();
  44. }
  45.  
  46. private void Awake()
  47. {
  48. appliedBuffs = new List<PlayerBuff>(10);
  49. }
  50. }
  51.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(29,10): error CS0246: The type or namespace name `List' could not be found. Are you missing `System.Collections.Generic' using directive?
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty