예제 #1
0
 public Suspension(SerializationInfo info, StreamingContext context)
 {
     Name             = (string)info.GetValue("Name", typeof(string));
     Level            = (int)info.GetValue("Level", typeof(int));
     MaxLifePoints    = (int)info.GetValue("MaxLifePoints", typeof(int));
     MaxArmorPoints   = (int)info.GetValue("MaxArmorPoints", typeof(int));
     ArmorResistance  = (int)info.GetValue("ArmorResistance", typeof(int));
     EnginePower      = (int)info.GetValue("EnginePower", typeof(int));
     CapacityFuelTank = (int)info.GetValue("CapacityFuelTank", typeof(int));
     FuelConsumption  = (int)info.GetValue("FuelConsumption", typeof(int));
     QuantityFuel     = (int)info.GetValue("QuantityFuel", typeof(int));
     ModeMotion       = (ModeMotionSuspension)info.GetValue("ModeMotion", typeof(int));
     SetSpeed();
 }
예제 #2
0
        public Suspension(string name,
                          int level,
                          int maxLifePoints,
                          int maxArmorPoints,
                          int armorResistance,
                          int enginePower,
                          int capacityFuelTank,
                          int fuelConsumption,
                          ModeMotionSuspension modeMotion)
        {
            Name = string.IsNullOrEmpty(name)
                                ? throw new ArgumentNullException(nameof(name))
                                : name;

            Level = level <= 0
                                ? throw new ArgumentException(StringHelper.IncorrectNumericValue, nameof(level))
                                : level;

            MaxLifePoints = maxLifePoints <= 0
                                ? throw new ArgumentException(StringHelper.IncorrectNumericValue, nameof(maxLifePoints))
                                : maxLifePoints;

            MaxArmorPoints = maxArmorPoints <= 0
                                ? throw new ArgumentException(StringHelper.IncorrectNumericValue, nameof(maxArmorPoints))
                                : maxArmorPoints;

            ArmorResistance = armorResistance < 0
                                ? throw new ArgumentException(StringHelper.IncorrectNumericValue, nameof(armorResistance))
                                : armorResistance;

            EnginePower = enginePower <= 0
                                ? throw new ArgumentException(StringHelper.IncorrectNumericValue, nameof(enginePower))
                                : enginePower;

            CapacityFuelTank = capacityFuelTank <= 0
                                ? throw new ArgumentException(StringHelper.IncorrectNumericValue, nameof(capacityFuelTank))
                                : capacityFuelTank;

            FuelConsumption = fuelConsumption <= 0
                                ? throw new ArgumentException(StringHelper.IncorrectNumericValue, nameof(fuelConsumption))
                                : fuelConsumption;

            ModeMotion = Enum.TryParse(modeMotion.ToString(), out modeMotion)
                                ? modeMotion
                                : throw new ArgumentException(StringHelper.IncorrectEnumValue, nameof(modeMotion));

            SetSpeed();
        }