예제 #1
0
  public static File createRandomSaveGame() {
    // start a server
    FreeColServer serv = startServer(false, true);

    // generate a random map
    Controller c = serv.getController();
    assertNotNull(c);
    assertTrue(c instanceof PreGameController);
    PreGameController pgc = (PreGameController) c;
    try {
      pgc.startGame();
    } catch (FreeColException e) {
      fail(e.getMessage());
    }
    assertEquals(FreeColServer.GameState.IN_GAME, serv.getGameState());
    assertNotNull(serv.getGame());
    assertNotNull(serv.getGame().getMap());

    // save the game as a file
    File file = new File(TEST_FILE);
    try {
      serv.saveGame(file, null);
    } catch (IOException e) {
      e.printStackTrace();
      fail(e.toString());
    }
    assertTrue(file.exists());
    stopServer();

    return file;
  }
예제 #2
0
  /**
   * Start a new server game, using a *copy* of a supplied map.
   *
   * @param map The <code>Map</code> to copy.
   * @param spec The <code>Specification</code> to use.
   * @return The new running server game.
   */
  public static Game startServerGame(Map map, Specification spec) {
    stopServerGame();
    FreeColServer serv = startServer(false, true, spec);
    serv.setMapGenerator(new MockMapGenerator(serv.getGame(), map));
    PreGameController pgc = (PreGameController) serv.getController();
    try {
      pgc.startGame();
    } catch (FreeColException e) {
      fail("Failed to start game: " + e.getMessage());
    }

    Game game = serv.getGame();
    FreeColTestCase.setGame(game);
    if (game.getCurrentPlayer() == null) {
      game.setCurrentPlayer(game.getFirstPlayer());
    }
    random = new Random();
    return game;
  }
예제 #3
0
 public static void newTurn() {
   ServerGame game = (ServerGame) server.getGame();
   game.csNewTurn(random, new LogBuilder(0), new ChangeSet());
 }