@Test public void testPathFinding() { GameEngine engine = getGameEngine(); for (Obstacle obstacle : obstacles) { engine.addObstacle(obstacle); } for (Unit unit : gameUnits) { engine.addUnit(unit); } // let your engine to start/initialize the game engine.startGame(); tickGame(engine); Collection<Unit> units = engine.getUnits(); for (Unit unit : units) { assert unit.position.distanceTo(spawnPoint) < 5 * 4; } // move all units to other position Point destination = new Point(100 + 490, 100 + 490); for (Unit unit : units) { engine.moveUnitTo(unit.id, destination); } // give them time to go int acceptedTime = 150; for (int i = 0; i < acceptedTime; i++) { tickGame(engine); } // check destination units = engine.getUnits(); for (Unit unit : units) { // assert unit.position.distanceTo(destination) < 5 * 4; } while (true) { try { Thread.sleep(1000l); } catch (InterruptedException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } } }
private void ensureUnitsNotInObstacle(GameEngine engine) { Collection<Unit> units = engine.getUnits(); for (Unit unit : units) { for (Obstacle obstacle : obstacles) { Circle unitSpace = new Circle(unit.position, unit.radius); assert !unitSpace.intersects(obstacle); } } }
private void ensureUnitsDoNotIntersect(GameEngine engine) { Collection<Unit> units = engine.getUnits(); List<Circle> unitSpaces = new ArrayList<>(); for (Unit unit : units) { Circle unitSpace = new Circle(unit.position, unit.radius); for (Circle existingSpace : unitSpaces) { boolean notIntersects = !existingSpace.intersects(unitSpace); assert notIntersects; } unitSpaces.add(unitSpace); } }