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()); }
/// <summary> /// This method will update the pointers to the Cell in the GameWorld that is occuppied by the Unit. /// </summary> /// <param name="unit">The unit who's location is being updated.</param> public void updateUnitLocation(Unit unit) { if (!unit.getCell().contains(unit.x, unit.y)) { Cell newCell = gw.map.getCell((int)Math.Floor(unit.x), (int)Math.Floor(unit.y)); Cell oldCell = unit.getCell(); oldCell.removeUnit(); // NOTE: doesn't check if newCell is already occupied. unit.setCell(newCell); newCell.setUnit(unit); } }
/// <summary> /// This method will update the pointers to the Cell in the GameWorld that is occuppied by the Unit. /// </summary> /// <param name="unit">The unit who's location is being updated.</param> public void updateUnitLocation(Unit unit) { if (!unit.getCell().contains(unit.x, unit.y)) { Cell newCell = gw.map.getCell((int)Math.Floor(unit.x), (int)Math.Floor(unit.y)); Cell oldCell = unit.getCell(); oldCell.removeUnit(); // NOTE: doesn't check if newCell is already occupied. unit.setCell(newCell); newCell.setUnit(unit); // Update the visibility map. this.visMapLogic.updateVisMap(unit); // Update the Cells that the unit is observing. updateCellsUnitIsObserving(unit); // Notify all observers of the cell that a unit has moved onto the cell. newCell.notify(new ZRTSModel.GameEvent.GameEvent(newCell, unit, unit, ZRTSModel.GameEvent.GameEvent.EventType.MoveEvent)); } }