/// <summary> /// If any pieces are being highlighted for a valid move operation, this method /// returns those pieces to a normal, un-highlighted state. /// </summary> public void CancelSelection() { if (this.currentShowValidMoveOperation != null) { this.currentShowValidMoveOperation.Hide(); this.currentShowValidMoveOperation = null; } }
/// <summary> /// Takes user interface input in the form of a mouse pointer location and the containing /// 3D viewport and attempts to "select" the piece that exists at that location. If a piece is /// found, the appropriate game operation is performed, such as highlighting a valid source, or /// executing a move. /// </summary> /// <param name="location"></param> /// <param name="viewport"></param> public void SelectPiece(Point location, Viewport3D viewport) { if (this.GameOver || this.showingOnlyPlacedPieces) { return; } ModelVisual3D hitTestResult = GameBoardController.GetHitTestResult(viewport, location); GamePieceVisual targetPiece = GameBoardController.ConvertHitTestResultToGamePieceVisual(hitTestResult); if (this.currentShowValidMoveOperation != null) { if (targetPiece != null && this.currentShowValidMoveOperation.ValidDestinationPieces.Contains(targetPiece)) { //execute move ExecuteMoveOperation operation = new ExecuteMoveOperation(this, this.currentShowValidMoveOperation.SourcePiece, targetPiece); this.currentShowValidMoveOperation.Hide(); this.currentShowValidMoveOperation = null; operation.Execute(); this.moveOperations.Add(operation); this.BuildBoardFromMoveHistory(); this.OnMoveMade(operation); this.CheckForEngineMove(); this.isDirty = true; } } else { if (targetPiece != null) { if (targetPiece.IsValidSource) { this.currentShowValidMoveOperation = new ShowValidMoveOperation(this, targetPiece); this.currentShowValidMoveOperation.Show(); } } } }