Ejemplo n.º 1
0
  /**
   * The treasureChests have their own method to place seeds in
   *
   * @param treasurePanel where the seeds are being placed in
   * @param seedAmount how many seeds are being placed into the pit
   */
  private void addSeedsToTreasureChest(AbsolutePanel treasurePanel, int seedAmount) {
    treasurePanel.clear();

    for (int i = 0; i < seedAmount; i++) {
      final Image seed = new Image();
      seed.setResource(gameImages.redSeed());
      DOM.setStyleAttribute(seed.getElement(), "backgroundSize", "20px 20px");

      int[] point = getTargetPointTreasureChest(i);
      treasurePanel.add(seed, point[0], point[1]);
    }
    Label countLabel = new Label(seedAmount + "");
    countLabel.setWidth(TREASURE_CHEST_WIDTH + "px");
    countLabel.setHorizontalAlignment(Label.ALIGN_CENTER);
    treasurePanel.add(countLabel, 0, 22 * 3);
  }
Ejemplo n.º 2
0
  /** To animate a seed from one pit to another */
  @Override
  public void animateFromPitToPit(
      PlayerColor startSide,
      int startCol,
      PlayerColor endSide,
      int endCol,
      double delay,
      boolean finalAnimation) {
    int startRow = startSide.isNorth() ? 0 : 1;
    int actualStartCol = (startRow == 0) ? 5 - startCol : startCol;
    int endRow = endSide.isNorth() ? 0 : 1;
    int actualEndCol = (endRow == 0) ? 5 - endCol : endCol;

    AbsolutePanel startPanel = (AbsolutePanel) gameGrid.getWidget(startRow, actualStartCol);
    final Image seed;
    seed = (Image) startPanel.getWidget(startPanel.getWidgetCount() - 2);
    int startXStartPanel = startPanel.getWidgetLeft(seed);
    int startYStartPanel = startPanel.getWidgetTop(seed);
    int startX =
        2
            + actualStartCol * 2
            + TREASURE_CHEST_WIDTH
            + PIT_WIDTH * actualStartCol
            + PADDING * (actualStartCol * 2 + 3)
            + startXStartPanel;
    int startY = 2 + PADDING + startRow * (PIT_HEIGHT + 2 * PADDING + 2) + startYStartPanel;

    AbsolutePanel endPanel;
    int[] endPointEndPanel;
    int endXEndPanel;
    int endYEndPanel;
    int endX;
    int endY;
    if (endCol < 6) {
      endPanel = (AbsolutePanel) gameGrid.getWidget(endRow, actualEndCol);
      endPointEndPanel = getTargetPoint(endPanel.getWidgetCount() - 1);
      endXEndPanel = endPointEndPanel[0];
      endYEndPanel = endPointEndPanel[1];
      endX =
          2
              + actualEndCol * 2
              + TREASURE_CHEST_WIDTH
              + PIT_WIDTH * actualEndCol
              + PADDING * (actualEndCol * 2 + 3)
              + endXEndPanel;
      endY = 2 + PADDING + endRow * (PIT_HEIGHT + 2 * PADDING + 2) + endYEndPanel;
    } else {
      Grid hGrid = endRow == 0 ? treasureGridN : treasureGridS;
      endPanel = (AbsolutePanel) hGrid.getWidget(0, 0);
      endPointEndPanel = getTargetPointTreasureChest(endPanel.getWidgetCount() - 1);
      endXEndPanel = endPointEndPanel[0];
      endYEndPanel = endPointEndPanel[1];
      endX =
          2
              + PADDING
              + (TREASURE_CHEST_WIDTH + PIT_WIDTH * 6 + PADDING * 14 + 6 * 2) * endRow
              + endXEndPanel;
      endY = 2 + PADDING + endYEndPanel;
    }

    animation =
        new SeedMovingAnimation(
            seed,
            gameImages.redSeed(),
            startPanel,
            endPanel,
            startXStartPanel,
            startYStartPanel,
            endXEndPanel,
            endYEndPanel,
            startX,
            startY,
            endX,
            endY,
            finalAnimation,
            this,
            dotSound);
    animation.run(1000, Duration.currentTimeMillis() + delay);
  }