/// <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(); } }
/// <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); } }