コード例 #1
0
        public void AddTrigger_triggerIsAddedToUnitAfterItIsAddedToManagger_EventFired()
        {
            EventManager gem = new EventManager();
            ActionManager actman = new ActionManager(gem);

            Unit A = new Unit();
            Unit B = new Unit();

            A.ActionManager = actman;
            B.ActionManager = actman;

            int dmg = int.MaxValue;

            bool eventFired = false;

            Trigger T = new Trigger<UnitTakesDamagePostEvent>(_ => eventFired = true);
            EntityXmasAction ga1 = new DamageUnitTargetAction(B, dmg);

            gem.AddEntity(B);
            B.Register(T);

            A.QueueAction(ga1);
            actman.ExecuteActions();

            Assert.IsTrue(eventFired);
        }
コード例 #2
0
        public void ExecuteActionWithGlobalTrigger_UnitDealsDamageToAnotherUnitWithDamage_EventsWasFiredOnBothActions()
        {
            EventManager gem = new EventManager();
            ActionManager actman = new ActionManager(gem);

            Unit A = new Unit();
            Unit B = new Unit();

            A.ActionManager = actman;
            B.ActionManager = actman;

            int dmg = int.MaxValue;

            int actualTimesFired = 0;

            Trigger T = new Trigger<UnitTakesDamagePostEvent>(_ => actualTimesFired++);
            EntityXmasAction ga1 = new DamageUnitTargetAction(B, dmg);
            EntityXmasAction ga2 = new DamageUnitTargetAction(A, dmg);

            gem.Register(T);
            gem.AddEntity(A);
            gem.AddEntity(B);

            A.QueueAction(ga1);
            B.QueueAction(ga2);
            actman.ExecuteActions();

            int expectedTimeFired = 2;

            Assert.AreEqual(expectedTimeFired, actualTimesFired);
        }
コード例 #3
0
 public UnitTakesDamagePostEvent(Unit source, Unit target, int dmg, int actualDmg)
 {
     this.source = source;
     this.target = target;
     this.dmg = dmg;
     this.actualDmg = actualDmg;
 }
コード例 #4
0
ファイル: TileTest.cs プロジェクト: jannickj/XmasEngine
 public void CanContain_aWall_ReturnsFalse()
 {
     Unit a = new Unit();
     Tile t = new Tile();
     ImpassableWall wall = new ImpassableWall();
     t.AddEntity(wall);
     Assert.IsFalse(t.CanContain(a));
 }
コード例 #5
0
ファイル: TileTest.cs プロジェクト: jannickj/XmasEngine
        public void GetEntities_tileWithAnUnit_ReturnThatAgent()
        {
            Unit a = new Unit();
            Tile t = new Tile();
            t.AddEntity(a);

            Unit expected = a;
            Unit actual = t.Entities.OfType<Unit>().First();
            Assert.AreEqual(expected, actual);
        }
コード例 #6
0
ファイル: TileTest.cs プロジェクト: jannickj/XmasEngine
 public void CanContain_TerrainWithPowerUp_Returnstrue()
 {
     Unit a = new Unit();
     PowerUp p = new PowerUp();
     PowerUp p2 = new PowerUp();
     Tile t = new Tile();
     t.AddEntity(p);
     Assert.IsTrue(t.CanContain(a));
     Assert.IsTrue(t.CanContain(p2));
 }
コード例 #7
0
ファイル: TileTest.cs プロジェクト: jannickj/XmasEngine
 public void CanContain_terrainWithAnUnit_Returnsfalse()
 {
     Unit a = new Unit();
     Unit b = new Unit();
     PowerUp p = new PowerUp();
     Tile t = new Tile();
     t.AddEntity(a);
     Assert.IsFalse(t.CanContain(b));
     Assert.IsTrue(t.CanContain(p));
 }
コード例 #8
0
ファイル: GameWorldTest.cs プロジェクト: jannickj/multipacman
        public void GetEntityPosition_OneAgentInWorld_ReturnThatAgentPosition()
        {
            EventManager evtman = new EventManager();
            TileWorld world = new TileWorld(new Size(2, 2));
            world.EventManager = evtman;

            Agent agent = new Unit();
            world.AddEntity(agent,new TileSpawnInformation(new TilePosition(new Point(1, 2))));

            Point expected = new Point(1, 2);
            Point actual = ((TilePosition) world.GetEntityPosition(agent)).Point;
            Assert.AreEqual(expected, actual);
        }
