public void OnPrimaryMouseUp(MouseEventArgs mouseEventArgs) { var boardCell = GetCellFromPosition(mouseEventArgs.Point); if (SelectedPiece == null) { // We know we're going to try to make a selection // Is the cell empty or an enemy piece? if (!boardCell.IsOccupied || boardCell.Piece.Side != CurrentTurn) { return; } // It must be our piece! SelectedPiece = boardCell.Piece; SelectedPiece.OnSelected(); } else { // Here we have a piece selected so the player is trying to do something with that piece or change the selection. if (SelectedPiece.Equals(boardCell.Piece)) { SelectedPiece.OnDeselected(); SelectedPiece = null; return; } if (!SelectedPiece.FindPossibleMovementPaths().Contains(boardCell)) { return; } // Ok so the piece is allowed to move here. Do we need to destroy a piece to move there? if (boardCell.IsOccupied) { boardCell.Piece.DestroyPiece(); boardCell.Piece = null; PieceDestroyed?.Invoke(this, new PieceDestroyedEventArgs()); } boardCell.Piece = SelectedPiece; SelectedPiece.MoveToCell(boardCell); EndTurn(); } }
private void OnDestroy() { //Register destroyed obj PieceDestroyed?.Invoke(gameObject); }
public void Destroy() { DestroyPieceHandler.OnDestroy(); PieceDestroyed?.Invoke(this); }