コード例 #1
0
ファイル: Presenter.java プロジェクト: michajg/mancala-smg
  /** 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());
    }
  }
コード例 #2
0
ファイル: Graphics.java プロジェクト: michajg/mancala-smg
 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()));
 }
コード例 #3
0
ファイル: Presenter.java プロジェクト: michajg/mancala-smg
  /**
   * 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();
  }
コード例 #4
0
ファイル: Presenter.java プロジェクト: michajg/mancala-smg
  /** 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);
    }
  }
コード例 #5
0
ファイル: Graphics.java プロジェクト: michajg/mancala-smg
 @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);
 }
コード例 #6
0
ファイル: Graphics.java プロジェクト: michajg/mancala-smg
 private void initializeUILanguage() {
   aiIsNorthButton.setText(messages.GameAiSouth());
   aiIsSouthButton.setText(messages.GameAiNorth());
   startGameButton.setText(messages.play());
   cancelStartGameButton.setText(messages.cancel());
 }
コード例 #7
0
ファイル: Presenter.java プロジェクト: michajg/mancala-smg
 @Override
 public void onFailure(Throwable caught) {
   Window.alert(messages.loadMatchError());
 }