Пример #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();
        }
Пример #2
0
        private static void VisitorExample()
        {
            Logger.Instance.Info("Running Visitor Example");

            var mockPosition   = Vector2.Zero;
            var mockMap        = new Map(16, 16);
            var mockPathFinder = new PathFindingAdapter(mockMap);
            var player1        = new Player1 {
                LifePoints = 100
            };
            var pistol     = new Pistol();
            var enemyState = new EnemyStateFactory();

            Boss boss1 = new Boss(mockPathFinder, pistol, player1, 500, mockPosition, null, enemyState.GetState("Moving"), mockMap);
            Boss boss2 = new Boss(mockPathFinder, pistol, player1, 200, mockPosition, null, enemyState.GetState("Moving"), mockMap);

            EnemiesFactory enemiesFactory = new EnemiesConcreteFactory();
            var            enemyA1        = enemiesFactory.CreateEnemy(mockPathFinder, EnemyType.Small, pistol, player1, 50, mockPosition,
                                                                       null, enemyState.GetState("Moving"), mockMap);
            var enemyB1 =
                enemiesFactory.CreateEnemy(mockPathFinder, EnemyType.Big, pistol, player1, 75, mockPosition, null, enemyState.GetState("Moving"), mockMap);
            var enemyA2 = enemiesFactory.CreateEnemy(mockPathFinder, EnemyType.Small, pistol, player1, 25, mockPosition,
                                                     null, enemyState.GetState("Moving"), mockMap);
            var enemyB2 =
                enemiesFactory.CreateEnemy(mockPathFinder, EnemyType.Big, pistol, player1, 50, mockPosition, null, enemyState.GetState("Moving"), mockMap);

            boss1.AddMinion(enemyA1);
            boss1.AddMinion(boss2);
            boss1.AddMinion(enemyB1);

            boss2.AddMinion(enemyA2);
            boss2.AddMinion(enemyB2);

            boss1.Accept(new EnemyVisitor());
        }
Пример #3
0
 public MainHero(Texture2D Texture, Vector2 StartPos)
 {
     keyboardState = keyboardStatePast = new KeyboardState();
     width         = 57;
     height        = 57;
     position      = StartPos;
     texture       = Texture;
     speed         = 10f;
     health        = 5000;
     //rectangle = new Rectangle((int)StartPos.X, (int)StartPos.Y, Width, Height);
     rectangle = new RectangleV3(StartPos, width, height);
     guns      = new Weapon[4];
     guns[0]   = new Pistol();
     //guns[0].isEnemy = false;
     guns[1] = new Blaster();
     // guns[1].isEnemy = false;
     guns[2] = new Lightsaber();
     // guns[2].isEnemy = false;
     guns[3] = new Rocket();
     //  guns[3].isEnemy = false;
     //guns[1] = new Blaster();
     //guns[2] = new Lightsaber();
     abilities = new List <Ability>();
     //abilities.Add(new Standart(this));
 }
Пример #4
0
 public Player()
 {
     position      = new Vector2(100, 200);
     texture       = Assets.Player;
     weaponList[0] = new Pistol();
     weaponList[1] = new Uzi();
     weaponList[2] = new Shotgun();
     weaponList[3] = new Sniper();
     weaponList[4] = new RocketLauncher();
     uiFont        = Assets.UIFont;
     weapon        = weaponList[0];
 }
Пример #5
0
        private static void CompositeExample()
        {
            Logger.Instance.Info("Running Composite Example");
            var mockPosition   = Vector2.Zero;
            var mockMap        = new Map(16, 16);
            var mockPathFinder = new PathFindingAdapter(mockMap);
            var player1        = new Player1 {
                LifePoints = 100
            };
            var pistol     = new Pistol();
            var enemyState = new EnemyStateFactory();

            var boss1 = new Boss(mockPathFinder, pistol, player1, 500, mockPosition, null, enemyState.GetState("Moving"), mockMap);
            var boss2 = new Boss(mockPathFinder, pistol, player1, 200, mockPosition, null, enemyState.GetState("Moving"), mockMap);

            EnemiesFactory enemiesFactory = new EnemiesConcreteFactory();
            var            enemyA1        = enemiesFactory.CreateEnemy(mockPathFinder, EnemyType.Small, pistol, player1, 50, mockPosition,
                                                                       null, enemyState.GetState("Moving"), mockMap);
            var enemyB1 =
                enemiesFactory.CreateEnemy(mockPathFinder, EnemyType.Big, pistol, player1, 75, mockPosition, null, enemyState.GetState("Moving"), mockMap);
            var enemyA2 = enemiesFactory.CreateEnemy(mockPathFinder, EnemyType.Small, pistol, player1, 25, mockPosition,
                                                     null, enemyState.GetState("Moving"), mockMap);
            var enemyB2 =
                enemiesFactory.CreateEnemy(mockPathFinder, EnemyType.Big, pistol, player1, 50, mockPosition, null, enemyState.GetState("Moving"), mockMap);

            boss1.AddMinion(enemyA1);
            boss1.AddMinion(boss2);
            boss1.AddMinion(enemyB1);

            boss2.AddMinion(enemyA2);
            boss2.AddMinion(enemyB2);


            Logger.Instance.Info("Boss1 has " + boss1.LifePoints + "HP. His minions:");
            int i = 1;

            foreach (Enemy enemy in boss1.GetMinions())
            {
                Logger.Instance.Info("Minion has " + enemy.LifePoints + "HP, his boss is Boss" + i + ".");
                if (enemy.GetType() == typeof(Boss))
                {
                    i++;
                    Boss temp = (Boss)enemy;
                    Logger.Instance.Info("This minion is boss as well.");
                    foreach (Enemy minion in temp.GetMinions())
                    {
                        Logger.Instance.Info("Minion has " + minion.LifePoints + "HP, his boss is Boss" + i + ".");
                    }
                    i--;
                }
            }
        }
