Exemple #1
0
        private static void ChainOfResponsibilityExample()
        {
            Console.WriteLine("Chain of Responsibility Example:");
            var          mockPosition       = Vector2.Zero;
            int          mapSize            = 32;
            var          mockMap            = new Map(mapSize, mapSize);
            IPathFinding pathfindingAdapter = new PathFindingAdapter(mockMap);
            var          weapon             = new Shotgun();
            var          mockPlayer         = new Player1 {
                LifePoints = 100
            };
            var enemyState = new EnemyStateFactory();

            var grandparentEnemy = new EnemyA(pathfindingAdapter, weapon, mockPlayer, 100, mockPosition, null, enemyState.GetState("Moving"), mockMap);
            var parentEnemy      = new EnemyB(pathfindingAdapter, weapon, mockPlayer, 100, mockPosition, null, enemyState.GetState("Moving"), mockMap);
            var childEnemy       = new EnemyA(pathfindingAdapter, weapon, mockPlayer, 100, mockPosition, null, enemyState.GetState("Moving"), mockMap);

            parentEnemy.SetParentEnemy(grandparentEnemy);
            childEnemy.SetParentEnemy(parentEnemy);

            Console.WriteLine("Life points before child takes damage:");
            Console.WriteLine($"Grandparent: {grandparentEnemy.LifePoints}");
            Console.WriteLine($"Parent: {parentEnemy.LifePoints}");
            Console.WriteLine($"Child: {childEnemy.LifePoints}");

            childEnemy.TakeDamage(100);

            Console.WriteLine("Life points after child takes damage:");
            Console.WriteLine($"Grandparent: {grandparentEnemy.LifePoints}");
            Console.WriteLine($"Parent: {parentEnemy.LifePoints}");
            Console.WriteLine($"Child: {childEnemy.LifePoints}");
        }
Exemple #2
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];
 }
Exemple #3
0
        private static void StateExample()
        {
            Console.WriteLine("State Example:");
            var          mockPosition       = Vector2.Zero;
            int          mapSize            = 32;
            var          mockMap            = new Map(mapSize, mapSize);
            IPathFinding pathfindingAdapter = new PathFindingAdapter(mockMap);
            var          weapon             = new Shotgun();
            var          mockPlayer         = new Player1 {
                LifePoints = 100
            };
            var enemyState = new EnemyStateFactory();

            var enemy = new EnemyA(pathfindingAdapter, weapon, mockPlayer, 50, mockPosition, null, enemyState.GetState("Moving"), mockMap);

            enemy.DoAction();
            enemy.CurrentState = enemyState.GetState("Shooting");
            enemy.DoAction();
        }