Esempio n. 1
0
  /** makes a move on the model, adds the new state to the history and updates the board */
  void makeMove(int index) {
    try {
      lastMove = index;
      if (aiMatch) {
        stateToSetAfterAnimation = state.copyState();
        stateToSetAfterAnimation.makeMove(index);
        makeAnimatedMove(index, state.copyState());
      } else {
        State stateCopy = state.copyState();
        stateCopy.makeMove(index);
        sendMoveToServer(index, State.serialize(stateCopy));
      }
      // State oldState = state.copyState();
      //
      // stateToSetAfterAnimation = state.copyState();
      // stateToSetAfterAnimation.makeMove(index);

      // state.makeMove(index);

      // sendMoveToServer() is called by the graphics class after the animation is done
      // makeAnimatedMove(index, oldState);

    } catch (IllegalMoveException e) {
      graphics.setMessage(messages.newGameBecauseError() + e);
      setState(new State());
    } catch (GameOverException e) {
      graphics.setMessage(messages.newGameBecauseError() + e);
      setState(new State());
    }
  }
Esempio n. 2
0
 private void showPlayGameElements(ContactInfo contact) {
   startGameLabel.setVisible(true);
   startGameButton.setVisible(true);
   cancelStartGameButton.setVisible(true);
   if (contact.getTurn().equals(""))
     startGameLabel.setText(messages.startGameQuestion(contact.getName()));
   else startGameLabel.setText(messages.continueGameQuestion(contact.getName()));
 }
Esempio n. 3
0
  /**
   * Updates all elements that are necessary after the state changed 1. Update all the seedAmounts
   * in the pits after a move was made 2. It enables only the pits from the player whose turn it is
   * 3. When there are zero seeds in a pit it can't be chosen either so disable them 4. Set a
   * message in the case of game over
   */
  void updateBoard() {

    if (usersSide == null) graphics.setTurnLabelText(messages.startNewGame());
    else {
      graphics.setTurnLabelText(
          state.getWhoseTurn().equals(usersSide)
              ? messages.itsYourTurn()
              : messages.opponentsTurn());
    }
    updatePits();
    enableActiveSide();
    disableZeroSeedPits();
    message();
  }
Esempio n. 4
0
  /** Set a message in the case of game over */
  void message() {
    if (state.isGameOver()) {

      graphics.gameOverSound();
      String msg = "";
      if (state.winner() == null) {
        msg = messages.tie();
      } else {
        String winner = state.winner().isNorth() ? "North" : "South";
        msg = messages.winnerIs(winner, state.score() + "");
      }
      graphics.setMessage(msg);
      publish(msg);
    }
  }
Esempio n. 5
0
 @Override
 public void setAiMovesLabelTextTriggerAiMove(String text, Graphics graphicsForAnim) {
   aiMovesLabel.setText(messages.aiMakesMove());
   aiMovesLabel.getElement().getStyle().setOpacity(1);
   aiAdditionalMoveAnimation =
       new AIAdditionalMoveAnimation(aiMovesLabel.getElement(), graphicsForAnim);
   aiAdditionalMoveAnimation.fade(2000, 0, 1000);
 }
Esempio n. 6
0
 private void initializeUILanguage() {
   aiIsNorthButton.setText(messages.GameAiSouth());
   aiIsSouthButton.setText(messages.GameAiNorth());
   startGameButton.setText(messages.play());
   cancelStartGameButton.setText(messages.cancel());
 }
Esempio n. 7
0
 @Override
 public void onFailure(Throwable caught) {
   Window.alert(messages.loadMatchError());
 }