/** Tests invalid completion of buildable, having enough resources */
  public void testInvalidCompletion() {
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getStandardColony(2);
    Building carpenterHouse = colony.getBuilding(carpenterHouseType);
    assertEquals(
        "Colony should not have lumber mill", carpenterHouse, colony.getBuilding(lumberMillType));
    assertFalse("Colony should not be able to build lumber mill", colony.canBuild(lumberMillType));
    colony.setCurrentlyBuilding(lumberMillType);
    assertEquals(
        "Colony should be building lumber mill", lumberMillType, colony.getCurrentlyBuilding());
    // Add sufficient units and goods to build lumber mill.
    Unit unit = new ServerUnit(game, colony.getTile(), colony.getOwner(), colonistType);
    unit.setLocation(colony);
    for (AbstractGoods ag : lumberMillType.getRequiredGoods()) {
      GoodsType type = ag.getType();
      int amount = ag.getAmount() + 1;
      colony.addGoods(type, amount);
      assertEquals("Wrong quantity of " + type, amount, colony.getGoodsCount(type));
    }

    // Allow the building to finish
    ServerTestHelper.newTurn();

    assertEquals(
        "Colony should have lumber mill",
        lumberMillType,
        colony.getBuilding(lumberMillType).getType());
    assertFalse(
        "Colony should no longer be building lumber mill",
        colony.getCurrentlyBuilding() == lumberMillType);
  }
示例#2
0
  public void setColony(Colony newColony) {
    if (newColony != colony) {
      if (colony != null) {
        colony.removePropertyChangeListener(EVENT, this);
        for (MouseListener listener : getMouseListeners()) {
          removeMouseListener(listener);
        }
      }
      this.colony = newColony;

      // we are interested in changes to the build queue, as well as
      // changes to the warehouse and the colony's production bonus
      colony.addPropertyChangeListener(EVENT, this);

      if (openBuildQueue) {
        addMouseListener(
            new MouseAdapter() {
              public void mousePressed(MouseEvent e) {
                gui.showBuildQueuePanel(colony);
              }
            });
      }
    }
    initialize(colony.getCurrentlyBuilding());
  }
示例#3
0
 public void update() {
   initialize(colony.getCurrentlyBuilding());
 }