Пример #1
0
        private void btTune_Click(object sender, EventArgs e)
        {
            if (lbTuneOptions.Items.Count <= 0)
            {
                MessageBox.Show("Must select tuning options");
                return;
            }

            iCar car = (iCar)lbUntunedCars.SelectedItem;

            if (car == null)
            {
                car = (iCar)lbTunedCars.SelectedItem;
                if (car == null)
                {
                    MessageBox.Show("Must select a Car");
                    return;
                }
                else
                {
                    lbTunedCars.Items.RemoveAt(lbTunedCars.SelectedIndex);
                }
            }
            else
            {
                lbUntunedCars.Items.RemoveAt(lbUntunedCars.SelectedIndex);
            }

            // this copy is only done for naming purposes.
            // since from this point forward the iCar object is no longer a car (component) but a tuning option (decoration)
            iCar tuning_options = car;

            foreach (var option in lbTuneOptions.SelectedItems)
            {
                string optionName = option.ToString();
                if (optionName == PaintJob.Name)
                {
                    tuning_options = new PaintJob(tuning_options);
                }
                else if (optionName == Hydraulics.Name)
                {
                    tuning_options = new Hydraulics(tuning_options);
                }
                else if (optionName == VinylSticker.Name)
                {
                    tuning_options = new VinylSticker(tuning_options);
                }
                else if (optionName == Airco.Name)
                {
                    Airco airco = new Airco(tuning_options);
                    //To show you can have different funtionality for each decorator we will test the airco:
                    airco.TurnOn();
                    airco.TurnOff();
                    tuning_options = airco;
                }
            }
            tbLabelCars.Text = "";
            lbTunedCars.Items.Add(tuning_options);
        }
Пример #2
0
        public TuningOptions(iCar car)
        {
            if (car == null)
            {
                throw new ArgumentNullException("car is null");
            }

            _car = car;
        }
Пример #3
0
        private void lbTunedCars_SelectedIndexChanged(object sender, EventArgs e)
        {
            iCar car = (iCar)lbTunedCars.SelectedItem;

            if (car == null)
            {
                return;
            }

            lbUntunedCars.ClearSelected();

            tbLabelCars.Text = "Costs: \u20AC " + car.cost() + " " + car.ToString();
        }
Пример #4
0
 public VinylSticker(iCar car) : base(car)
 {
 }
Пример #5
0
 public PaintJob(iCar car) : base(car)
 {
 }
Пример #6
0
 public Hydraulics(iCar car) : base(car)
 {
 }
Пример #7
0
 public Airco(iCar car) : base(car)
 {
 }