/// <summary> /// Try selecting a piece on a tile. /// </summary> /// <param name="tile">The tile where the piece (is possibly) standing.</param> /// <returns>true if a piece could be selected, false otherwise.</returns> public bool SelectPiece(Tile tile) { //Search if a piece standing on this tile. Piece toSelect = _pieces.Find(piece => piece.TileCoordinate == tile.Coordinate); if (toSelect != null) { Board.SelectedTile = tile; Board.HighlightPossibleMoves(toSelect.PossibleMoves, removeHighlight: false); _selectedPiece = toSelect; _hasSelectedPiece = true; return(true); } return(false); }
/// <summary> /// Try moving a piece to a tile. Will capture an enemy piece if it already occupies the tile. /// </summary> /// <param name="tile">The tile to move to.</param> /// <param name="other">The other player.</param> /// <returns>true if a move was possible, false otherwise.</returns> public bool MovePiece(Tile tile, Player other) { bool isSuccess = _selectedPiece.Move(tile.Coordinate); if (isSuccess && other != null) { //Check if the destination tile has an enemy piece. //Capture the piece if there is one. Piece toCapture = other.Pieces.Find(piece => piece.TileCoordinate == tile.Coordinate); if (toCapture != null) { _points += CapturePiece(other, toCapture); } } //Remove highlight from tile, and unselect piece. Board.SelectedTile = null; Board.HighlightPossibleMoves(_selectedPiece.PossibleMoves, removeHighlight: true); _selectedPiece = null; _hasSelectedPiece = false; return(isSuccess); }