Esempio n. 1
0
        private static void MediatorExample()
        {
            Console.WriteLine("Mediator Example:");

            var enemyState        = new EnemyStateFactory();
            var mapWidthAndHeight = 16;
            var mockPosition      = Vector2.Zero;
            var mockMap           = new Map(mapWidthAndHeight, mapWidthAndHeight);
            var mockPlayer        = new Player1 {
                LifePoints = 100
            };
            var mapObjects = new List <IMapObject>
            {
                new EnemyA(null, null, mockPlayer, 100, mockPosition, null, enemyState.GetState("Moving"), mockMap),
                new EnemyB(null, null, mockPlayer, 100, mockPosition, null, enemyState.GetState("Moving"), mockMap),
                new EnemyA(null, null, mockPlayer, 100, mockPosition, null, enemyState.GetState("Moving"), mockMap),
                new EnemyB(null, null, mockPlayer, 100, mockPosition, null, enemyState.GetState("Moving"), mockMap),
                new EnemyA(null, null, mockPlayer, 100, mockPosition, null, enemyState.GetState("Moving"), mockMap),
                mockPlayer,
                new Wall()
            };

            foreach (var mapObject in mapObjects)
            {
                mockMap.AddMapObject(mapObject);
            }

            var newEnemy = new EnemyA(null, null, mockPlayer, 100, mockPosition, null, enemyState.GetState("Moving"), mockMap);

            Logger.Instance.Info("All enemies received a message that an enemy spawned, so their base damages increase");
        }
Esempio n. 2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _weaponTextures = new Dictionary <string, Texture2D>();
            _spriteBatch    = new SpriteBatch(GraphicsDevice);
            // TODO: use this.Content to load your game content here
            _backgroundTexture = Content.Load <Texture2D>("background");
            _playerTexture     = Content.Load <Texture2D>("player");
            _enemyATexture     = Content.Load <Texture2D>("enemyA");
            _enemyBTexture     = Content.Load <Texture2D>("enemyB");
            _bossTexture       = Content.Load <Texture2D>("boss");

            foreach (var weapon in Enum.GetValues(typeof(WeaponName)))
            {
                _weaponTextures.Add(weapon.ToString(), Content.Load <Texture2D>(weapon.ToString()));
            }

            _wallTexture = Content.Load <Texture2D>("wall");

            _player = new Player1(Vector2.Zero, _playerTexture);
            _map    = new Map(GameSettings.MapSize, GameSettings.MapSize)
            {
                BackgroundTexture = _backgroundTexture
            };
            _map.AddMapObject(_player);
            _pathFinder = new PathFindingAdapter(_map);

            var enemyState = new EnemyStateFactory();

            var enemiesFactory = new EnemiesConcreteFactory();

            _enemies = new List <Enemy>
            {
                enemiesFactory.CreateEnemy(_pathFinder, EnemyType.Small, new Bazooka(), _player, 100, new Vector2(5 * GameSettings.TileSize, 5 * GameSettings.TileSize), _enemyATexture, enemyState.GetState("Moving"), _map),
                enemiesFactory.CreateEnemy(_pathFinder, EnemyType.Big, new Pistol(), _player, 100, new Vector2(3 * GameSettings.TileSize, 5 * GameSettings.TileSize), _enemyBTexture, enemyState.GetState("Moving"), _map),
                enemiesFactory.CreateEnemy(_pathFinder, EnemyType.Boss, new Pistol(), _player, 500, new Vector2(1 * GameSettings.TileSize, 1 * GameSettings.TileSize), _bossTexture, enemyState.GetState("Moving"), _map),
                enemiesFactory.CreateEnemy(_pathFinder, EnemyType.Boss, new Pistol(), _player, 250, new Vector2(1 * GameSettings.TileSize, 2 * GameSettings.TileSize), _bossTexture, enemyState.GetState("Moving"), _map)
            };

            Boss boss = (Boss)_enemies[2];

            boss.AddMinion(_enemies[0]);
            boss.AddMinion(_enemies[1]);
            boss.AddMinion(_enemies[3]);

            foreach (Enemy minion in boss.GetMinions())
            {
                _map.AddMapObject(minion);
            }

            var clonedEnemies = new List <Enemy>
            {
                _enemies[0].DeepCopy(),
                _enemies[0].DeepCopy(),
                _enemies[1].DeepCopy(),
                _enemies[1].DeepCopy()
            };

            clonedEnemies[0].Position = new Vector2(7 * GameSettings.TileSize, 5 * GameSettings.TileSize);
            clonedEnemies[1].Position = new Vector2(5 * GameSettings.TileSize, 9 * GameSettings.TileSize);
            clonedEnemies[2].Position = new Vector2(2 * GameSettings.TileSize, 4 * GameSettings.TileSize);
            clonedEnemies[3].Position = new Vector2(5 * GameSettings.TileSize, 1 * GameSettings.TileSize);

            _enemies.Add(clonedEnemies[0]);
            _enemies.Add(clonedEnemies[1]);
            _enemies.Add(clonedEnemies[2]);
            _enemies.Add(clonedEnemies[3]);

            Boss boss2 = (Boss)_enemies[3];

            boss2.AddMinion(_enemies[4]);

            _walls = new List <Wall>
            {
                new Wall {
                    Position = new Vector2(10 * GameSettings.TileSize, 10 * GameSettings.TileSize), Texture = _wallTexture
                },
                new Wall {
                    Position = new Vector2(11 * GameSettings.TileSize, 10 * GameSettings.TileSize), Texture = _wallTexture
                },
                new Wall {
                    Position = new Vector2(12 * GameSettings.TileSize, 10 * GameSettings.TileSize), Texture = _wallTexture
                },
                new Wall {
                    Position = new Vector2(13 * GameSettings.TileSize, 10 * GameSettings.TileSize), Texture = _wallTexture
                },
                new Wall {
                    Position = new Vector2(14 * GameSettings.TileSize, 10 * GameSettings.TileSize), Texture = _wallTexture
                },
                new Wall {
                    Position = new Vector2(15 * GameSettings.TileSize, 10 * GameSettings.TileSize), Texture = _wallTexture
                }
            };
            _weapons = new List <Weapon>();

            foreach (var enemy in _enemies)
            {
                _map.AddMapObject(enemy);
            }
            foreach (var wall in _walls)
            {
                _map.AddMapObject(wall);
            }
            foreach (var weapon in _weapons)
            {
                _map.AddMapObject(weapon);
            }
        }