Beispiel #1
0
 private void rewindToEndActionPerformed(
     java.awt.event.ActionEvent evt) // GEN-FIRST:event_rewindToEndActionPerformed
     { // GEN-HEADEREND:event_rewindToEndActionPerformed
   try {
     Game activeGame = this.getActiveTabGame();
     if (!activeGame.rewindToEnd()) {
       JOptionPane.showMessageDialog(null, Settings.lang("noMoreUndoMovesInMemory"));
     }
   } catch (ArrayIndexOutOfBoundsException exc) {
     JOptionPane.showMessageDialog(null, Settings.lang("activeTabDoesNotExists"));
   } catch (UnsupportedOperationException exc) {
     JOptionPane.showMessageDialog(null, exc.getMessage());
   }
 } // GEN-LAST:event_rewindToEndActionPerformed
Beispiel #2
0
 private void moveBackItemActionPerformed(
     java.awt.event.ActionEvent evt) // GEN-FIRST:event_moveBackItemActionPerformed
     { // GEN-HEADEREND:event_moveBackItemActionPerformed
   if (getGui() != null && getGui().getGame() != null) {
     getGui().getGame().undo();
   } else {
     try {
       Game activeGame = this.getActiveTabGame();
       if (!activeGame.undo()) {
         JOptionPane.showMessageDialog(null, Settings.lang("noMoreUndoMovesInMemory"));
       }
     } catch (java.lang.ArrayIndexOutOfBoundsException exc) {
       JOptionPane.showMessageDialog(null, Settings.lang("activeTabDoesNotExists"));
     } catch (UnsupportedOperationException exc) {
       JOptionPane.showMessageDialog(null, exc.getMessage());
     }
   }
 } // GEN-LAST:event_moveBackItemActionPerformed
Beispiel #3
0
  public void addMove(
      Square begin,
      Square end,
      boolean registerInHistory,
      Castling castlingMove,
      boolean wasEnPassant,
      Piece promotedPiece) {
    boolean wasCastling = castlingMove != Castling.NONE;
    String locMove = begin.getPiece().getSymbol();

    if (game.getSettings().isUpsideDown()) {
      locMove +=
          Character.toString(
              (char)
                  ((Chessboard.getBottom() - begin.getPozX())
                      + 97)); // add letter of Square from which move was made
      locMove +=
          Integer.toString(begin.getPozY() + 1); // add number of Square from which move was made
    } else {
      locMove +=
          Character.toString(
              (char) (begin.getPozX() + 97)); // add letter of Square from which move was made
      locMove +=
          Integer.toString(8 - begin.getPozY()); // add number of Square from which move was made
    }

    if (end.piece != null) {
      locMove += "x"; // take down opponent piece
    } else {
      locMove += "-"; // normal move
    }

    if (game.getSettings().isUpsideDown()) {
      locMove +=
          Character.toString(
              (char)
                  ((Chessboard.getBottom() - end.getPozX())
                      + 97)); // add letter of Square to which move was made
      locMove += Integer.toString(end.getPozY() + 1); // add number of Square to which move was made
    } else {
      locMove +=
          Character.toString(
              (char) (end.getPozX() + 97)); // add letter of Square to which move was made
      locMove += Integer.toString(8 - end.getPozY()); // add number of Square to which move was made
    }

    if (begin.getPiece().getSymbol().equals("")
        && begin.getPozX() - end.getPozX() != 0
        && end.piece == null) {
      locMove += "(e.p)"; // pawn take down opponent en passant
      wasEnPassant = true;
    }
    if ((!this.enterBlack && this.game.getChessboard().getKingBlack().isChecked())
        || (this.enterBlack
            && this.game.getChessboard().getKingWhite().isChecked())) { // if checked

      if ((!this.enterBlack
              && this.game.getChessboard().getKingBlack().isCheckmatedOrStalemated() == 1)
          || (this.enterBlack
              && this.game.getChessboard().getKingWhite().isCheckmatedOrStalemated()
                  == 1)) { // check if checkmated
        locMove += "#"; // check mate
      } else {
        locMove += "+"; // check
      }
    }
    if (castlingMove != Castling.NONE) {
      this.addCastling(castlingMove.getSymbol());
    } else {
      this.move.add(locMove);
      this.addMove2Table(locMove);
    }
    this.scrollPane.scrollRectToVisible(new Rectangle(0, this.scrollPane.getHeight() - 2, 1, 1));

    if (registerInHistory) {

      AbstractMove moveToAdd =
          new Move(
              this.game.getChessboard(),
              new Square(begin),
              new Square(end),
              begin.piece,
              end.piece,
              castlingMove,
              wasEnPassant,
              promotedPiece);
      this.moveBackStack.add(moveToAdd);
    }
  }