void Start()
    {
        //The factories we can choose from
        _CarFactory US_Factory = new USFactory();

        _CarFactory China_Factory = new ChinaFactory();


        //Manufacture cars
        _Car order1 = US_Factory.ManufactureCar(CarModels.ModelS, new List <CarExtras>()
        {
            CarExtras.DracoThruster
        });

        FinalizeOrder(order1);


        _Car order2 = China_Factory.ManufactureCar(CarModels.Cybertruck, new List <CarExtras>()
        {
            CarExtras.DracoThruster
        });

        FinalizeOrder(order2);


        _Car order3 = US_Factory.ManufactureCar(CarModels.Roadster, new List <CarExtras>()
        {
            CarExtras.DracoThruster, CarExtras.EjectionSeat, CarExtras.DracoThruster
        });

        FinalizeOrder(order3);
    }
 private void FinalizeOrder(_Car finishedCar)
 {
     if (finishedCar == null)
     {
         Debug.Log($"Sorry but we cant manufacture your order, please try again!");
     }
     else
     {
         Debug.Log($"Your order: {finishedCar.GetDescription()} is ready for delivery as soon as you pay ${finishedCar.Cost()}");
     }
 }
Beispiel #3
0
        public override _Car ManufactureCar(CarModels carModel, List <CarExtras> carExtras)
        {
            _Car car = null;

            if (carModel == CarModels.ModelS)
            {
                car = new ModelS();
            }
            else if (carModel == CarModels.Roadster)
            {
                car = new Roadster();
            }

            //Notice that the Cybertruck is missing here, so we cant manufacture it!
            if (car == null)
            {
                Debug.Log("Sorry but this factory cant manufacture this model :(");

                return(car);
            }


            //Add the extras
            foreach (CarExtras carExtra in carExtras)
            {
                if (carExtra == CarExtras.DracoThruster)
                {
                    car = new DracoThruster(car, 1);
                }
                else if (carExtra == CarExtras.EjectionSeat)
                {
                    car = new EjectionSeat(car, 1);
                }
                else
                {
                    Debug.Log("Sorry but this factory cant add this car extra :(");
                }
            }

            return(car);
        }
Beispiel #4
0
        public override _Car ManufactureCar(CarModels carModel, List <CarExtras> carExtras)
        {
            _Car car = null;

            if (carModel == CarModels.Cybertruck)
            {
                car = new Cybertruck();
            }
            else if (carModel == CarModels.ModelS)
            {
                car = new ModelS();
            }
            else if (carModel == CarModels.Roadster)
            {
                car = new Roadster();
            }

            if (car == null)
            {
                Debug.Log("Sorry but this factory cant manufacture this model :(");

                return(car);
            }


            //Add the extras
            foreach (CarExtras carExtra in carExtras)
            {
                if (carExtra == CarExtras.DracoThruster)
                {
                    car = new DracoThruster(car, 1);
                }
                //Ejection seats are not legal in US so cant manufacture it (but we will still manufacture the rest of the car)
                else
                {
                    Debug.Log("Sorry but this factory cant add this car extra :(");
                }
            }

            return(car);
        }
Beispiel #5
0
        public bool SaveCar(_Car c)
        {
            try
            {
                if (c.IsNew)
                {
                    db.CARS.Add(new CARS()
                    {
                        Number  = c.Number,
                        Branch  = c.Branch,
                        CarType = c.CarType,
                        Mileage = c.Mileage,
                        IsFree  = c.IsFree,
                        Isvalid = c.Isvalid,
                        Image   = c.Image
                    });
                }
                else
                {
                    var curr = db.CARS.Where(w => w.Number == c.Number).FirstOrDefault();
                    curr.Branch  = c.Branch;
                    curr.CarType = c.CarType;
                    curr.Mileage = c.Mileage;
                    curr.IsFree  = c.IsFree;
                    curr.Isvalid = c.Isvalid;
                    curr.Image   = c.Image;
                }

                db.SaveChanges();
            }
            catch
            {
                return(false);
            }
            return(true);
        }