Пример #1
0
        public static bool IsCorretVehicle(Vehicle vehicle)
        {
            Road road = vehicle.Road;

            // Road check, no road - no vehicle
            if (road == null)
            {
                MessageBox.Show(@"Road is null. Select road, please.");
                return false;
            }

            // Check that tram and trolley is stay at thier roads
            if ((vehicle is Tram && !(road is TramRoad)) || (vehicle is TralleyBus && !(road is TralleyRoad)))
            {
                MessageBox.Show(@"This vehicle can't move at that road.");
                return false;
            }

            // Check that other vehicle isn't placed on tram road
            if (!(vehicle is Tram) && road is TramRoad)
            {
                MessageBox.Show(@"You can't place this vehicle at tram road.");
                return false;
            }

            // Check max speed
            if (vehicle.MaxSpeed <= 0)
            {
                MessageBox.Show(@"Wrong max speed value. It must be greater then 0.");
                return false;
            }

            // Engine specific checks
            if (vehicle is EngineDriven)
            {
                EngineDriven e = (EngineDriven) vehicle;
                if (e.MaxFuel <= 0)
                {
                    MessageBox.Show(@"Wrong max Fuel value. It must be greater then 0.");
                    return false;
                }
            }
            else if (vehicle is MuscleDriven)
            {
                MuscleDriven m = (MuscleDriven) vehicle;

            }

            return true;
        }
        private void AddVehicle(Road road, Vehicle vehicle)
        {
            var mainForm = (MainForm) Owner;
            PictureBox picBoxVehicle;
            PictureBox picBoxRoad;

            switch (road.OrderNumber)
            {
                case 1:
                    picBoxRoad = mainForm.pictureRoad1;
                    picBoxVehicle = mainForm.pictureVehicle1;
                    break;
                case 2:
                    picBoxRoad = mainForm.pictureRoad2;
                    picBoxVehicle = mainForm.pictureVehicle2;
                    break;
                case 3:
                    picBoxRoad = mainForm.pictureRoad3;
                    picBoxVehicle = mainForm.pictureVehicle3;
                    break;
                case 4:
                    picBoxRoad = mainForm.pictureRoad4;
                    picBoxVehicle = mainForm.pictureVehicle4;
                    break;
                case 5:
                    picBoxRoad = mainForm.pictureRoad5;
                    picBoxVehicle = mainForm.pictureVehicle5;
                    break;
                default:
                    MessageBox.Show(@"Something strange happened...");
                    return;
            }

            picBoxVehicle.Visible = true;
            picBoxVehicle.BackColor = Color.Transparent;
            picBoxVehicle.Parent = picBoxRoad;
            picBoxVehicle.Location = new Point(0, 0);
            picBoxVehicle.Image = vehicle.GetImage();

            vehicle.Picture = picBoxVehicle;

            RemoveClickEvent(vehicle.Picture);
            vehicle.Picture.DoubleClick += vehicle.ShowLog;
        }