Exemplo n.º 1
0
        /// <summary>
        /// Function tries to make move selected piece to selected location.
        /// </summary>
        /// <param name="board">Current board</param>
        /// <param name="enemy"></param>
        /// <param name="piece">Selected piece</param>
        /// <param name="destination">Selected destination</param>
        /// <returns>Returns true if player finished his move</returns>
        public bool Turn(CheckerBoard board, Player enemy, Piece piece, Position destination)
        {
            bool attackFlag = IsPossibleAttack(board);

            if (!IsCorrectPiece(piece))
            {
                return(false);
            }
            if (!piece.IsCorrectDestination(attackFlag, destination, board))
            {
                return(false);
            }
            if (attackPiece != null && piece != attackPiece)
            {
                return(false);
            }
            if (piece.CanAttack(board))
            {
                numberOfMovementsWithoutAttack = 0;
                Piece deletePiece = piece.FunkcjaCudzika(board, destination);
                deletePiece.RemovePiece(board, enemy.pieces);
            }
            else
            {
                if (piece.GetType() == typeof(Queen))
                {
                    numberOfMovementsWithoutAttack++;
                }
            }
            piece.Move(board, destination);
            if (attackFlag && piece.CanAttack(board))
            {
                attackPiece = piece;
                return(false);
            }
            attackPiece = null;
            if (piece.IsBecomeQueen())
            {
                piece.ChangePieceToQueen(board, this.pieces);
            }
            return(true);
        }