public static T FindSubject <T>() where T : class
        {
            foreach (object subject in Subjects)
            {
                T resultSubject = subject as T;

                if (resultSubject != null)
                {
                    return(resultSubject);
                }
            }

            Type searchingType = typeof(T);

            if (searchingType == typeof(HitEnemySubject))
            {
                HitEnemySubject subject = new HitEnemySubject();
                Subjects.Add(subject);
                return(subject as T);
            }
            else if (searchingType == typeof(KillEnemySubject))
            {
                KillEnemySubject subject = new KillEnemySubject();
                Subjects.Add(subject);
                return(subject as T);
            }
            else
            {
                throw new TypeAccessException("Unsupported subject type");
            }
        }
Ejemplo n.º 2
0
        public void OnEnemyKilled(KillEnemySubject subject)
        {
            if (IsAchieved)
            {
                return;
            }

            Console.WriteLine("Achievement reached: First blood!");
            IsAchieved = true;
        }