示例#1
0
 void initCar(string CarMaker, CarType NewCarType)
 {
     Id = Guid.NewGuid();
     TypeOfCar = NewCarType;
     FactoryName = CarMaker;
     _maxSpeed = calcMaxSpeed();
     CurrentSpeed = 0;
     _lastSpeed = 0;
     DateTime installDate = DateTime.UtcNow;
     Tires = new List<IVehicleTire>();
     for (int i = 0; i < 4; i++)
     {
         //Create 4 tires
         CarTire newTire = new CarTire(this, i, installDate);
         Tires.Add(newTire);
     }
 }
示例#2
0
        public void ReplaceFlat()
        {
            int replacementTirePos = int.MinValue;
            CarTire newTire = null;
            List<IVehicleTire> newTires = new List<IVehicleTire>();

            foreach (CarTire ct in Tires)
            {
                if (ct.IsFlat())
                {
                    replacementTirePos = ct.PositionNumber;
                    newTire = new CarTire(this, ct.PositionNumber, DateTime.UtcNow);
                    break;
                }
            }

            for (int i = 0; i < 4; i++)
            {
                if (i == replacementTirePos)
                {
                    newTires.Add(newTire);
                }
                else
                {
                    newTires.Add(Tires[i]);
                }
            }
            Tires = newTires;
        }