public void testMapWithUnitMove() { Scenario scenario = new Scenario(20, 20); Controller controller = new Controller(scenario); Unit unit = new Unit(scenario.getPlayer(), new UnitStats()); controller.addUnit(unit, 6, 6); MoveAction move = new MoveAction(10, 10, scenario.getGameWorld(), unit); controller.giveActionCommand(unit, move); // Update the world so that the unit moves. for (int i = 0; i < 1000; i++) { controller.updateWorld(); } // Test that all of the cells within the units visibility range have been explored. for (int i = (int)unit.x - (int)unit.stats.visibilityRange; i < (int)unit.x + (int)unit.stats.visibilityRange; i++) { for (int j = (int)unit.y - (int)unit.stats.visibilityRange; j < (int)unit.y + (int)unit.stats.visibilityRange; j++) { Assert.IsTrue(scenario.getGameWorld().map.getCell(i, j).explored); } } }
public void testMove() { 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); controller.giveActionCommand(unit, action); Assert.AreEqual(scenario.getGameWorld().map.getCell(10, 10), unit.getCell()); // Run 1000 cycles of the game for (int i = 0; i < 1000; i++) { controller.updateWorld(); } // Test if the unit has ended up in the target cell. Assert.AreEqual(scenario.getGameWorld().map.getCell(8, 8), unit.getCell()); }