コード例 #1
0
  @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.
      }
    }
  }