Пример #1
0
  /** It enables only the pits from the player whose turn it is */
  void enableActiveSide() {
    boolean enableNorth;
    boolean enableSouth;

    if (usersSide == null) { // sideTheUserIs is not yet initialized
      enableNorth = false;
      enableSouth = false;
    } else if (state.getWhoseTurn().isNorth() && usersSide.isNorth()) {
      enableNorth = true;
      enableSouth = false;
    } else if (state.getWhoseTurn().isNorth() && usersSide.isSouth()) {
      enableNorth = false;
      enableSouth = false;
    } else if (state.getWhoseTurn().isSouth() && usersSide.isSouth()) {
      enableNorth = false;
      enableSouth = true;
    } else {
      enableNorth = false;
      enableSouth = false;
    }

    for (int i = 0; i < state.getNorthPits().length - 1; i++) {
      graphics.setPitEnabled(PlayerColor.N, i, enableNorth);
      graphics.setPitEnabled(PlayerColor.S, i, enableSouth);
    }
  }
Пример #2
0
  /**
   * After the user clicked on a pit the seeds should be distributed in an animated fashion
   *
   * @param chosenPitIndex the index the user chose to distribute the seeds from
   * @param oldState the state before the user chose his pit
   */
  void makeAnimatedMove(int chosenPitIndex, State oldState) {

    // disable board until the animation is over
    disableBoard();
    state.makeMove(chosenPitIndex);

    PlayerColor whoseTurn = oldState.getWhoseTurn();
    PlayerColor sideToPlaceSeedOn = whoseTurn;
    int seedAmount = oldState.getPitsOfWhoseTurn()[chosenPitIndex];
    boolean lastAnimation = false;
    int indexToPlaceSeedIn = chosenPitIndex;
    int maxIndex = 6;
    for (int i = 1; i <= seedAmount; i++) {
      indexToPlaceSeedIn++;
      maxIndex = whoseTurn.equals(sideToPlaceSeedOn) ? 6 : 5;
      if ((indexToPlaceSeedIn) > maxIndex) {
        sideToPlaceSeedOn = sideToPlaceSeedOn.getOpposite();
        indexToPlaceSeedIn = 0;
      }
      if (i == seedAmount) lastAnimation = true;
      graphics.animateFromPitToPit(
          whoseTurn,
          chosenPitIndex,
          sideToPlaceSeedOn,
          indexToPlaceSeedIn,
          400 * (i - 1),
          lastAnimation);
    }

    if (this.state.getLastMoveWasOppositeCapture()) {
      // graphics.oppositeCaptureSound();

      // TODO: give this it's own animation

      // //int[] opposingPits = whoseTurn.isNorth() ?
      // this.state.getSouthPits() : state.getNorthPits();
      // int seedAmountInOpposingPit = this.state.getOppositeSeeds();
      //
      // graphics.animateFromPitToPit(whoseTurn, indexToPlaceSeedIn,
      // whoseTurn, 6, seedAmount * 400 + 1400);
      // for(int i = 0; i < seedAmountInOpposingPit; i++)
      // graphics.animateFromPitToPit(whoseTurn.getOpposite(),
      // State.getMirrorIndex(indexToPlaceSeedIn, 5), whoseTurn, 6,
      // seedAmount * 400 + 1000 + 400 * i);
    }
  }
Пример #3
0
  /**
   * A player can only select certain pits for their move. That's why some have to be enabled and
   * some have to be disabled before a player's turn.
   */
  @Override
  public void setPitEnabled(PlayerColor side, int col, boolean enabled) {
    AbsolutePanel pnl;
    if (col < 6) {
      if (side.isNorth()) {
        pnl = (AbsolutePanel) gameGrid.getWidget(0, State.getMirrorIndex(col, 5));
      } else if (side.isSouth()) {
        pnl = (AbsolutePanel) gameGrid.getWidget(1, col);
      } else throw new IllegalMoveException();

      final int colB = col;
      int row = side.isNorth() ? 0 : 1;

      if (enabled) {
        // the handerRegs keeps track of all click handlers of the pits
        // by removing it from this array the handler is removed from
        // the pit (absolutePanel) as well
        handlerRegs[row][col].removeHandler();
        handlerRegs[row][col] =
            pnl.addDomHandler(
                new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent event) {
                    presenter.makeMove(colB);
                  }
                },
                ClickEvent.getType());
      } else {
        handlerRegs[row][col].removeHandler();
        handlerRegs[row][col] =
            pnl.addDomHandler(
                new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent event) {
                    setWarnLabelText(messages.warnMessage());
                  }
                },
                ClickEvent.getType());
      }
    }
  }
Пример #4
0
  /** The seedAmount will be placed on the right side at the correct index */
  @Override
  public void setSeeds(PlayerColor side, int col, int seedAmount) {
    if (col < 6) {
      AbsolutePanel pnl;
      if (side.isNorth()) {
        pnl = (AbsolutePanel) gameGrid.getWidget(0, State.getMirrorIndex(col, 5));
      } else if (side.isSouth()) {
        pnl = (AbsolutePanel) gameGrid.getWidget(1, col);
      } else throw new IllegalMoveException();

      addSeeds(pnl, seedAmount);
    } else if (col == 6) {
      AbsolutePanel pnl;
      if (side.isNorth()) {
        pnl = (AbsolutePanel) treasureGridN.getWidget(0, 0);
      } else if (side.isSouth()) {
        pnl = (AbsolutePanel) treasureGridS.getWidget(0, 0);
      } else throw new IllegalMoveException();
      addSeedsToTreasureChest(pnl, seedAmount);
    } else throw new IllegalMoveException();
  }
Пример #5
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);
  }