Exemplo n.º 1
0
        static void ObserverExample()
        {
            Logger.Instance.Info("Running Observer Example");

            var mockPosition   = Vector2.Zero;
            var mockMap        = new Map(16, 16);
            var mockPathFinder = new PathFindingAdapter(mockMap);
            var enemyState     = new EnemyStateFactory();

            var player1 = new Player1 {
                LifePoints = 100
            };
            var pistol  = new Pistol();
            var enemies = new List <IEnemyObserver>
            {
                new EnemyA(mockPathFinder, pistol, player1, 50, mockPosition, null, enemyState.GetState("Moving"), mockMap),
                new EnemyA(mockPathFinder, pistol, player1, 50, mockPosition, null, enemyState.GetState("Moving"), mockMap),
                new EnemyA(mockPathFinder, pistol, player1, 50, mockPosition, null, enemyState.GetState("Moving"), mockMap)
            };

            foreach (var enemy in enemies)
            {
                player1.AttachObserver(enemy);
            }

            Logger.Instance.Info("Test1:");
            player1.Notify();
            Logger.Instance.Info("Test2:");
            player1.LifePoints = 90;
            player1.DetachObserver(enemies[0]);
            player1.Notify();
        }