コード例 #1
0
        /// <summary>
        ///		Clona los datos
        /// </summary>
        public override MovementBaseModel Clone()
        {
            MovementFigureModel target = new MovementFigureModel(new MovementTurnModel(Turn.Number, Turn.Type), Content);

            // Clona los datos internos
            CloneInner(target);
            // Clona las propiedades
            target.Color         = Color;
            target.Type          = Type;
            target.OriginPiece   = OriginPiece;
            target.From          = new CellModel(From);
            target.To            = new CellModel(To);
            target.PromotedPiece = PromotedPiece;
            target.Captured      = Captured?.Clone();
            if (CapturedEnPassant != null)
            {
                target.CapturedEnPassant = new CellModel(CapturedEnPassant);
            }
            target.IsCheck       = IsCheck;
            target.IsDoubleCheck = IsDoubleCheck;
            target.IsCheck       = IsCheckMate;
            target.IsDrawOffered = IsDrawOffered;
            // Devuelve el objeto
            return(target);
        }
コード例 #2
0
        /// <summary>
        ///		Clona los movimientos hasta una variación
        /// </summary>
        internal MovementModelCollection CloneTo(MovementVariationModel variation, MovementVariationModel targetVariation,
                                                 MovementFigureModel targetMovement)
        {
            MovementModelCollection movements = new MovementModelCollection();
            bool variationFound = false;

            // Clona los datos
            foreach (MovementBaseModel movement in this)
            {
                if (!variationFound)
                {
                    // Busca la variación entre las variaciones del movimiento
                    foreach (MovementVariationModel variationChild in movement.Variations)
                    {
                        if (variationChild.Id == targetVariation.Id)
                        {
                            // Añade los movimientos de la variación
                            foreach (MovementBaseModel movementBase in variationChild.Movements)
                            {
                                movements.Add(movementBase.Clone());
                            }
                            // Indica que se ha encontrado la variación y no se debe seguir clonando
                            variationFound = true;
                        }
                    }
                    // Si no se ha encontrado la variación, se sigue clonando, si se ha encontrado, se sustituye el
                    // movimiento por el destino y se deja de clonar
                    if (!variationFound)
                    {
                        movements.Add(movement.Clone());
                    }
                }
            }
            // Devuelve la colección clonada
            return(movements);
        }
コード例 #3
0
        /// <summary>
        ///		Clona hasta una variación
        /// </summary>
        public MovementVariationModel CloneTo(MovementBaseModel parent, MovementVariationModel target, MovementFigureModel movement)
        {
            MovementVariationModel variation = new MovementVariationModel(parent);

            // Clona los movimientos
            variation.Movements.AddRange(Movements.CloneTo(variation, target, movement));
            // Devuelve la variación clonada
            return(variation);
        }