示例#1
0
        public void AddMovement(Database db, string movement)
        {
            Coordinate starting    = HouseCoordinatesInterpreter(movement.Substring(0, 2));
            Coordinate destination = HouseCoordinatesInterpreter(movement.Substring(3, 2));

            IHouse startingHouse    = ChessBoard[starting.Column, starting.Row];
            IHouse destinationHouse = ChessBoard[destination.Column, destination.Row];



            if (startingHouse.PieceInLocation == null ||
                startingHouse.PieceInLocation?.Color != Timer.CurrentPlayerTurn ||
                destinationHouse.PieceInLocation?.Color == Timer.CurrentPlayerTurn ||
                startingHouse.PieceInLocation?.CanMove(starting.Column, starting.Row,
                                                       destination.Column, destination.Row, ChessBoard.Houses) == false
                )
            {
                throw new InvalidOperationException("Mossa non valida");
            }

            ChessBoard.MovePiece(startingHouse, destinationHouse);

            Notes.WriteMovement(db, table, movement);
            //Check King still alive
            Color checkDefeatedColor;

            if (Timer.CurrentPlayerTurn == Color.White)
            {
                checkDefeatedColor = Color.Black;
            }
            else
            {
                checkDefeatedColor = Color.White;
            }
            bool reInVita = ChessBoard.KingIsAlive(checkDefeatedColor);

            if (!reInVita)
            {
                Victory.Invoke(ChessBoard, Timer.CurrentPlayerTurn);
            }
            Timer.SwitchPlayerTurn();
        }