コード例 #9
0
        public void AddEventToUnit_containMultiTrigger_TheAddedEventGetsFired()
        {
            EventManager gem = new EventManager();

            Unit A = new Unit();

            gem.AddEntity(A);

            bool eventfired = false;

            MultiTrigger mt = new MultiTrigger();

            A.Register(mt);

            mt.AddAction<XmasEvent>(e => eventfired = true);

            mt.RegisterEvent<UnitTakesDamagePostEvent>();

            A.Raise(new UnitTakesDamagePostEvent(null, null, 0, 0));

            Assert.IsTrue(eventfired);
        }
コード例 #10
0
ファイル: TileTest.cs プロジェクト: jannickj/XmasEngine
 public void CanContain_emptyTerrain_Returnstrue()
 {
     Unit a = new Unit();
     Tile t = new Tile();
     Assert.IsTrue(t.CanContain(a));
 }
コード例 #11
0
 public UnitTakesDamagePreEvent(Unit source, Unit target, int dmg)
 {
     this.source = source;
     this.target = target;
     this.dmg = dmg;
 }
コード例 #12
0
        public void RemoveTrigger_triggerIsRemovedFromUnit_NoEventFired()
        {
            EventManager gem = new EventManager();
            ActionManager actman = new ActionManager(gem);

            Unit A = new Unit();
            Unit B = new Unit();

            A.ActionManager = actman;
            B.ActionManager = actman;

            int dmg = int.MaxValue;

            bool eventFired = false;

            Trigger T = new Trigger<UnitTakesDamagePostEvent>(_ => eventFired = true);
            EntityXmasAction ga1 = new DamageUnitTargetAction(B, dmg);

            B.Register(T);
            gem.AddEntity(B);

            B.Deregister(T);

            A.QueueAction(ga1);

            Assert.IsFalse(eventFired);
        }
コード例 #13
0
        public void ExecuteActionWithSpecificTargetEvent_UnitDealsDamageToAnotherUnit_TheOtherUnitTakesDamage()
        {
            EventManager gem = new EventManager();
            ActionManager actman = new ActionManager(gem);

            Unit expectedDealer = new Unit();
            Unit expectedTaker = new Unit();

            expectedDealer.ActionManager = actman;
            expectedTaker.ActionManager = actman;
            int expectedDmg = 10;

            //ignore initialization values
            Unit actualDealer = null;
            Unit actualTaker = null;
            int actualDmg = new int();

            Trigger t = new Trigger<UnitTakesDamagePostEvent>(e =>
                {
                    actualDealer = e.Source;
                    actualTaker = e.Target;
                    actualDmg = e.Damage;
                });
            DamageUnitTargetAction ga = new DamageUnitTargetAction(expectedTaker, expectedDmg);

            expectedTaker.Register(t);
            gem.AddEntity(expectedTaker);

            expectedDealer.QueueAction(ga);
            actman.ExecuteActions();

            Assert.AreEqual(expectedDealer, actualDealer);
            Assert.AreEqual(expectedTaker, actualTaker);
            Assert.AreEqual(expectedDmg, actualDmg);
        }
コード例 #14
0
        public void ExecuteActionWithSpecificTargetEvent_UnitDealsDamageToAnotherUnitWithDamagePrevetionImplemented_TheTargetUnitTakesNoDamage()
        {
            EventManager gem = new EventManager();
            ActionManager actman = new ActionManager(gem);

            Unit expectedDealer = new Unit();
            Unit expectedTaker = new Unit();

            expectedDealer.ActionManager = actman;
            expectedTaker.ActionManager = actman;

            int dmg = 10;
            int prevent = 10;
            int expectedDmg = 10;

            //ignore initialization values
            Unit actualDealer = null;
            Unit actualTaker = null;
            int actualDmg = new int();

            Trigger preT = new Trigger<UnitTakesDamagePreEvent>(e => e.ModDmgPreMultiplier(-prevent));
            Trigger postT = new Trigger<UnitTakesDamagePostEvent>(e =>
                {
                    actualDealer = e.Source;
                    actualTaker = e.Target;
                    actualDmg = e.Damage;
                });
            EntityXmasAction ga = new DamageUnitTargetAction(expectedTaker, dmg);

            expectedTaker.Register(preT);
            expectedTaker.Register(postT);
            gem.AddEntity(expectedTaker);

            expectedDealer.QueueAction(ga);
            actman.ExecuteActions();

            Assert.AreEqual(expectedDealer, actualDealer);
            Assert.AreEqual(expectedTaker, actualTaker);
            Assert.AreEqual(expectedDmg, actualDmg);
        }