Пример #6
0
        private static void BridgeExample()
        {
            Logger.Instance.Info("Running Bridge Example");

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

            IPlayer player  = new Player1();
            IWeapon bazooka = new Bazooka();
            IWeapon pistol  = new Pistol();

            Enemy enemyAWithBazooka = new EnemyA(mockPathFinder, bazooka, player, 50, mockPosition, null, enemyState.GetState("Moving"), mockMap);
            Enemy enemyBWithPistol  = new EnemyB(mockPathFinder, pistol, player, 50, mockPosition, null, enemyState.GetState("Moving"), mockMap);

            enemyAWithBazooka.Attack();
            enemyBWithPistol.Attack();
        }
Пример #7
0
        private static void PrototypeExample()
        {
            Logger.Instance.Info("Running Prototype Example");
            var mockPosition   = Vector2.Zero;
            var mockMap        = new Map(16, 16);
            var mockPathFinder = new PathFindingAdapter(mockMap);
            var player1        = new Player1 {
                LifePoints = 100
            };
            var pistol     = new Pistol();
            var enemyState = new EnemyStateFactory();

            EnemiesFactory enemiesFactory = new EnemiesConcreteFactory();
            var            enemyA         = enemiesFactory.CreateEnemy(mockPathFinder, EnemyType.Small, pistol, player1, 50, mockPosition,
                                                                       null, enemyState.GetState("Moving"), mockMap);

            Logger.Instance.Info("First enemy has " + enemyA.LifePoints + " life points and his hash code is " +
                                 enemyA.GetHashCode() + " and weapon's hash code is " +
                                 enemyA.GetWeapon().GetHashCode());

            var enemyA1 = enemyA.Clone();

            Logger.Instance.Info("Cloned enemy has " + enemyA1.LifePoints + " life points and his hash code is " +
                                 enemyA1.GetHashCode() + " and weapon's hash code is " +
                                 enemyA1.GetWeapon().GetHashCode());
            var enemyA2 = enemyA.Clone();

            Logger.Instance.Info("Second Cloned enemy has " + enemyA2.LifePoints +
                                 " life points and his hash code is " + enemyA2.GetHashCode() +
                                 " and weapon's hash code is " + enemyA2.GetWeapon().GetHashCode());

            var enemyA3 = enemyA.DeepCopy();

            Logger.Instance.Info("Deep Cloned enemy has " + enemyA3.LifePoints + " life points and his hash code is " +
                                 enemyA3.GetHashCode() + " and weapon's hash code is " +
                                 enemyA3.GetWeapon().GetHashCode());
            var enemyA4 = enemyA.DeepCopy();

            Logger.Instance.Info("Second Deep Cloned enemy has " + enemyA4.LifePoints +
                                 " life points and his hash code is " + enemyA4.GetHashCode() +
                                 " and weapon's hash code is " + enemyA4.GetWeapon().GetHashCode());
        }
Пример #8
0
        private static void FactoryExample()
        {
            Logger.Instance.Info("Running Factory Example");
            var mockPosition   = Vector2.Zero;
            var mockMap        = new Map(16, 16);
            var mockPathFinder = new PathFindingAdapter(mockMap);
            var player1        = new Player1 {
                LifePoints = 100
            };
            var pistol         = new Pistol();
            var enemiesFactory = new EnemiesConcreteFactory();
            var enemyState     = new EnemyStateFactory();

            var enemyA = enemiesFactory.CreateEnemy(mockPathFinder, EnemyType.Small, pistol, player1, 50, mockPosition,
                                                    null, enemyState.GetState("Moving"), mockMap);

            Logger.Instance.Info("First enemy has " + enemyA.LifePoints + " life points and his type is " +
                                 enemyA.GetType());
            var enemyB =
                enemiesFactory.CreateEnemy(mockPathFinder, EnemyType.Big, pistol, player1, 75, mockPosition, null, enemyState.GetState("Moving"), mockMap);

            Logger.Instance.Info("Second enemy has " + enemyB.LifePoints + " life points and his type is " +
                                 enemyB.GetType());
        }
Пример #9
0
 public override Gun Clone()
 {
     Pistol p = new Pistol();
     SetValues(p);
     return p;
 }