public static void AttackPiece(Piece attacker, Piece attacked) { ChessBoard board = ChessTracker.board; if (attacked.isWhite) { board.WhitePieces.Remove(board.WhitePieces.Find(x => x.Controller.name == attacked.Controller.name)); } else { board.BlackPieces.Remove(board.BlackPieces.Find(x => x.Controller.name == attacked.Controller.name)); } Destroy(ChessHelper.GetPiece(attacked.position).Controller.gameObject); attacker.position = attacked.position; attacker.Controller.transform.position = ChessHelper.CalcPosition(attacked.position, attacked); ChessHistory.selectedSquare.GetComponent <MeshRenderer>().material = ChessHistory.selectedSquareMat; ChessHelper.ResetOldSquares(); ChessHelper.ResetHistory(); ChessHelper.ResetOldAttackSquares(); ChessTracker.isWhiteTurn = !ChessTracker.isWhiteTurn; ChessHelper.HandleKingsInCheck(); }
private void OnMouseDown() { if (ChessHistory.selectedSquare != null && ChessHistory.selectedPiece.PossibleMoves.Contains(position)) { // Move the pawn to chosen square ChessHistory.selectedPiece.position = position; ChessHistory.selectedPiece.Controller.transform.position = ChessHelper.CalcPosition(position, ChessHistory.selectedPiece); if (ChessHistory.selectedPiece is Pawn) { Pawn pawn = (Pawn)ChessHistory.selectedPiece; pawn.isFirstMove = false; } ChessTracker.isWhiteTurn = !ChessTracker.isWhiteTurn; ChessHistory.selectedSquare.GetComponent <MeshRenderer>().material = ChessHistory.selectedSquareMat; ChessHelper.ResetOldSquares(); ChessHelper.ResetOldAttackSquares(); ChessHelper.ResetHistory(); // Calculate if any king is in check or checkmate ChessHelper.HandleKingsInCheck(); } }