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());
    }
  }