Exemplo n.º 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);
    }
  }
Exemplo n.º 2
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();
  }
Exemplo n.º 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());
      }
    }
  }