Exemple #1
0
        private void ArmyAdd_Click(object sender, EventArgs e)
        {
            // Instantiate army builder
            var army = new ArmyBuilder();

            try
            {
                // Get the army name
                if (!txtTemplateName.Text.Equals(""))
                {
                    army.Name = txtTemplateName.Text;
                }

                // Get army values
                if (!txtSpear.Text.Equals(""))
                {
                    army.Spearman = int.Parse(txtSpear.Text);
                }
                if (!txtSwords.Text.Equals(""))
                {
                    army.Swordsman = int.Parse(txtSwords.Text);
                }
                if (!txtAxe.Text.Equals(""))
                {
                    army.Axeman = int.Parse(txtAxe.Text);
                }
                if (!txtLC.Text.Equals(""))
                {
                    army.LightCavalry = int.Parse(txtLC.Text);
                }
                if (!txtHC.Text.Equals(""))
                {
                    army.HeavyCavalary = int.Parse(txtHC.Text);
                }
                if (!txtScout.Text.Equals(""))
                {
                    army.Scout = int.Parse(txtScout.Text);
                }
                if (!txtRam.Text.Equals(""))
                {
                    army.Ram = int.Parse(txtRam.Text);
                }
                if (!txtCat.Text.Equals(""))
                {
                    army.Catapult = int.Parse(txtCat.Text);
                }
                if (!txtKnight.Text.Equals(""))
                {
                    army.Knight = int.Parse(txtKnight.Text);
                }
                if (!txtNoble.Text.Equals(""))
                {
                    army.Nobleman = int.Parse(txtNoble.Text);
                }

                // add the created army into the army list
                if (army.GetSize() != 0)
                {
                    ArmyList.Items.Add(army);
                }
            }
            catch (Exception)
            {
                // enters here if there is something wrong while parsing string to integer
                MessageBox.Show("Only numbers are allowed");
            }
        }