Пример #1
0
        public static MechModel GenerateMechModel(MechClasses mechClass, string modelName, string variantName,
                                                  string weightIncrement, Factions faction)
        {
            MechModel mechModel = null;

            switch (mechClass)
            {
            case MechClasses.LIGHT:
                mechModel = new LightMech(modelName, variantName, faction,
                                          (LightMechWeightIncrements)System.Enum.Parse(typeof(LightMechWeightIncrements), weightIncrement));
                break;

            case MechClasses.MEDIUM:
                mechModel = new MediumMech(modelName, variantName, faction,
                                           (MediumMechWeightIncrements)System.Enum.Parse(typeof(MediumMechWeightIncrements), weightIncrement));
                break;

            case MechClasses.HEAVY:
                mechModel = new HeavyMech(modelName, variantName, faction,
                                          (HeavyMechWeightIncrements)System.Enum.Parse(typeof(HeavyMechWeightIncrements), weightIncrement));
                break;

            case MechClasses.ASSAULT:
                mechModel = new AssaultMech(modelName, variantName, faction,
                                            (AssaultMechWeightIncrements)System.Enum.Parse(typeof(AssaultMechWeightIncrements), weightIncrement));
                break;
            }

            return(mechModel);
        }
Пример #2
0
        private void AddMechButton_Click(object sender, EventArgs e)
        {
            if (ValidateForm())
            {
                string mechModel;
                if (this.ExistingMechs.SelectedIndex == 0)
                {
                    mechModel = this.NewChassisName.Text;
                }
                else
                {
                    mechModel = ((DropDownItem)this.ExistingMechs.Items[this.ExistingMechs.SelectedIndex]).DisplayValue;
                }
                string   mechVariant = this.VariantName.Text;
                Factions faction     = (Factions)System.Enum.Parse(typeof(Factions),
                                                                   ((DropDownItem)this.FactionSelector.Items[this.FactionSelector.SelectedIndex]).Value);
                string      weightIncrement = ((DropDownItem)this.WeightIncrement.Items[this.WeightIncrement.SelectedIndex]).Value;
                MechClasses mechClass       = (MechClasses)System.Enum.Parse(typeof(MechClasses),
                                                                             ((DropDownItem)this.WeightClassSelector.Items[this.WeightClassSelector.SelectedIndex]).Value);

                MechModel mechForAddition = MechModelMaker.GenerateMechModel(mechClass, mechModel, mechVariant,
                                                                             weightIncrement, faction);

                AddMechResult result = MChooserXMLWriter.AddMechToFile(mechForAddition);

                HandleAddMechResults(result, mechForAddition);
            }
            else
            {
                this.ResponseMessage.Text      = "Please fill out all relevent data for new mech or variant";
                this.ResponseMessage.ForeColor = Color.Red;
                this.ResponseMessage.Visible   = true;
            }
        }
Пример #3
0
        private void UpdateWeightClassDropdown(MechClasses weightClass)
        {
            if (CompletedInitialization)
            {
                switch (weightClass)
                {
                case MechClasses.LIGHT:
                    this.WeightClassSelector.SelectedIndex = 0;
                    UpdateWeightIncrements(0);
                    break;

                case MechClasses.MEDIUM:
                    this.WeightClassSelector.SelectedIndex = 1;
                    UpdateWeightIncrements(1);
                    break;

                case MechClasses.HEAVY:
                    this.WeightClassSelector.SelectedIndex = 2;
                    UpdateWeightIncrements(2);
                    break;

                case MechClasses.ASSAULT:
                    this.WeightClassSelector.SelectedIndex = 3;
                    UpdateWeightIncrements(3);
                    break;
                }
            }
        }
Пример #4
0
        private static List <MechModel> ConvertXElementsToMechModels(IEnumerable <XElement> xelements,
                                                                     MechClasses mechClass, Factions[] selectedFactions)
        {
            List <MechModel> mechs = new List <MechModel>();

            foreach (XElement xel in xelements)
            {
                Factions faction = (Factions)System.Enum.Parse(typeof(Factions), (string)xel.Attribute(StaticValues.XMLMechfactionTag));
                if (selectedFactions.Contains(faction))
                {
                    string modelName = (string)xel.Attribute(StaticValues.XMLModelNameTag);
                    string weight    = (string)xel.Attribute(StaticValues.XMLWeightIncrementTag);

                    foreach (XElement subXel in xel.Elements())
                    {
                        string    variant = subXel.Value;
                        MechModel model   = GenerateMechModel(mechClass, modelName, variant, weight, faction);
                        mechs.Add(model);
                    }
                }
            }
            return(mechs);
        }
Пример #5
0
 private static List <MechModel> GetMechsByClass(XDocument doc, MechClasses mechClass, Factions[] selectedFactions)
 {
     return(ConvertXElementsToMechModels((from el in doc.Root.Elements(mechClass.ToString().ToLower())
                                          .Elements(StaticValues.XMLMechTag)
                                          select el), mechClass, selectedFactions));
 }