private void attemptToPlacePiece(BoardSquare square) { ChessMove attemptedMove = new ChessMove(liftedFrom, square.getLocation(), liftedPiece); if (square.getLocation() == this.liftedFrom || !gameBoard.getState().isLegalMove(attemptedMove, lastMove)) { // If the piece is getting placed back to where it was lifted from just put it back, or if the move is illegal placePieceBack(); return; } if (checkForAndApplyPawnPromotion(attemptedMove)) { return; } checkForAndApplyenPassant(attemptedMove); gameBoard.getSquare(square.getLocation()).placePiece(this.liftedPiece); setCursorToDefault(); checkForAndApplyCastle(attemptedMove); forceUIUpdate(); updateCastleingPossibilities(); this.liftedPiece = null; this.liftedFrom = null; nextTurn(); gameState currentState = this.gameBoard.getState().calculateGameState(this.turn, lastMove); if (currentState == gameState.lightWin) { gameCompleteAndRestart(currentState); return; } else if (currentState == gameState.darkWin) { gameCompleteAndRestart(currentState); return; } else if (currentState == gameState.draw) { gameCompleteAndRestart(currentState); return; } lastMove = attemptedMove; }
/// <summary> /// Attemps to lift the piece from the given square as long as it is that players turn /// </summary> /// <param name="?"></param> private void attemptToLiftPiece(BoardSquare square) { ChessPiece pieceToLift = square.getPiece(); if (pieceToLift == null || pieceToLift.getColour() != this.turn) { return; } this.liftedPiece = square.liftPiece(); this.liftedFrom = square.getLocation(); setCursorToLiftedPiece(); }