public void testGiveCommand() { Scenario scenario = new Scenario(20, 20); Controller controller = new Controller(scenario); Unit unit = new Unit(scenario.getPlayer(), 200); controller.addUnit(unit, 10f, 10f); // Create a MoveAction MoveAction action = new MoveAction(8f, 8f, scenario.getGameWorld(), unit); // Test if the ActionController returns true when it gives the command. Assert.IsTrue(controller.giveActionCommand(unit, action)); // Test if the MoveAction is actually on the unit's action queue. Assert.IsTrue(unit.getActionQueue()[0] == action); // Create a second MoveAction MoveAction action2 = new MoveAction(7f, 7f, scenario.getGameWorld(), unit); // Test if the ActionController interrupts the current MoveAction and replaces it with the new one. Assert.IsTrue(controller.giveActionCommand(unit, action2)); Assert.IsTrue(unit.getActionQueue()[0] == action2); Assert.IsFalse(unit.getActionQueue().Contains(action)); }
public void testInsertCommand() { Scenario scenario = new Scenario(20, 20); Controller controller = new Controller(scenario); Unit unit = new Unit(scenario.getPlayer(), 200); controller.addUnit(unit, 10f, 10f); // Create a MoveAction MoveAction action = new MoveAction(8f, 8f, scenario.getGameWorld(), unit); // Test if the ActionController returns true when it gives the command. Assert.IsTrue(controller.giveActionCommand(unit, action)); // Test if the MoveAction is actually on the unit's action queue. Assert.IsTrue(unit.getActionQueue()[0] == action); // Create a second MoveAction MoveAction action2 = new MoveAction(7f, 7f, scenario.getGameWorld(), unit); // Insert the second MoveAction to the beginning of the units action queue. ActionController.insertIntoActionQueue(unit, action2); Assert.IsTrue(unit.getActionQueue()[0] == action2); Assert.IsTrue(unit.getActionQueue()[1] == action); }
/// <summary> /// This method will process an AttackEvent that the unit observed and will determine how the unit should "react" to it. /// </summary> /// <param name="unit"></param> /// <param name="gameEvent"></param> /// <param name="gw"></param> private static void handleAttackEventUnit(Unit unit, GameEvent gameEvent, GameWorld gw) { // Check if unit is in the Passive AttackStance. if (unit.getAttackStance() == Unit.AttackStance.Passive) { // Ignore the AttackEvent. return; } // If an ally Entity is being attacked. if (gameEvent.targetEntity.getOwner() == unit.getOwner() && unit.getOwner().isEnemy(gameEvent.sourceEntity.getOwner())) { // If the unit is not performing any action. if (unit.getActionQueue().Count == 0) { // Attack the sourceEnemy } } }