コード例 #1
0
        /// <summary>
        /// Odczytuje samolot o zadanym id z pliku xml z samolotami
        /// </summary>
        static public Plane readFromFile(int id)
        {
            XmlDocument xDoc = new XmlDocument();

            xDoc.LoadXml(Resources.DefinedPlanes);

            Plane loadedPlane;

            XmlNodeList planeNodes = xDoc.SelectNodes("Planes/Plane");

            foreach (XmlNode node in planeNodes)
            {
                if (Int32.Parse(node.Attributes.GetNamedItem("id").Value) == id)
                {
                    string type = node.SelectSingleNode("Type").InnerText;

                    if (type == "PassengerPlane")
                    {
                        loadedPlane = new PassengerPlane();
                        ((PassengerPlane)loadedPlane).setMaxNumberOfPassengers(Int32.Parse(node.SelectSingleNode("MaxPassengers").InnerText));
                    }
                    else if (type == "MilitaryPlane")
                    {
                        loadedPlane = new MilitaryPlane();
                        ((MilitaryPlane)loadedPlane).setMaxAmmo(Int32.Parse(node.SelectSingleNode("MaxAmmo").InnerText));
                        ((MilitaryPlane)loadedPlane).setWeaponType(node.SelectSingleNode("WeaponType").InnerText);
                    }
                    else if (type == "TransportPlane")
                    {
                        loadedPlane = new TransportPlane();
                        ((TransportPlane)loadedPlane).setMaxStorageCapacity(Int32.Parse(node.SelectSingleNode("MaxStorage").InnerText));
                    }
                    else
                    {
                        return(null);
                    }

                    loadedPlane.setModel(node.SelectSingleNode("Model").InnerText);
                    loadedPlane.setMaxFuelLevel(Int32.Parse(node.SelectSingleNode("MaxFuelLevel").InnerText));
                    loadedPlane.setFuelUsage(Int32.Parse(node.SelectSingleNode("FuelUsage").InnerText));
                    loadedPlane.setTakeoffTime(Int32.Parse(node.SelectSingleNode("TakeoffInterval").InnerText));
                    loadedPlane.setPlaneImage(node.SelectSingleNode("Image").InnerText);

                    return(loadedPlane);
                }
            }

            return(null);
        }
コード例 #2
0
        private void buttonCreateInHangar_Click(object sender, EventArgs e)
        {
            if (!validateData())
            {
                return;
            }

            Plane factoriedPlane;

            if (currentFactoring == PlaneType.Passenger)
            {
                factoriedPlane = new PassengerPlane();
                ((PassengerPlane)factoriedPlane).setMaxNumberOfPassengers(Int32.Parse(textBoxSpecific.Text));
            }
            else if (currentFactoring == PlaneType.Transport)
            {
                factoriedPlane = new TransportPlane();
                ((TransportPlane)factoriedPlane).setMaxStorageCapacity(Int32.Parse(textBoxSpecific.Text));
            }
            else
            {
                factoriedPlane = new MilitaryPlane();
                ((MilitaryPlane)factoriedPlane).setWeaponType(textBoxWeaponType.Text);
                ((MilitaryPlane)factoriedPlane).setMaxAmmo(Int32.Parse(textBoxSpecific.Text));
            }

            factoriedPlane.setPlaneImage(chosenImageName);
            factoriedPlane.setModel(textBoxModel.Text);
            factoriedPlane.setFuelUsage(Int32.Parse(textBoxFuelUsage.Text));
            factoriedPlane.setMaxFuelLevel(Int32.Parse(textBoxMaxFuelLevel.Text));
            factoriedPlane.setTakeoffTime(Int32.Parse(comboBox1.Text));
            factoriedPlane.setAfterTechnicalInspection(false);

            AirportManager.getInstance().getHangar().addToHangar(factoriedPlane);
            hideFactoryPanel();
            resetControls();
            handleAppWindow.refreshBtnPlaneFactory();
        }