Example #1
0
        /// <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);
        }