Exemple #1
0
        /// <summary>
        /// Constructor to create a new intance of an interstella Object from a InterstellaObject Paramater object
        /// </summary>
        /// <param name="paramaters"><see cref="InterstellaObjectParams"/></param>
        public InterstellaObject(InterstellaObjectParams paramaters) : base(paramaters.Position, paramaters.Velocity, paramaters.Acceleration)
        {
            // Params for MovingObject constructor given to base.
            // Resultant force starts at 0
            _ResultantForce = new Vector(0, 0);

            // Fields set from paramaters
            _Type   = paramaters.Type;
            _Mass   = paramaters.Mass;
            _Radius = paramaters.Radius;
        }
Exemple #2
0
        /// <summary>
        /// Converts a complete List of Data Objects and returns an InterstellarSystem Object
        /// </summary>
        private static InterstellaSystem ParseIntermediateFormToSystem(List <Data> intermediateDataFormatSystem)
        {
            InterstellaSystem DataAsSystemType = new InterstellaSystem();

            // loop through each data object
            foreach (var DataItem in intermediateDataFormatSystem)
            {
                // Check For System Name
                if (DataItem.Tag == _DataReadTypes[0].Tag)
                {
                    DataAsSystemType.SystemSaveName = DataItem.DataString;
                }

                // Check For System Mass Retention
                else if (DataItem.Tag == _DataReadTypes[1].Tag)
                {
                    DataAsSystemType.CollissionMassRetentionPercentage = (double)Convert.ChangeType(DataItem.DataString, DataItem.DesiredType);
                }

                // Check for objects collections
                else if (DataItem.Tag == _DataReadTypes[2].Tag)
                {
                    List <InterstellaObject> Objects = new List <InterstellaObject>();

                    // Cast each data string too a interstella Object
                    foreach (var DataObject in DataItem.DataStrings)
                    {
                        InterstellaObjectParams ObjectParams = new InterstellaObjectParams();

                        // Get Properties
                        foreach (var ObjectProperty in DataObject.DataStrings)
                        {
                            // Get Type
                            if (ObjectProperty.Tag == _DataReadTypes[3].Tag)
                            {
                                ObjectParams.Type = ConvertDataStringToTypeEnum(ObjectProperty.DataString);
                            }

                            // Get Position
                            else if (ObjectProperty.Tag == _DataReadTypes[4].Tag)
                            {
                                ObjectParams.Position = CastDataToVector(ObjectProperty.DataStrings);
                            }

                            // Get Velocity
                            else if (ObjectProperty.Tag == _DataReadTypes[5].Tag)
                            {
                                ObjectParams.Velocity = CastDataToVector(ObjectProperty.DataStrings);
                            }

                            // Get Acceleration
                            else if (ObjectProperty.Tag == _DataReadTypes[6].Tag)
                            {
                                ObjectParams.Acceleration = CastDataToVector(ObjectProperty.DataStrings);
                            }

                            // Get Mass
                            else if (ObjectProperty.Tag == _DataReadTypes[7].Tag)
                            {
                                ObjectParams.Mass = (double)Convert.ChangeType(ObjectProperty.DataString, ObjectProperty.DesiredType);
                            }

                            // Get Radius
                            else if (ObjectProperty.Tag == _DataReadTypes[8].Tag)
                            {
                                ObjectParams.Radius = (double)Convert.ChangeType(ObjectProperty.DataString, ObjectProperty.DesiredType);
                            }
                        }
                        // Use the retrieved data to construct an Interstellar Object
                        Objects.Add(new InterstellaObject(ObjectParams));
                    }
                    // Add these objects to the system
                    DataAsSystemType.InterstellaObjects = Objects;
                }
            }
            return(DataAsSystemType);
        }