Example #1
0
 /// <summary>
 /// Button to level up chosen building.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void buttonLevelUpBuilding_Click(object sender, EventArgs e)
 {
     if (radioButtonShowAll.Checked)
     {
         building = buildingsList[Math.Abs(buildingsListIndex) % buildingsList.Count];
         if (building is Mine)
         {
             Mine mine = (Mine)building;
             ReduceResources(mine);
             mine.LevelUp();
         }
         else if (building is Farm)
         {
             Farm farm = (Farm)building;
             ReduceResources(farm);
             farm.LevelUp();
             cropsPerSec += farm.GetResourcePerSec();
         }
         else if (building is TaxOffice)
         {
             TaxOffice taxOffice = (TaxOffice)building;
             ReduceResources(taxOffice);
             taxOffice.LevelUp();
             goldPerSec += taxOffice.GetResourcePerSec();
         }
     }
 }
Example #2
0
        /// <summary>
        /// Method to read settings from file
        /// </summary>
        private void ReadSettings()
        {
            //Not working
            try
            {
                System.IO.StreamReader reader = new System.IO.StreamReader("settings.txt");
                string line = reader.ReadLine();

                while (line != null)
                {
                    coal  = Convert.ToInt32(line);
                    crops = Convert.ToInt32(line);
                    gold  = Convert.ToInt32(line);


                    string type = line;
                    if (type == Convert.ToString("Mine"))
                    {
                        Building mine = new Mine();
                        mine.SetName(line.ToString());
                        mine.SetLevel(Convert.ToInt32(line));
                        mine.SetResourcePerSec(Convert.ToInt32(line));

                        coalPerSec += mine.GetResourcePerSec();
                        buildingsList.Add(mine);
                    }
                    else if (type == Convert.ToString("Farm"))
                    {
                        Building farm = new Farm();
                        farm.SetName(line.ToString());
                        farm.SetLevel(Convert.ToInt32(line));
                        farm.SetResourcePerSec(Convert.ToInt32(line));

                        cropsPerSec += farm.GetResourcePerSec();
                        buildingsList.Add(farm);
                    }
                    else if (type == Convert.ToString("Tax Office"))
                    {
                        Building taxOffice = new TaxOffice();
                        taxOffice.SetName(line.ToString());
                        taxOffice.SetLevel(Convert.ToInt32(line));
                        taxOffice.SetResourcePerSec(Convert.ToInt32(line));

                        goldPerClick += taxOffice.GetResourcePerSec();
                        buildingsList.Add(taxOffice);
                    }
                }
            }catch (System.IO.FileNotFoundException exception)
            {
                exception.GetBaseException();
            }
        }
Example #3
0
        /// <summary>
        /// Button to buy new buildings
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonBuyBuilding_Click(object sender, EventArgs e)
        {
            //Buying mine
            if (radioButtonMine.Checked && this.gold >= Building.GetCostMine())
            {
                this.gold -= Building.GetCostMine();
                Building mine = new Mine();

                //Sets custom name
                if (textBoxCustomName.Text != "")
                {
                    mine.SetName(textBoxCustomName.Text);
                }

                this.coalPerSec += mine.GetResourcePerSec();
                buildingsList.Add(mine);
            }
            //Buying farm
            else if (radioButtonFarm.Checked && this.gold >= Building.GetCostFarm())
            {
                this.gold -= Building.GetCostFarm();
                Building farm = new Farm();

                //Sets custom name
                if (textBoxCustomName.Text != "")
                {
                    farm.SetName(textBoxCustomName.Text);
                }

                this.cropsPerSec += farm.GetResourcePerSec();
                buildingsList.Add(farm);
            }
            //Buying tax office
            else if (radioButtonTaxOffice.Checked && this.gold >= Building.GetCostTaxOffice())
            {
                this.gold -= Building.GetCostTaxOffice();
                Building taxOffice = new TaxOffice();

                //Sets custom name
                if (textBoxCustomName.Text != "")
                {
                    taxOffice.SetName(textBoxCustomName.Text);
                }

                this.goldPerSec += taxOffice.GetResourcePerSec();
                buildingsList.Add(taxOffice);
            }
        }