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); }
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); }
public UnitTakesDamagePostEvent(Unit source, Unit target, int dmg, int actualDmg) { this.source = source; this.target = target; this.dmg = dmg; this.actualDmg = actualDmg; }
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)); }
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); }
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)); }
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)); }
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); }
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); }
public void CanContain_emptyTerrain_Returnstrue() { Unit a = new Unit(); Tile t = new Tile(); Assert.IsTrue(t.CanContain(a)); }
public UnitTakesDamagePreEvent(Unit source, Unit target, int dmg) { this.source = source; this.target = target; this.dmg = dmg; }
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); }
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); }
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); }